Skip to content

Instantly share code, notes, and snippets.

@in-in
Last active February 19, 2018 14:25
Show Gist options
  • Save in-in/be3e25fb6ab8b22c6247b92283156144 to your computer and use it in GitHub Desktop.
Save in-in/be3e25fb6ab8b22c6247b92283156144 to your computer and use it in GitHub Desktop.
resize images two and three times
#! /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
@in-in
Copy link
Author

in-in commented Mar 5, 2017

change ext variable

@in-in
Copy link
Author

in-in commented Feb 19, 2018

update output name

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