SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
philpem
Posts: 6
Joined: 2015-08-05T13:00:16-07:00
Authentication code: 1151

SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by philpem »

Hi,
I use Imagemagick as part of a shell script to resize and watermark photos for uploading to the Internet. This involves resizing them down to a maximum size of 1280 pixels in either direction (maintaining the aspect ratio), and stamping them with a watermark.

I've previously used the version of ImageMagick which comes with Ubuntu 14.10:

Code: Select all

Version: ImageMagick 6.7.7-10 2014-08-21 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP  
However after upgrading to Ubuntu 15.04, the version of Imagemagick has changed to this:

Code: Select all

Version: ImageMagick 6.8.9-9 Q16 x86_64 2015-01-06 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
And this is the result -- Imagemagick 6.7.7 on the top (the correct output), and Imagemagick 6.8.9 on the bottom.
Image

What is causing the white boxes around the SVG output? Is this an Imagemagick bug, or a problem in the way I'm using it?

Here is the command line my shell script uses:

Code: Select all

convert -filter Lanczos \
InputFile.jpg \
-set option:filter:filter Lanczos \
-set option:filter:blur 0.8 \
-resize 1280x1280 \
-quality 97 \
-gravity southeast \( -background none "watermark.svg" -geometry 426x \) -composite \
OutputFile.jpg
Thanks,
Phil.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by fmw42 »

Perhaps you need an upgrade to a more current version of IM. Your 6.8.9-9 might be buggy? Try the latest 6.9.1.9.

If that fails, please post a listing of your svg file.

Also generally (for proper IM 6 syntax), your input image should come right after convert. Also your -geometry should come after the \) and your -gravity should come just before your -geometry. But IM 6 is forgiving and these changes probably do not matter.
philpem
Posts: 6
Joined: 2015-08-05T13:00:16-07:00
Authentication code: 1151

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by philpem »

I don't have 6.9.1.9 to hand, and I'm not aware of an Ubuntu PPA of it. Is it difficult to build from source, in (say) /opt/imagemagick?

I've altered the syntax of my command and it made no difference. I did have to move the "geometry" command back inside the brackets, though -- it's meant to affect the dimensions of the SVG file, not the final image.

Thanks,
Phil.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by snibgo »

Also, the two installations may use different delegates for the SVG. Try with "-verbose" on each to see what delegate is used.
snibgo's IM pages: im.snibgo.com
philpem
Posts: 6
Joined: 2015-08-05T13:00:16-07:00
Authentication code: 1151

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by philpem »

The earlier version doesn't seem to use a delegate for SVG, but the later version is converting it to EPS with Inkscape, then using Ghostscript to convert it to PNG! What a roundabout way of doing things...!

Older version:

Code: Select all

IMG_0930.jpg JPEG 1920x1920 1920x1920+0+0 8-bit DirectClass 2.25MB 0.070u 0:00.080
/home/philpem/bin/watermark.svg SVG 718x172 718x172+0+0 16-bit DirectClass 176KB 0.020u 0:00.030
IMG_0930.jpg=>./watermarked_1280/IMG_0930.jpg JPEG 1920x1920=>1280x1280 1280x1280+0+0 8-bit DirectClass 1.122MB 0.580u 0:00.250
Newer version:

Code: Select all

IMG_0930.jpg JPEG 1920x1920 1920x1920+0+0 8-bit sRGB 2.25MB 0.090u 0:00.080
"inkscape" "/home/philpem/bin/watermark.svg" --export-eps="/tmp/magick-27886tw4xBDevgmPr" --export-dpi="90,90" --export-background="rgb(0%,0%,0%)" --export-background-opacity="0" > "/tmp/magick-27886NlrM884rALUJ" 2>&1
"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g551x115  "-sOutputFile=/tmp/magick-27886uBLA_DeCmlsF%d" "-f/tmp/magick-2788646TdvZspFngm" "-f/tmp/magick-2788630ZedULopr42"
/tmp/magick-27886uBLA_DeCmlsF1 PNG 551x115 551x115+0+0 8-bit sRGB 23.8KB 0.010u 0:00.000
/tmp/magick-27886tw4xBDevgmPr PNG 551x115 551x115+0+0 16-bit sRGB 23.8KB 0.000u 0:00.000
/home/philpem/bin/watermark.svg=>/tmp/magick-27886tw4xBDevgmPr PNG 551x115 551x115+0+0 16-bit sRGB 23.8KB 0.000u 0:00.000
IMG_0930.jpg=>./watermarked_1280/IMG_0930.jpg JPEG 1920x1920=>1280x1280 1280x1280+0+0 8-bit sRGB 1.123MB 0.340u 0:00.640
EDIT: The older version seems to have an "rsvg" delegate built in, which the newer version does not have. Could this be the problem?

