ImageMagick Reflection

走远了吗. 提交于 2019-12-22 05:59:15

问题


Brief:

convert ( -size 585x128 gradient: )  NewImage.png

How do I change the above ImageMagick command so it takes the width and height from an existing image? I need it to remain a one line command.


Details:

I'm trying to programatically create an image reflection using ImageMagick. The effect I am looking for is similar to what you would see when looking at an object on the edge of a pool of water. There is a pretty good thread on what I am trying to do here but the solution isn't exactly what I am looking for. Since I will be calling ImageMagick from a C#.Net application I want to use one call without any temp files and return the image through stdout. So far I have this...

convert OriginalImage.png  ( OriginalImage.png -flip -blur 3x5 \
    -crop 100%%x30%%+0+0 -negate -evaluate multiply 0.3 \
    -negate  ( -size 585x128 gradient: ) +matte -compose copy_opacity -composite )
    -append NewImage.png

This works ok but doesn't give me the exact fade I am looking for. Instead of a nice solid fade from top to bottom it is giving me a fade from top left to bottom right. I added the (-negate -evaluate multiply 0.3 -negate) section in to lighten it up a bit more since I wasn't getting the fade I wanted. I also don't want to have to hard code in the size of the image when creating the gradient ( -size 585x128 gradient: ) I'm also going to want to keep the original image's transparency if possible.

To go to stdout I plan on replacing "NewImage.png" with "-"


回答1:


If you are calling it from C#, perhaps you could get retrieve the image dimensions in C#. Then call the ImageMagick command with

command = String.Format("convert bar %1x%2",img.Width,img.Height)



回答2:


You should take the existing image as an input, and create the gradient yourself using -fx instead of using the gradient pseudo-format.




回答3:


May be this can help: Reflection under an image

#!/bin/sh

gamma=$1
source=$2
destination=$3
size=`identify -format "%wx%h" $source`

convert $source \
  \( -size $size xc:none \
  \( \( -flip $source -crop $size+0+0 \) \
  -size $size gradient: -gamma $gamma \
  -compose copy_opacity -composite \) \
  -compose blend -composite \) \
  -append $destination


来源:https://stackoverflow.com/questions/198928/imagemagick-reflection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!