Page 1 of 2
Black background (instead of transparent) after drop shadow
Posted: 2014-10-10T02:55:37-07:00
by nandinga
Hi!
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:
Code: Select all
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

or this 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:

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

but with JPEG, the background is black instead:
All files can be downloaded here in a ZIP:
http://cl.ly/Xz8V/Archive%202014-10-10% ... 5%20am.zip
Any ideas of what could be happening?
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T03:37:42-07:00
by snibgo
Running your command on your files with IM 6.8.9-5, with Inkscape v0.48, the result from the JPEG looks the same as from the PNG.
What version of IM are you using? What is the SVG renderer?
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T04:10:27-07:00
by nandinga
Hi! Thx!! Not sure what you mean about the SVG renderer, but:
Code: Select all
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 on OsX.
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T04:40:58-07:00
by nandinga
I've upgraded IM to this version (a bit newer than yours):
Code: Select all
Version: ImageMagick 6.8.9-7 Q16 x86_64 2014-10-10 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg lcms ltdl lzma png tiff xml zlib
It still fails the same.
One interesting test:
Code: Select all
convert result_from_png.png test.jpg
flattens out the image, obviously, and makes the background black! Thinking about hidden color behind transparency...
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T05:03:12-07:00
by snibgo
nandinga wrote:Not sure what you mean about the SVG renderer ...
What is the output from:
Code: Select all
convert -background None vector.svg s.png
Does it mention Inkscape?
What does s.png look like? Is it a white cutout shape against a transparent background, or entirely opaque white?
nandinga wrote:... flattens out the image, obviously, and makes the background black!
Those pixels in the png are transparent black. If you want a different colour, eg red:
Code: Select all
convert result_from_png.png -background red -flatten test.jpg
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T07:15:47-07:00
by nandinga
Code: Select all
convert -background None vector.svg s.png
outputs nothing to console (nothing about Inkscape, in fact never seen anything related, and wasn't expecting any output). The generated s.png looks correct: the vector rendered white over transparent background.
Code: Select all
identify -verbose s.png | grep -i inkscape
outputs nothing either.
Code: Select all
convert result_from_png.png -background red -flatten test.jpg
yup... tried putting -background none about everywhere in the command but wasn't able to fix the problem doing so :s
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T08:03:58-07:00
by snibgo
Sorry, I meant, what is the text output from:
Code: Select all
convert -verbose -background None vector.svg s.png
As you get the expected s.png, I doubt that is the problem.
Does your shell need "+" and "#" to be escaped?
Please insert "+write shad_x1.png" after "-composite", so the command is now:
Code: Select all
convert image.jpeg -background white -flatten \( -background none vector.svg \) -compose CopyOpacity -gravity center -composite +write shad_x1.png \( \+clone -background \#111 -shadow 80x5\+5\+5 \) -background none -compose DstOver -flatten result_from_jpeg.png
Is shad_x1.png like this:

Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T08:28:14-07:00
by nandinga
Ah, yes, there is Inkscape... :p
Code: Select all
$ convert -verbose -background None vector.svg s.png
"inkscape" "vector.svg" --export-eps="/var/tmp/magick-33126aSUB52u1R4o0" --export-dpi="90,90" --export-background="rgb(0%,0%,0%)" --export-background-opacity="0" > "/var/tmp/magick-331261TvU31zBnx9Z" 2>&1
mvg:/var/tmp/magick-33126Q6WfzqePU2mI=>/var/tmp/magick-33126Q6WfzqePU2mI MVG 500x500 500x500+0+0 16-bit sRGB 1.25KB 0.040u 0:00.039
vector.svg SVG 500x500 500x500+0+0 16-bit sRGB 1.25KB 0.000u 0:00.000
vector.svg=>s.png SVG 500x500 500x500+0+0 8-bit sRGB 8.76KB 0.020u 0:00.019
I can't see your version of your shad_x1.png image but here is mine:

This is the correct output at this stage. The problems come when drawing the shadow. In fact, the sublist that generates the shadow itself works, and if you look closely the final image, the shadow is there, composed in the right place. The only problem we have is a black background instead of transparent.
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T08:30:16-07:00
by nandinga
The above makes the vectorial part look like there's no problem there. Do you know a way to check and compare our libjpeg versions? and/or maybe libpng?
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T08:52:56-07:00
by snibgo
Your verbose output show it is trying Inkscape, but then using MVG. MVG sometimes give bad results, but not in this case.
nandinga wrote:I can't see your version of your shad_x1.png image but here is mine:
Yours looks correct, like mine. (I don't know why you can't see mine. I probably copied the wrong URL. Sorry. I'm having a bad day.)
I think the problem is the final "flatten". This shouldn't (I think) leave any pixels transparent. I don't know why it does for me.
Instead of:
Code: Select all
-background none -compose DstOver -flatten
try:
Code: Select all
+swap -background None -layers merge
This is the "approved" technique for adding shadows.
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T11:22:35-07:00
by nandinga
Did that work for you? I get this:
BUT ...looks like the right direction to go

Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T12:14:55-07:00
by snibgo
Yeah, the single command needs a "-compose Copy". Sorry. It is a very bad day. My command is now:
Code: Select all
%IM%convert ^
image.jpeg ^
-background white -flatten ^
( -background none vector.svg ) ^
-compose CopyOpacity -gravity center -composite ^
+write shad_x1.png ^
( +clone -background #111 -shadow 80x5+5+5 ) ^
+swap -background None -compose Copy -layers merge ^
shad_x4.png
(This is Windows BAT syntax. Adjust as required.)
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T13:01:17-07:00
by nandinga
Nop :s ..now the shadow is lost.

are you getting same results as me? or all your results where good?
PD: can't be such a bad day... you're helping me a lot!!

Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T13:09:24-07:00
by nandinga
btw, this version of the command doesn't work with the png either :s
Re: Black background (instead of transparent) after drop sha
Posted: 2014-10-10T13:20:46-07:00
by snibgo
snibgo wrote:-compose Copy
Snibgo, you idiot. You need to restore the default compose, after the first "-compose" changed it to "CopyOpacity". The default isn't "Copy" but "Over". So that second compose should be not "-compose Copy" but "-compose Over".
I'm a double idiot for not seeing that the shadow wasn't there.
Code: Select all
%IM%convert ^
image.jpeg ^
-background white -flatten ^
( -background none vector.svg ) ^
-compose CopyOpacity -gravity center -composite ^
+write shad_x1.png ^
( +clone -background #111 -shadow 80x5+5+5 ) ^
+swap -background None -compose Over -layers merge ^
shad_x4.png