0

I know that there are many tools to optimize an image:

  • pngquant
  • optipng
  • jpegoptim
  • gifsicle
  • exiftool
  • ecc

but they are all specific for a certain file type. Is there a single command line that, whatever image type passed, it applies the right compression? Something similar to what https://compressor.io does but cli.

With "optimize" I mean reducing the size of the overall file while keeping it visually nearly identical (thanks @Philippos).

4
  • »Optimize« is underspecified. For lossy compression, a size optimization will probably result in a single interpolated colour for the whole picture, for example.
    – Philippos
    May 2, 2022 at 14:13
  • I have clarified, thanks @Philippos!
    – nulll
    May 2, 2022 at 14:20
  • reducing the size of the overall file while keeping it visually nearly identical This is a very difficult problem that's effectively Impossible in general for all but the formats like TIFF that aren't already compressed but could be compressed. Bitmap images can't be compressed, else they wouldn't be bitmap images. GIFs and PNGs are already compressed. JPEGs lose information and image quality as they're compressed. And "visually nearly identical" is subjective and highly image-dependent so you can't really automate it easily. See en.wikipedia.org/wiki/Image_compression May 2, 2022 at 15:09
  • (cont) If this were an easy problem to solve automatically, given all the images stored around the planet, there would likely be a lot of easy solutions. May 2, 2022 at 15:11

1 Answer 1

0

If you don't mind using SVG as an intermediary format, then inkscape may be useful.

But you're probably looking for ImageMagick's convert.

From the man page:

convert-im6.q16(1)         General Commands Manual        convert-im6.q16(1)

NAME
       convert  -  convert between image formats as well as resize an image,
       blur, crop, despeckle, dither, draw on, flip,  join,  re-sample,  and
       much more.

SYNOPSIS
       convert-im6.q16 [input-option] input-file [output-option] output-file

OVERVIEW
       The   convert-im6.q16   program  is  a  member  of  the  ImageMagick-
       ims6.q16(1) suite of tools.  Use it to convert between image  formats
       as  well  as resize an image, blur, crop, despeckle, dither, draw on,
       flip, join, re-sample, and much more.

       For more information about the convert command, point your browser to
       file:///usr/share/doc/imagemagick-6-common/html/www/convert.html  (on
       debian  system  you  may  install  the  imagemagick-6   package)   or
       https://www.imagemagick.org/script/convert.php.

It will use a compression which is relevant to the type of file you are using (jpegs are compressed differently than pngs). You may choose another type of compression using the -compress flag and specify None, BZip, Fax, Group4, JPEG, JPEG2000, Lossless, LZW, RLE or Zip.

Use the -quality option to set the compression level to be used by JPEG, PNG, MIFF, and MPEG encoders. Use the -sampling-factor option to set the sampling factor to be used by JPEG, MPEG, and YUV encoders for down-sampling the chroma channels.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .