I want to convert a 640x480 JPEG image to 320x240. I know it can be done by decoding the JPEG image into raw YCbCr, scale it and re-encode it into JPEG. But is it possible possible with JPEG encoding to directly scale the image with out decoding?


You can, but only if your JPEG viewer supports the SmartScale JPEG extension. jpegtran can do this for sizes of N/8, with N=1..16. Basically, the DCT block size is changed from 8x8 to something else during recompression (e.g. 4x4), which effectively scales the image.

Note: SmartScale was introduced in version 8 of the libjpeg library, but it's not widely supported by viewers.

A document describing the changes in detail can be found here: Evolution of JPEG.

EDIT: It seems that most viewers cannot actually display these images, as they are based on libjpeg-turbo. And libjpeg-turbo chose not to implement this feature. In fact, I've tried quite a few programs (on Ubuntu 14.04 and Windows 8) and none have been able to display the downscaled image created using jpegtrans. Even Photoshop, IrfanView and GIMP failed.

EDIT 2: In fact, Ubuntu and Fedora don't even ship the libjpeg8 library, but completely replace it with the libjpeg-turbo version. So none of the programs will be able to read JPEG SmartScale files, save for a few binaries that are statically linked to the original libjpeg8 library.

  • Is there a codec that constructs the image that grows on just by appending further data to the image? – Necktwi Jul 3 '14 at 14:41
  • what about the progressive jpeg? Doesn't it does exactly what i'm asking? – Necktwi Jul 3 '14 at 15:44
  • No, that does something slightly different by increasing the quality of the image (from low to full), but the resolution is always unchanged (reference). However, there is another JPEG extension called "hierarchical mode", which encodes different resolutions (see also here). But again, libjpeg-turbo doesn't support it (see here, search for "progressive" in the text). – jmiserez Jul 3 '14 at 17:54
  • 1
    And to answer the first comment, of course there are such codecs. Just not JPG. What you are looking for is called an image pyramid, or multiscale representation. E.g. JPEG2000 uses a wavelet transform that creates a wavelet pyramid. There are other pyramids, such as Gaussian or Laplacian pyramids. This slideset gives a good overview on how things work, while JPEG2000 is discussed here and here. – jmiserez Jul 3 '14 at 18:10
  • Thanks for the information about the new JPEG formats. I don't expect many source images (cameras, scanners, etc) to use them yet. – AFH Jul 14 '14 at 11:01

The short answer is no. A JPEG image uses compression, which means that each output byte depends on all the others. If you change the number of image bytes, then you must decompress and recompress.

There will be a loss of quality as a result of the recompression, since JPEG uses lossy compression, but you are losing quality anyway by quartering the resolution. You can get the best possible quality from the low-resolution image by increasing the JPEG quality level when recompressing, though this will of course increase the file size.

If you do a lot of work with images, it is best to work in a lossless compression format, such as PNG, converting to JPEG only when images are finalised, provided of course that you have the extra disc space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.