Skip to content

Instantly share code, notes, and snippets.

@ionvision
Last active December 7, 2016 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionvision/3f225987d317a48b40a16b54604b5620 to your computer and use it in GitHub Desktop.
Save ionvision/3f225987d317a48b40a16b54604b5620 to your computer and use it in GitHub Desktop.
Basic usage of imagemagick
  • Convert a png file to jpg file

convert image.png image.jpg

  • Convert all png files to jpg files

mogrify -format jpg *.png

or loop version

for i in .png ; do convert "i" "{i%.}.jpg" ; done

or xargs version with name-mangling

ls -1 .png | xargs -n 1 bash -c 'convert "0" "{0%.}.jpg"'

or parallel version

ls -1 *.png | parallel convert '{}' '{.}.jpg'

  • Rescale the images

convert -resize 50% screen.jpg

convert -resize 600x600 screen.jpg:

1920x1200 => 600x375

600x1200 => 300x600

150x300 => 300x600

300x150 => 600x300

mogrify -resize 600x600> *.jpg:

1920x1200 => 600x375

600x1200 => 300x600

150x300 => 150x300 (is not resized to bigger size)

300x150 => 300x150 (is not resized to bigger size)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment