IM Version: stable 7.0.5-0
Does imagemagick implement/provide an api or any helpers to use standard JFIF encoding when compressing/encoding a JPEG image? Based on this wikipedia article my understanding of the steps involved are the following:
- Optionally convert the colors in the image from RGB to YCBCR
- Optionally reduce the resolution of chroma data by a factor of 2 or 3
- Split up the image into blocks of 8x8 pixels and apply DCT-II on each pixel to get DCT coefficients
- Quantize DCT coefficients
- Compress quantized values using some variant of Huffmans encoding
Code: Select all
ycbcr_values[] = imagetorcbcr('my image.jpeg');
ycbcr_values[] = reducechroma(ycbcr_values, 3);
blocks[][] = pixelstoblocks(ycbcr_values, 8, 8);
dct_blocks[][] = dct(blocks);
quantized_blocks[][] = quantize(dct_blocks);
image = writeimage('out image.jpeg', quantized_blocks);