Forum Moderators: phranque

Message Too Old, No Replies

Using jpegoptim and optipng

         

csdude55

5:07 pm on Mar 15, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@Jonesy mentioned this in another thread, but I didn't want to take it off topic so I brought it here:

Then there is `jpegoptim --strip-all -m75` and `optipng -strip -o7` to remove unnecessary meta data from the images and do compression.

This is pretty interesting to me, since I allow users to upload photos that I then crop and shrink to fit my parameters. I use ImageMagick for manipulations, but I don't think it compresses them like that.

My questions are:

1. How do I know if these are installed?

2. Is there any reason to NOT use them? Performance, speed, etc?

3. I'll probably do this in Perl, so is there a better way than:
system("jpegoptim --strip-all -m75");
system("optipng -strip -o7");

# or maybe
($ext) = lc($file) =~ /\.([^.]+)$/;

if ($ext eq 'jpg' || $ext eq 'jpeg) {
system("jpegoptim --strip-all -m75");
}

elsif ($ext eq 'png') {
system("optipng -strip -o7");
}

not2easy

5:30 pm on Mar 15, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



In a discussion a few years back: [webmasterworld.com...] there were many suggestions for tools and services. Some of those are still around and doing the job. One I had found useful and still use is ImageOptim which can be integrated via API. The developer is happy to help work out any unusual needs. I have no relationship with the company but I admire their work.

I'm still using ImageOptim which you can use in a variety of ways, for me the desktop app is fine and takes out from 10 to over 30% of a file size by compression and by removing identifiable geo and meta data from the image. Not for everyone, if you need to keep data with the image for example, but for uploaded images it gives users more privacy. You don't always need the time and place and serial number of the lens used for the image.

robzilla

8:40 pm on Mar 15, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. How do I know if these are installed?

Run them from the command line and you'll find out :-) But they're usually not installed by default.

2. Is there any reason to NOT use them? Performance, speed, etc?

Compression can take a bit of time, you should not make your users wait for it to finish. Better to do it in the background somehow.

Might want to look into WEBP and AVIF as well, but they're a little more complex in that you need to send them only to browsers that support them.

phranque

5:35 am on Mar 16, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Run them from the command line and you'll find out :-) But they're usually not installed by default.

even when installed in some cases, you may need to specify the full path.