views:

1946

answers:

3

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  A: 

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)
korro
I'd rather not have to make a separate call to get the image size. Since ImageMagick will have the image loaded, I was hoping to be able to reuse the size information.
A: 

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

Sparr
A: 

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
hacketiwack