Thursday, October 21, 2021

Reduce image size on Linux

ImageMagick provide tools on Linux to manipulate images such as those of the  JPEG, TIFF, PNM, GIF and Photo CD image formats. Default installation includes special effects that can be applied to the images.

Using other Linux scripts and commands, there are many uses to the tool provided by ImageMagick.

Install on Centos 

sudo yum install ImageMagick

Or

sudo dnf install ImageMagick


Resize images

convert original_apple.jpg -resize 1024 new_apple.jpg


Search files larger than 2Mb size in a directory and convert image to max width 2048 while preserving image ratio.

find directory_name -type f  -size +2M -exec convert {} -resize 2048 {} \;


Other actions by ImageMagick

Change image compression (value between 1 and 100)

convert original_apple.jpg -quality 95 new_apple.jpg


Resize image by height 

convert original_apple.jpg -resize x200 new_apple.jpg


Rotate an image

convert original_apple.jpg -rotate 180 new_apple.jpg


Convert PNG format to JPEG

convert original_apple.png original_apple.jpg

This will remove any transparency in PNG.


Apply an image effect.

convert original_apple.png -swirl 45 original_apple.jpg

Following are effects available:

-annotate geometry text

-charcoal radius

-enhance

-implode amount

-monochrome

-sketch geometry

-swirl degrees

-transpose

-transverse

No comments:

Blog Archive