Created
December 1, 2015 10:02
-
-
Save redrohX/f38d7e48ceb22734d231 to your computer and use it in GitHub Desktop.
Imagemagick shell script
This file contains hidden or 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 | |
root=$PWD | |
#list=`find media/catalog/category/cache media/catalog/product/cache media/wysiwyg -type d` | |
list=`find media/catalog/output/folder1 media/catalog/output/folder3 -type d` | |
watermark="Kega Imagemagick" | |
green='\033[0;32m' | |
nocolor='\033[0m' | |
imagecount=1 | |
count=0 | |
spinner() | |
{ | |
local pid=$1 | |
local delay=0.1 | |
local spinstr='|/-\' | |
echo "$pid" > "/tmp/.spinner.pid" | |
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do | |
local temp=${spinstr#?} | |
printf " [%c] " "$spinstr" | |
local spinstr=$temp${spinstr%"$temp"} | |
sleep $delay | |
printf "\b\b\b\b\b\b" | |
done | |
printf " \b\b\b\b" | |
} | |
imagemagick() | |
{ | |
convert $file -filter Triangle \ | |
-define filter:support=2 \ | |
-unsharp 0.25x0.25+8+0.065 \ | |
-dither None \ | |
-posterize 136 \ | |
-quality 82 \ | |
-define jpeg:fancy-upsampling=off \ | |
-interlace none \ | |
-colorspace sRGB \ | |
-strip \ | |
-set comment "${watermark}" \ | |
-quiet $file | |
} | |
for directory in $list; do | |
cd $root/$directory | |
for file in *; do | |
if [ ! -d "${file}" ]; then | |
identity=`identify -format %c $file` | |
origsize=`(wc -c <"$file")` | |
if [ ! "$identity" == "$watermark" ] && [[ $file == *.jpg || $file == *.jpeg ]]; then | |
count=1 | |
(imagemagick) & | |
printf "${imagecount} Processing ${directory}/$file \n Original size: $origsize bytes " | |
spinner $! | |
printf "| New size:${newsize=$(wc -c <"$file")} bytes | Saved: $(($origsize-$newsize)) bytes | ${green}Done!${nocolor} \n" | |
(( imagecount++ )) | |
fi | |
fi | |
done | |
cd $root | |
done | |
if [ $count == 0 ]; then | |
echo "No new images to process" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment