Page 1 of 1

3D reflection has black background instead of transparency

Posted: 2012-01-23T06:20:44-07:00
by neuro
I want to apply the 3D reflection technique to a series of square images. At present, wen I apply it to a png with alpha transparency, the cloned mirror image displays black instead of transparent.

I'm using the following command:

convert original-500x500.png -alpha on \
\( +clone -flip \
-size 500x350 gradient:gray40-black \
-alpha off -compose copyOpacity -composite \
\) -append \
+distort Perspective '0,0,0,0 0,500,0,500 500,0,450,50 500,500,450,450' \
-gravity North -crop 500x1000+0-15\! \
-background transparent -compose Over -flatten 3D_result.png

Here is an example of what is produced:

Image

Is there something I am doing wrong? Or is this a bug?

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-23T12:12:15-07:00
by fmw42
try adding -alpha on -virtual-pixel transparent before your +distort perspective. Just a guess. I did not try it.

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-24T06:30:36-07:00
by neuro
That didn't work either I'm afraid. :(

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-24T11:34:53-07:00
by fmw42
This works perfectly fine for me on IM 6.7.4.8 Q16 Mac OSX Snow Leopard, giving a transparent outside and not black!
What version of IM are you using?


convert -size 500x500 pattern:checkerboard -alpha set \
\( +clone -flip \
-size 500x350 gradient:gray40-black \
-alpha off -compose copyOpacity -composite \
\) -compose over -append \
-alpha set -virtual-pixel transparent +distort Perspective '0,0,0,0 0,500,0,500 500,0,450,50 500,500,450,450' \
-gravity North -crop 500x1000+0-15\! \
-background transparent -compose Over -flatten tmp.png

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-25T01:29:52-07:00
by neuro
That still fails for me. Interestingly with a png it does exactly the same as above, but with the checkerboard pattern (as in yours) it does this...

Image

For some reason, it pulls the top row of pixels into towards the centre. This 'bug' also carries over to jpegs too.

I managed to get the 3D reflection working (sans errors) with the following script:

infile="test.png"
ramp=40
spacer=0
fade=100
ww=`convert $infile -format "%w" info:`
hh=`convert $infile -format "%h" info:`
hhr=`convert xc: -format "%[fx:$hh*$ramp/100]" info:`
convert $infile \
\( -size ${ww}x${spacer} xc:none \) \
\( -clone 0 -flip -crop ${ww}x${hhr}+0+0 +repage \) \
\( -clone 0 -alpha extract -flip -crop ${ww}x${hhr}+0+0 +repage \
-size ${ww}x${hhr} gradient: +level 0x${fade}% \
-compose multiply -composite \) \
\( -clone 2 -clone 3 -alpha off -compose copy_opacity -composite \) \
-delete 2,3 -channel rgba -alpha on -append \
+distort Perspective '0,0,0,0 0,500,0,500 500,0,450,50 500,500,450,450' \
-gravity North -crop 500x1000+0-15\! rounded_corner_vreflect.png

But I have yet to make this fully friendly for various image sizes. Also, I'd like to know if it's just a bug in IM that is causing me problems with the original scripts.

My imagemagick version number is: 8:6.6.0.4-3ubuntu1.

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-25T10:27:20-07:00
by fmw42
Was the picture generated from my exact code? If so, then something seems wrong with your IM version. Seems like your -virtual-pixel transparent is getting ignored and defaulting to -virtual-pixel edge. The offset is probably due to needing +repage to reset the virtual canvas or remove the offsets from your crop. If you have changed my code or using it in PHP, then please post the code that you used to generate the checkerboard image.

8:6.6.0.4-3ubuntu1 is not an IM version. Perhaps 6.6.0.4?

try

convert -version

to get the IM version.

Perhaps you need to upgrade as it does not do that for me.

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-26T02:36:08-07:00
by neuro
I copied your code to the letter.

And yes, it is version 6.6.0-4

Code: Select all

convert -version
Version: ImageMagick 6.6.0-4 2011-06-15 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP 
Apt just pulls up more package/maintatiners information

Code: Select all

Package: imagemagick
Priority: optional
Section: graphics
Installed-Size: 284
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: ImageMagick Packaging Team <pkg-gmagick-im-team@lists.alioth.debian.org>
Architecture: i386
Version: 8:6.6.0.4-3ubuntu1
Depends: libc6 (>= 2.3.6-6~), libmagickcore3 (>= 8:6.6.0.4), libmagickwand3 (>= 8:6.6.0.4)
Recommends: libmagickcore3-extra, ghostscript, netpbm
Suggests: imagemagick-doc, autotrace, cups-bsd | lpr | lprng, curl, enscript, ffmpeg, gimp, gnuplot, grads, groff-base, hp2xx, html2ps, libwmf-bin, mplayer, povray, radiance, sane-utils, texlive-base-bin, transfig, xdg-utils, ufraw-batch
Filename: pool/main/i/imagemagick/imagemagick_6.6.0.4-3ubuntu1_i386.deb
Size: 48710
MD5sum: 3e375b3358278c28f1f5f8d7490acf31
SHA1: 82979857619a905a46ad76c6fcf925824c1038dd
SHA256: abb4938a54b272ed928d7063edafd0fa77dbd57fde5e6c5b4e953165cdf2965b
Description-en: image manipulation programs
 ImageMagick is a software suite to create, edit, and compose bitmap images.
 It can read, convert and write images in a variety of formats (over 100)
 including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript,
 SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale,
 shear and transform images, adjust image colors, apply various special
 effects, or draw text, lines, polygons, ellipses and Bézier curves.
 All manipulations can be achieved through shell commands as well as through
 an X11 graphical interface (display).
Homepage: http://www.imagemagick.org/
Description-md5: 7c91199cdb23d3f0345a662d072b5a37
Is this a bug with my specific version then?

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-26T11:47:26-07:00
by fmw42
Sorry, I suspect so, but would not guarantee that it is not something else wrong with your configuration. The IM developers would have give you more information about that.


Try this:

convert -size 500x500 pattern:checkerboard -alpha set \
\( +clone -flip \
-size 500x350 gradient:gray40-black \
-alpha off -compose copyOpacity -composite \
\) -compose over -append \
-alpha set -background none -virtual-pixel background +distort Perspective '0,0,0,0 0,500,0,500 500,0,450,50 500,500,450,450' \
-gravity North -crop 500x1000+0-15\! \
-background transparent -compose Over -flatten tmp.png

Any difference?

Just curious, but why did you want the -15 pixel y offset in your crop?

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-27T01:23:23-07:00
by neuro
Ooops, that crop was copied over from another example. It's not needed.

Here's the results from your latest test code... still the same problem. Very strange! I take it this works for you? What version are you using?

Image

Re: 3D reflection has black background instead of transparen

Posted: 2012-01-27T10:46:59-07:00
by fmw42
IM 6.7.4.10 Q16 Mac OSX Snow Leopard.