Can we change size of an JPEG image with out decoding and re-encoding it?

Solution 1:

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.

Solution 2:

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.