Search code examples
command-line-interfacegimp

How can I overwrite a jpg list of files in gimp using the command line


I would like to optimize a list of jpe?g files that I have in my website which are taking a lot of space, so I have been using gimp to save more space.

What I've been doing is to open a file in GIMP using the GUI and then saving the file with File -> overwrite {file}.jpg , and then I choose the quality to be 60%, and noticed that I can save a lot of space by doing this. Since I have hundreds of images in my site, I was wondering if there is a way to do this process with a script. I have seen the GIMP Batch option but I don't know what command to use to do what I wanted to do.

Any help is appreciated.


Solution

  • Better use ImageMagick's mogrify for this:

    magick mogrify -quality 60 foobar.jpg
    

    In practice you can re-encode several files in one shot, and besides quality, you can also ensure that you are using the maximum chroma subsampling:

    magick mogrify -sampling-factor 4:2:0 -quality 60 *.jpg
    

    (in older versions of IM, the command is a plain mogrify ..., the magick command has been added recently to avoid name clashes with other commands).