| Issue 68: | Optimize JPEG images within the PDF | |
| 4 people starred this issue and may be notified of changes. | Back to list |
** These produce bytewise identical, but smaller files:
* jpegoptim -t --strip-all *.jpg
* imgopt *.jpg
* for F in *.jpg; do
jpegtran -copy none -optimize -outfile jo.bin "$F" &&
mv -f jo.bin "$F"; done
... but make sure to run jfifremove (part of imgopt, simple code, unused)
etc. first for removing JFIF, EXIF etc. metadata; `-copy none' also
removes some stuff
See more about this in trunk/info.txt .
Feb 27, 2013
#1
rbr...@gmail.com
Feb 27, 2013
Thank you for posting these commands for JPEG optimization. It would be a useful feature to add to pdfizeopt. I also have some similar commands somewhere to try. About JPEG2000: it's a completely different lossy image compression algorithm. It's a design principle of pdfsizeopt that it can't cause visual quality loss. So converting JPEG images to JPEG2000 won't be added. (We can relax this requirement in the future if there are volunteers for adding support: they can add a command-line flag disabled by default.)
Feb 27, 2013
Thanks for the comment. Regarding JPEG2000, I think that it is, indeed, better to keep with the current philosophy of being "as lossless as we can" and just scrap that idea of mine.
Sep 12, 2013
I suggest running jpegtran (at least) twice to create two optimized jpeg files, one with "-progressive", one without, and choosing the smaller one. Usually, especially for photos, the progressive version is smaller. For simpler and smaller images, sometimes the non-progressive version is smaller. Jpegtran is superfast, so multiple runs will hardly affect compression time. To optimize filesize further, the sequence of the progressive order can be changed by the jpegtran-parameter "-scans". The default scanfile, included into jpegtran, is optimized for progressive images on the web but not for filesize. To keep the speed high, a number of fixed scanfiles, optimized for filesize, can be used to create different jpeg-files. Then just take the smallest one. I suggest using the scanfiles from this file: http://akuvian.org/src/jpgcrush.tar.gz If speed is not first priority, a scanfile can be created for each image by finding a good combination using a tool called jpegrescan. Typical example: original jpeg: 770138 bytes (not optimized, 61 byte metadata) jpegtran -copy none -optimize in.jpg out.jpg : 623913 bytes jpegtran -copy none -optimize -progressive in.jpg out.jpg : 618403 bytes jpegtran -copy none -optimize -progressive -scans jpeg_scan_rgb.txt in.jpg out.jpg : 606477 bytes (third example needs "jpeg_scan_rgb.txt" from http://akuvian.org/src/jpgcrush.tar.gz
Sep 12, 2013
@SebastianWilke78: Thank you for the insights, links and great ideas! Now I only need some free time to implement this. I also accept patches. |