Work with images

image info

$ identify demo.jpg 
demo.jpg JPEG 1660x600 1660x600+0+0 8-bit DirectClass 339KB 0.000u 0:00.000

// show image size
$ identify -ping -format "%f | %wx%h \n" red_chair_709x1000.jpg 
red_chair_709x1000.jpg | 709x1000

refer to: ImageMagick format option

resize image

$ convert demo.jpg  -resize 500x200 demo_resized.jpg
$ identify demo_resized.jpg // maintain aspect ratio
demo_resized.jpg JPEG 500x181 500x181+0+0 8-bit DirectClass 46.3KB 0.000u 0:00.000

bulk resize:

$ ls iphone_*
iphone_1102.png  iphone_1103.png  iphone_1104.png  iphone_1105.png

$ for f in `ls iphone*`; do echo $f; convert $f -resize 600 ${f%.*}_resized.${f##*.}; done

$ identify *resized*
iphone_1102_resized.png PNG 600x1067 600x1067+0+0 8-bit DirectClass 98.8KB 0.000u 0:00.000
iphone_1103_resized.png[1] PNG 600x1067 600x1067+0+0 8-bit DirectClass 210KB 0.000u 0:00.000
iphone_1104_resized.png[2] PNG 600x1067 600x1067+0+0 8-bit DirectClass 116KB 0.000u 0:00.000
iphone_1105_resized.png[3] PNG 600x1067 600x1067+0+0 8-bit DirectClass 268KB 0.000u 0:00.000

rotate an image

when you rotate an image in Shotwell, seems like it just add an tag Exif.Image.Orientation to the image, does not actually do anything with the pixel matrix, and this tag is not consistently honored by all programs handling images, the following command can actually work on the pixels

convert apple.jpg -rotate 90 apple-after.jpg

show/edit/remove EXIF data

show metadata:

exiv2 -p a pr apple.jpg

delete all metadata:

exiv2 -d a rm apple.jpg

convert image format

convert png to jpg:

for f in *png; do echo $f; convert -flatten -background white $f ${f%.*}.jpg; done;

convert and compress:

convert -strip -interlace Plane -quality 85% banner.png banner-no-blur.jpg

with Gaussian blur:

convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% banner.png banner.jpg

composite, add overlay to an image

composite overlay.png background.png result.png