SVG overlay and transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ClaretAndy

SVG overlay and transparency

Post by ClaretAndy »

Hello,

I'm new to ImageMagick, but so far my experience of using it has been good. I'm currently using the command line tools (version 6.2.8) in a shell script to graph data using gnuplot (and output in SVG format), and then patch a background (png) onto it using imagemagick. Sounds easy!

I'd like to use SVG because in the output image looks much better as opposed to converting SVG->PNG, and overlaying. I tried this, but the results are too blocky.

So, anyway, here's images ...
SVG image
PNG underlay

In the SVG, I have a background polygon set to transparent ...

Code: Select all

<polygon opacity="0" 
... so I would assume this command would work ....

Code: Select all

convert underlay.png radarline.svg -composite outtest.png
... but it doesn't. Like I said before, I could convert the SVG to PNG, and then overlay it ...

Code: Select all

convert radarline.svg -bordercolor white -border 1x1 -matte -fill none -fuzz 0% -draw 'matte 1,1 replace' -shave 1x1 -quality 100 -density 300 -resize 567x567 radarline_new.png
convert radarline6.png -fuzz 100% -fill white -opaque "rgb(34,63,140)" radarline-new.png
convert underlay_export.png radarline-new.png -composite -quality 100 -density 300 -resize 567x567 radar_final.jpg
... but the SVG line appears too blocky.

So, does anybody have any suggestions about how to either get IM to recognise the transparency in the SVG file, or to suggest a work around?

Thanks for your help.
Andy
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG overlay and transparency

Post by anthony »

Why not get "gnuplot" to output the graph in PNG directly?

For example I do this in my histogram graphing script
http://www.imagemagick.org/Usage/scripts/im_graph

Which I use to generate the graphs throughout the IM Examples, Color Modification page.
http://www.imagemagick.org/Usage/color/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ClaretAndy

Re: SVG overlay and transparency

Post by ClaretAndy »

Hi Anthony,

Thanks for your reply. I'm not usually so picky, but the images are to go in a published report, so they have to be hugh quality. I didn't like the option of outputting in PNG from gnuplot, because it produced a blocky png. In the end, I kind of solved my problem by increasing the resolution of the PNG output from gnuplot, and then resizing with IM. I'm reasonably happy with the result, although at different angles, the lines appear to be a different thickness.

Anyway, for anyone who's interested, here's the gnuplot code ...

Code: Select all

set terminal png transparent enhanced nocrop rounded size 2000,2000 xffffff xffffff
set out "radarline_gnu.png"

set rmargin 21
set lmargin 21
set tmargin 0
set bmargin 0

unset border
set angles degrees
set grid polar 60 front
set grid front
unset key
set polar
set size ratio 1 1,1

set style line 1 lw 30 lc rgb "#ffffff"
set style data lines

unset xtics
unset ytics 

set xrange [ -10 : 10 ] noreverse nowriteback
set yrange [ -10 : 10 ] noreverse nowriteback

# Plot just the white line ... 
plot "angola.txt" with lines ls 1
... and the IM commands ...

Code: Select all

convert radarline_gnu.png -resize 567x567 -matte -fill none -draw 'matte 1,1 replace' radarline_gnu2.png
convert underlay.png radarline_gnu2.png -composite -quality 100 -density 300 -resize 567x567 radartest.jpg
I would still be interested to hear from anyone that was successful in overlaying an SVG with transparency, because the results (when displayed in GIMP) are perfect.

Andy
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG overlay and transparency

Post by anthony »

For SVG... is your IM compiled to use the RSVG library. This will produce good SVG to raster conversions.

See IM Examples on using SVG
http://www.imagemagick.org/Usage/draw/#svg
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply