Page 1 of 1

Help to simplify to one-line command

Posted: 2018-08-01T02:56:45-07:00
by fabkzo
Hi,
ImageMagick 6.8.9-9 Q16 x86_64 2018-06-26
Debian 3.16.51-3 (2017-12-13) x86_64 GNU/Linux

I'm writing a little bash script to create a pixellated bottom of images, with shadow and blur; it works as I want and I would use it on folders but I think It could be optimised with -clone option to avoid creation of intermediate files , thing I haven't succeeded in.

Code: Select all

	picture=$1
 	PWidth=$(identify -format "%w" $picture)
	PHeight=$(identify -format "%h" $picture)
	hauteurcrop=$(echo "$PHeight-($PHeight/9.6)"|bc)
 	stretch=20
	
	convert "$picture" -crop "$PWidth"x"$stretch"+0+"$(echo "$hauteurcrop"-"$stretch"|bc)" -resize "$PWidth"x"$(echo "$PHeight/9.6"|bc)"! -channel RGBA  tmp-patch.tif

	w=`convert tmp-patch.tif -format "%[fx:w]" info:`
	h=`convert tmp-patch.tif -format "%[fx:h]" info:`
	minify=`convert xc: -format "%[fx:100/90]" info:`
	
	convert tmp-patch.tif -sample $minify% -scale ${w}x${h}! +repage tmp-pixel.tif

	convert -crop "$PWidth"x"$(echo "$PHeight-($PHeight/80)"|bc)"+0+"$(echo "$PHeight/80"|bc)" tmp-pixel.tif tmp-pixel.tif
	
	convert -size "$PWidth"x"$(echo "$PHeight/80"|bc)" -define gradient:direction=north gradient:black-white -alpha Set -background none mask.tif
	
	composite mask.tif tmp-patch.tif -compose multiply  -gravity north tmp-patch.tif
	convert tmp-patch.tif -alpha set -virtual-pixel transparent -channel A  -morphology Convolve Blur:30x65000+90 -level 50x100% +channel tmp-patch.tif
	
	convert "$picture" -page +0+"$hauteurcrop" tmp-patch.tif -flatten output.tif
	
	composite tmp-pixel.tif output.tif -gravity south "${picture%.*}-patch.jpg"
	
 	rm tmp-patch.tif tmp-pixel.tif mask.tif output.tif
My goal is then to create a little GUI with choices as enabling/disabling shadows/blur/pixels etc ... but I'm stuck at this point.
Can someone help me to simplify it?

Best regards,