Optimizing Images using command line

The images uploaded by users may not be of ideal size and may require compression to manage server space. There are some tools available for compressing JPG and PNG files.
Please note that the owner changes to the current username for the file after compression. Please remember to change ownership if required of the file or per folder post compression.

jpegoptim :
Optimize a jpg image with the same name

jpegoptim image.jpg

Optimize all jpg images in a folder

jpegoptim *.jpg

optipng:
Optimize an png image with the same name

optipng image.png

Optimize all png images in a folder

optipng *.jpg

--
https://www.tecmint.com/optimize-and-compress-jpeg-or-png-batch-images-l...
https://stackoverflow.com/questions/19153122/image-compression-tools-via...