Differences

This shows you the differences between two versions of the page.

Link to this comparison view

howto:compress_or_resize_images_in_bash [2016/11/23 07:38]
yehuda created
howto:compress_or_resize_images_in_bash [2019/05/30 09:14] (current)
yehuda
Line 20: Line 20:
  
 see more options: https://www.imagemagick.org/script/convert.php see more options: https://www.imagemagick.org/script/convert.php
 +
 +====== Resize image to minimal rate ======
 +
 +How about using ImageMagick's convertwhich has exactly such a minimal size option, see Image Geometry options?!
 +
 +Copy & Paste snippet (bash syntax) -- please notice the ^ after the size specification:
 +<code bash>
 +for file in *.jpg; do
 +   echo -n Converting ${file}...
 +   convert -resize 180x180^ "$file" "th_$file"
 +   echo done
 +done
 +</code>
 +
 +In addition, if you want to crop the resulting file to a quadratic shape around the center, you can use this script. The SIZE parameter in the first line specifies (surprise, surprise) the final size of the thumbnail.
 +<code bash>
 +SIZE=180
 +for file in *.jpg; do
 +   echo -n Converting ${file}...
 +   convert -resize ${SIZE}x${SIZE}^ "$file" temp.png
 +   convert -crop $(identify temp.png | awk -F'[ x]' -v SIZE=$SIZE '{ printf "%ux%u+%u+%u", SIZE, SIZE, ($3-SIZE)/2, ($4-SIZE)/2 }') temp.png "th_$file"
 +   echo done
 +done
 +rm temp.png
 +</code>
 +
 +The script is not very optimized, as it runs two commands (identify and convert -crop) on the thumbnail. But as the thumbnail is only small, I think the speed is reasonable.
 +
 +from: https://superuser.com/questions/676887/resize-image-to-a-maximum-size-on-command-line
howto/compress_or_resize_images_in_bash.txt ยท Last modified: 2019/05/30 09:14 by yehuda
Back to top
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0