0

I'm trying to drop a shadow to a composition of two images: one JPEG/PNG and one SVG vector. With the PNG image everything works seamlessly. Now, trying with the JPEG, I get a black background instead of the expected transparent background.

The command looks like this:

convert image.jpeg -background white -flatten \( -background none vector.svg \) -compose CopyOpacity -gravity center -composite \( \+clone -background \#111 -shadow 80x5\+5\+5 \) -background none -compose DstOver -flatten result_from_jpeg.png

We start from this JPEG:

image.jpeg

or this PNG:

image.png

Then we compose the vector, that because is white, you'll not be able to see raw, so here it is with a grid below:

vector_over_grid.png

the real vector is this one: http://cl.ly/Xymi/vector.svg

An then we drop the shadow. Starting with the PNG we get it right (transparent background):

result_from_png.png

but with JPEG, the background is black instead:

result_from_jpeg.png

All files can be downloaded here in a ZIP: http://cl.ly/Xz8V/Archive%202014-10-10%20at%2011.34.55%20am.zip

Any ideas of what could be happening? Thanks in advance!!

EDIT:

My version of IM:

Version: ImageMagick 6.8.8-9 Q16 x86_64 2014-03-28 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg lcms ltdl png tiff xml zlib

I'm developing on Mac OSX.

Community
  • 1
  • 1
nandilugio
  • 315
  • 2
  • 11
  • Wroks as expected on my IM Version: ImageMagick 6.8.9-7 Q16 x86_64 2014-09-10 – Mark Setchell Oct 10 '14 at 11:09
  • Thx @MarkSetchell I've updated the description with my version. Looks like a bug that got fixed... – nandilugio Oct 10 '14 at 11:17
  • @MarkSetchell I've upgraded IM to your version but still fails the same. One interesting test: `convert result_from_png.png test.jpg` flattens out the image, obviously, and makes the background black! Thinking about hidden color behind transparency... – nandilugio Oct 10 '14 at 11:42
  • A coworker tried in his machine with the original version I had (6.8.8-9) and worked for him. Also tested on a linux machine with somehow older version... worked too. I probably have some lib that is giving the problem :s – nandilugio Oct 10 '14 at 12:05

1 Answers1

0

Ok problem solved!! snibgo helped me over the ImageMagick forums.

Even though we couldn't understand the difference between my setup and the rest of the people that tried and didn't observe the problem, we did refactor the shadow portion of the command to a more correct way that in fact works well for both sources, jpeg and png:

convert image.jpeg -background white -flatten \
    \( -background none vector.svg \) \
    -compose CopyOpacity -gravity center -composite \
    \( +clone -background \#111 -shadow 80x5+5+5 \)
    +swap -background None -compose Over -layers merge \    # This is new
    correct_output.png

The whole discussion can be found here:

http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=26363

nandilugio
  • 315
  • 2
  • 11