Elongated “Shadow” Script
Posted: 2019-05-15T12:27:57-07:00
I am trying to duplicate the shadow effect seen on the green icon here:
using command line imagemagick, version 7.0.8-34 on Mac. The drop shadow is pretty straightforward with -shadow command. The elongated shadow is giving me troubles.
Given the inputs foreground.png (That has transparent bits to it, and the alpha channel set), background.png, and size…
The first strategy I tried to use was a custom -fx to output the maximum alpha value between the source pixel and the pixel immediately west and north of the source pixel:The problem here is that the p[-1,-1] refers to the source image, not the copy being manipulated. I suspect it isn’t possible to reference the being-manipulated copy. So I could just that run that command size - 1 times. Not fun.
The second strategy relies on -motion-blur. Motion blur the foreground in a certain direction, even out the alpha, then blacken the result:The problem I'm running into there is getting the right magicSigma. If the magicSigma is too high, it blurs too much out to the sides, so I lose the elongated shadow effect. If it’s too low, the shadow doesn’t reach to the southwestern corner.
Any suggestions as to how I can improve either method?
using command line imagemagick, version 7.0.8-34 on Mac. The drop shadow is pretty straightforward with -shadow command. The elongated shadow is giving me troubles.
Given the inputs foreground.png (That has transparent bits to it, and the alpha channel set), background.png, and size…
The first strategy I tried to use was a custom -fx to output the maximum alpha value between the source pixel and the pixel immediately west and north of the source pixel:
Code: Select all
magick foreground.png -channel A -fx 'min(max(p.a, p[-1,-1].a),0.04)' -channel-fx 'red=0 green=0 blue=0' shadow.png
The second strategy relies on -motion-blur. Motion blur the foreground in a certain direction, even out the alpha, then blacken the result:
Code: Select all
magick foreground.png -channel-fx 'red=0 green=0 blue=0' -channel A -motion-blur "0x$magicSigma+215" foreground.png -fx 'ceil(u.a) - 0.96 - (0.04 * v.a)' -blur 0x2 shadow.png
Any suggestions as to how I can improve either method?