Help to simplify to one-line command

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Posts: 6
Joined: 2018-07-31T06:03:18-07:00
Authentication code: 1152

Help to simplify to one-line command

Post by fabkzo »

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

 	PWidth=$(identify -format "%w" $picture)
	PHeight=$(identify -format "%h" $picture)
	hauteurcrop=$(echo "$PHeight-($PHeight/9.6)"|bc)
	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,