Page 1 of 1

[HELP] Transparency problems

Posted: 2007-09-02T17:20:19-07:00
by CAFxX
hi all, this is my first post here.
it has probably been asked before, but I wasn't able to find it. my problem is that I have to rasterize a vector image (say, in EPS format) with a transparent background and save it as a transparent PNG24.
what happens is that the rasterized image background becomes solid white, regardless of -type truecolormatte and similar.
can anyone explain why it happens? does workarounds exist?
thank you, CAFxX.

Re: rasterizing vector images

Posted: 2007-09-03T00:19:00-07:00
by CAFxX
this is the problematic snippet:

Code: Select all

<?php
		$ys = 20;
		$xe = 1000;
		$ye = 200;
		$wd = 600;
		$hd = 220;
		$file = 'vettoriali/header-back.eps';
		$temp = '/tmp/c4d-'.md5('c4d'.time().microtime().rand()).'.png';
		$cmd =  "convert -type truecolormatte -size ${xe}x$hd xc:transparent ".
				"-fill \"rgba(0,0,0,0.50)\" -draw \"rectangle 0,$ys $xe,$ye\" ".
				"-draw \"image src-over ".($xe-$wd).",0 $wd,$hd $file\" ".
				"$temp";
		error($cmd);
		exec($cmd);
		header("Content-Type: image/png");
		readfile($temp);
		unlink($temp);
?>
and this is the result:
Image
as you can see, the vector image is rasterized with a solid white background, even though the rest is correctly transparent.
moreover, even the rectangle fill isn't transparent at all, so I guess I'm missing something here...

Re: [HELP] Transparency problems

Posted: 2007-09-05T19:55:04-07:00
by anthony
set -background none

See IM Examples, Text to Image Handling, Postscript
http://www.imagemagick.org/Usage/text/#postscript

Re: [HELP] Transparency problems

Posted: 2007-09-05T23:58:45-07:00
by CAFxX
Tried, but without luck.
What puzzles me is that if $file is the image in vector format, the solid backgorund appears. But if it is a png file with transparency (made with photoshop from the vector image, or even by convert itself in a separate call), there's no solid background.

The only way found so far is to do tho passes:

Code: Select all

convert -channel RGBA -background none $file -size ${wd}x$hd $temp-1.png;
convert -type truecolormatte -size ${xe}x$hd xc:transparent \
    -matte -fill '#00000080' -draw "rectangle 0,$ys $xe,$ye" \
    -draw "image src-over ".($xe-$wd).",0 $wd,$hd $temp-1.png" \
    $temp-2.png
still, it looks weird that I can't do it in just one call, without saving/reopening the intermediate image...

Re: [HELP] Transparency problems

Posted: 2007-09-06T00:18:10-07:00
by anthony
What is you difference between temp-1 and temp-2?
You should be able to do it in one command.
You may have to turn off the channel setting later using +channel or it could effect other image operators.

Re: [HELP] Transparency problems

Posted: 2007-09-06T00:21:45-07:00
by CAFxX
temp-1 is where the rasterized vector image is placed, temp-2 is where the final composite image is stored to be read and sent by php's readfile.

Re: [HELP] Transparency problems

Posted: 2007-09-06T00:38:01-07:00
by anthony
It seems to me that the EPS bay be drawing the white background. Can you give a link to the image being used.

Re: [HELP] Transparency problems

Posted: 2007-09-06T00:40:44-07:00
by CAFxX
the problem occurs with svg as well...

here you go: http://cafxx.strayorange.com/tmp/header-back.svg

Re: [HELP] Transparency problems

Posted: 2007-09-06T01:11:57-07:00
by CAFxX
not quite related to this: how can I specify the "native" rasterizing resolution?
"convert -size w,h" does not work... the only way is to specify "convert -density [bignumber] -resize w,h" but this does not look that elegant...

Re: [HELP] Transparency problems

Posted: 2007-09-06T19:08:32-07:00
by anthony
The -density setting sets the native rasterizing resolution, -size is not used for SVG.
The -resize is usually only used for postscript which often comes out badly from the ghostscript delegate. The same is for the -channel setting, whcih could interfer with many other operations. The -type truecolormatte is a setting used for input and output of file formats.

I figrued out your problem... I have been caught out by this myself!
-draw draws on ALL images in the current image sequence!

If you read the SVG first, then try to draw on a second image, you draw on both!
try this....

Code: Select all

convert -size 1000x220 xc:transparent \
        -draw "fill #0008 rectangle 0,20 1000 200" \
        -background none header-back.svg \
        -geometry 600x220+400+0 -composite   result.png
The -geometry is a special operator that resizes the LAST image only
ans sets the composition offset (gravity effected). -composite uses the default
composition method 'Over'.

You were probably using src-over to replace pixels to try and fix the problem of -draw drawing all over the original SVG image.

If you wanted to read the SVG image first. Put the -draw processing in parenthesis to limit it to just the second image...

Code: Select all

convert -background none header-back.svg \
         \( -size 1000x220 xc:transparent \
             -draw "fill #0008 rectangle 0,20 1000 200" \
         \) +swap  -geometry 600x220+400+0 -composite   result.png
the +swap swaps the two images before -geometry resizes the LAST image.

I suggest you read BASICS in IM Examples (see signature). and remember
IN general, operators work on ALL images in the current image sequence