The main hindrance to develop a principal component analysis (PCA) encoder for image compression is the poor generalization ability of PCA. In this paper, we present a flexible semi-universal image encoder based on the recently proposed non-linear PCA framework. Unlike other PCA techniques with a fixed order of principal components, the proposed encoder can flexibly determine which component is more significant to the quality of compression according to the characteristics of the sub-image block to encode. The proposed encoder is used to compress still gray level images, and experimental results indicate that it can provide very good generalization ability as well as high compression ratio.