Search code examples
command-lineimagemagickimagemagick-convert

Image reflection using imagemagick command line?


Original Image

enter image description here

convert image.jpg -scale 310x496\! scaled.png
convert scaled.png +clone -flip -crop 310x150 -compose Dst -composite  out/shadow.png
convert -size 310x150 -alpha set gradient:rgba\(255,0,255,0.6\)-rgba\(255,255,0,0.50\) out/grad.png
convert out/shadow.png out/grad.png -compose Dst_Out  -composite out/shadow_gradiented.png
convert shadow_gradiented.png out/shadowed.png -append out/final.png

I am getting following output

enter image description here

But I want my output to be like following.

enter image description here

What am i doing wrong? Suggest me.

Additional: Is there any way I can make all in one command.


Solution

  • Not certain what you are trying to achieve, but this might get you started:

    convert wolf.jpg -scale 310x496\! \
       \( +clone -flip -crop x150+0+0\! -alpha set -channel A -fx "0.6" \) -append result.png
    

    enter image description here


    If you want the alpha tailing off, try a formula that is a function of j (the distance from the top of the reflection) and h (the total height of the reflection).

    convert wolf.jpg -scale 310x496\! \
       \( +clone -flip -crop x150+0+0\! -alpha set -channel A -fx "0.8-(0.6*j)/h" \) -append result.png
    

    If you want the code to be a bit more generic, and less dependent on actual sizes, you could change the height of the reflection to, say 1/4, of the height of the original (note the change from convert to magick)

    magick wolf.jpg -scale 310x496\! \
       \( +clone -flip -crop "x%[fx:h/4]+0+0\!" -alpha set -channel A -fx "0.8-(0.6*j)/h" \) -append result.png