Every so often, I try to upload a picture to a website and encounter a message:
Upload failed: the file size can't exceed n MB!
I know that resizing the picture's dimension should get me below n at a certain point, but the process of resizing, saving, checking file size is cumbersome. Furthermore, at times it may be handy to keep the current dimensions.
I'm looking for a way to change a picture's file size, preferably from the terminal. Is there a way to do this?
jpegoptim
First install
jpegoptim
viaThen either try to optimize filesize of your image via
or if you need a defined size via
This will overwrite the image - to make sure you have a backup while testing with
jpegoptim
.mogrify (imagemagick)
Resizing
You could as well use
mogrify
which is part ofimagemagick
. The following example shrinks the image dimensions to 50% (so resizing - not compressing)Compressing
The following example shows compressing with
mogrify
:convert (imagemagick)
Compressing
Compressing to 80% using convert works as follows:
Convert somes with a huge set of options, so you could use
which should according to this post:
trimage
I am quoting the project page here
You can simply install it via
After starting via just the application name you might see the UI
If you need more information about trimage either visit the project page or run
trimage -h
to take a look on the help.Other tools
There is as well
optipng
,pngcrush
,jpegtran
and several other tools in the image-size-optimization-corner .... but i've never used them.I'll end with some links