Code: Select all

DELEGATES     bzlib djvu fftw fontconfig freetype jbig jpeg jng jp2 lcms2 lqr lzma openexr pango png rsvg tiff x11 xml wmf zlib

Code: Select all

DELEGATES      bzlib djvu mpeg fftw fontconfig freetype jbig jng jpeg lcms lqr lzma openexr pango png ps tiff wmf x xml zlib
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by snibgo »

In some versions, IM converted via EPS. I don't know why. Currently, it tells InkScape to convert to PNG.

Is your Inkscape old? I'm on 0.91. If yours is older, try an upgrade.

What is in your SVG?
snibgo's IM pages: im.snibgo.com
philpem
Posts: 6
Joined: 2015-08-05T13:00:16-07:00
Authentication code: 1151

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by philpem »

The SVG file contains two text areas and two paths. One of each is set to fill black with alpha 70%, the other is filled white with the same alpha. The idea is that on a light image, the white will be visible and on a dark image, the black will be visible. It gives a drop-shadow effect on more normal images.

I found a StackExchange thread which pointed me towards a workaround: http://stackoverflow.com/questions/1159 ... vg-enabled

The newer version of IM appears to have two SVG renderers:

Code: Select all

$ convert -list format |grep SVG
     MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
      SVG  SVG       rw+   Scalable Vector Graphics (XML 2.9.2)
     SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (XML 2.9.2)
Its SVG delegate is apparently rsvg-convert:

Code: Select all

$ convert -list delegate |grep ' svg'
        svg =>          "rsvg-convert" -o "%o" "%i"
So lord only knows why it's trying to use EPS as an intermediary.

Prefixing the name of the watermark image with "MSVG:" was enough to get rid of the blockiness.

My Inkscape is 0.91 r13725 (Feb 19 2015).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by snibgo »

Okay, so you've solved the problem with "MSVG:". Good. However, MSVG is normally worse at SVG compliance than Inkscape. So I suspect the SVG file is also bad, and may have been made "bad" to suit MSVG's bugs. Can you paste it here? Open it with a text editor, and copy-paste the contents here, between [ code ] and [ /code ].
snibgo's IM pages: im.snibgo.com
philpem
Posts: 6
Joined: 2015-08-05T13:00:16-07:00
Authentication code: 1151

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by philpem »

Well, it turns out the text objects are enough to break it -- the path isn't required. So here you go, a minimal test case.

The SVG was generated with Inkscape 0.91.

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 15.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   version="1.1"
   id="Group_1_1_"
   x="0px"
   y="0px"
   width="717.75006"
   height="172.09534"
   viewBox="0 0 717.75006 172.09534"
   enable-background="new 0 0 359.694 118.701"
   xml:space="preserve"
   inkscape:version="0.91 r13725"
   sodipodi:docname="watermark.svg"><metadata
     id="metadata33"><rdf:RDF><cc:Work
         rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
     id="defs31" /><sodipodi:namedview
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1"
     objecttolerance="10"
     gridtolerance="10"
     guidetolerance="10"
     inkscape:pageopacity="0"
     inkscape:pageshadow="2"
     inkscape:window-width="1920"
     inkscape:window-height="1056"
     id="namedview29"
     showgrid="false"
     fit-margin-top="15"
     fit-margin-left="15"
     fit-margin-right="15"
     fit-margin-bottom="15"
     inkscape:zoom="1.757049"
     inkscape:cx="293.87727"
     inkscape:cy="84.854553"
     inkscape:window-x="1920"
     inkscape:window-y="0"
     inkscape:window-maximized="1"
     inkscape:current-layer="Group_1_1_" /><text
     xml:space="preserve"
     style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:0.75294118;stroke:none;font-family:Sans"
     x="562.84766"
     y="71.761543"
     id="text3010-6"
     sodipodi:linespacing="125%"><tspan
       sodipodi:role="line"
       id="tspan3012-8"
       x="562.84766"
       y="71.761543"
       style="text-align:end;text-anchor:end;fill:#000000;fill-opacity:0.75294118;font-family:constantia;-inkscape-font-specification:constantia">© 2015 Phil Pemberton</tspan><tspan
       sodipodi:role="line"
       x="572.92578"
       y="121.76154"
       style="text-align:end;text-anchor:end;fill:#000000;fill-opacity:0.75294118;font-family:constantia;-inkscape-font-specification:constantia"
       id="tspan3971">www.weasyl.com/~suburbanfox </tspan></text>
