Differences

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

Link to this comparison view

Next revision
Previous revision
howto:compress_or_resize_images_in_bash [2016/11/23 07:38] – created yehudahowto:compress_or_resize_images_in_bash [2022/01/03 16:03] (current) – external edit 127.0.0.1
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.1479886687.txt.gz · Last modified: (external edit)
Back to top
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0