Last active
February 19, 2018 14:25
-
-
Save in-in/be3e25fb6ab8b22c6247b92283156144 to your computer and use it in GitHub Desktop.
resize images two and three times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# prerequisites: libvips http://www.vips.ecs.soton.ac.uk | |
# http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/libvips-resample.html#vips-resize | |
# filename should looks like: `filename.jpg` | |
cwd=$(pwd) | |
# re='_([0-9]{2,4})\.(jpg|png)' | |
re='\.(jpg|jpeg|png)' | |
resize() | |
{ | |
# new_width=$(echo "$(vipsheader $1 -f width)"*$2 | bc) | |
# new_height=$(echo "$(vipsheader $1 -f height)"*$2 | bc) | |
ext=$(echo ${1##*.}) | |
new_filename=$(echo "${1//$(echo $1 | grep -ioE $re)}") | |
# result=$new_filename'_'$new_width'x'$new_height'@'$2'x'.$ext | |
result=$new_filename'_@'$2'x'.$ext | |
vips resize $filename $result $2 | |
} | |
for f in $cwd/*; do | |
path=$(basename "$f") | |
filename=$(echo $path | grep -iE $re) | |
if [[ $filename ]]; then | |
resize $filename '2' && resize $filename '3' | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change ext variable