<text
     xml:space="preserve"
     style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:0.75294118;stroke:none;font-family:Sans"
     x="561.34766"
     y="70.177544"
     id="text3010-6-5"
     sodipodi:linespacing="125%"><tspan
       sodipodi:role="line"
       x="561.34766"
       y="70.177544"
       style="text-align:end;text-anchor:end;fill:#ffffff;fill-opacity:0.75294118;font-family:constantia;-inkscape-font-specification:constantia"
       id="tspan3969">© 2015 Phil Pemberton</tspan><tspan
       sodipodi:role="line"
       x="571.42578"
       y="120.17754"
       style="text-align:end;text-anchor:end;fill:#ffffff;fill-opacity:0.75294118;font-family:constantia;-inkscape-font-specification:constantia"
       id="tspan3975">www.weasyl.com/~suburbanfox </tspan></text>
</svg>
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by snibgo »

I saved it as blocky.svg, encoded as UTF-8. Inkscape and my own RdXml software report no problems.

Code: Select all

f:\web\im>%IM%convert -verbose -background None blocky.svg blocky.png

"inkscape.exe" -z "C:/Users/Alan/AppData/Local/Temp/magick-7164acKuOMxlyMxP" --export-png="C:/Users/Alan/AppData/Local/Temp/magick-7164OGsY2HzRBigZ" --export-dpi="90,90" --export-background="rgb(0%,0%,0%)" --export-background-opacity="0" >"C:/Users/Alan/AppData/Local/Temp/magick-7164e6HF1VY28POf" 2>&1
blocky.svg SVG 718x172 718x172+0+0 16-bit sRGB 3.55KB 0.031u 0:00.812
blocky.svg=>blocky.png SVG 718x172 718x172+0+0 16-bit sRGB 132c 22.4KB 0.031u 0:00.016
Image
Looks fine to me.

IM v6.9.1--6, Inkscape 0.91 r13725, Windows 8.1.
snibgo's IM pages: im.snibgo.com
philpem
Posts: 6
Joined: 2015-08-05T13:00:16-07:00
Authentication code: 1151

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by philpem »

I get this -- once again a Ghostscript invocation:

Code: Select all

$ convert -verbose -background None watermark.svg blocky.png
"inkscape" "watermark.svg" --export-eps="/tmp/magick-3177CVIafbKtHiqA" --export-dpi="90,90" --export-background="rgb(0%,0%,0%)" --export-background-opacity="0" > "/tmp/magick-3177no4vMtc9poPw" 2>&1
"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g439x74  "-sOutputFile=/tmp/magick-3177pkvyzbVkiVJo%d" "-f/tmp/magick-3177qT-FVBvuMMqr" "-f/tmp/magick-3177iRhgQ_MB7E7t"
/tmp/magick-3177pkvyzbVkiVJo1 PNG 439x74 439x74+0+0 8-bit sRGB 12KB 0.000u 0:00.000
/tmp/magick-3177CVIafbKtHiqA PNG 439x74 439x74+0+0 16-bit sRGB 12KB 0.000u 0:00.000
watermark.svg=>/tmp/magick-3177CVIafbKtHiqA PNG 439x74 439x74+0+0 16-bit sRGB 12KB 0.000u 0:00.000
watermark.svg=>blocky.png PNG 439x74 439x74+0+0 8-bit sRGB 188c 7.23KB 0.010u 0:00.009
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: SVG has white blocky background on IM 6.8.9-9, but OK on 6.7.7-10

Post by snibgo »

Sorry, I don't know. Does your Inkscape correctly process the SVG? If you grab a copy of the EPS file, it might help isolate the problem. Perhaps you can tweak the delegates.xml file to go directly to PNG.

If Inkscape works but IM calling Inkscape doesn't, you could call Inkscape to make a PNG, and use that PNG in your IM command.
snibgo's IM pages: im.snibgo.com
Post Reply