Conversion of SVG image to PNG will text adds backslashes before quotation marks

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
hairykid
Posts: 17
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by hairykid »

Hi,

My website deals with print and the user can design their print before previewing their design - at which point the svg image which is generated with JS in real time is converted using imagemagick into a png.

The issue is that if you add the text for example - Hi my name's Gary.

It will convert to png as - Hi my name\'s Gary.

I can't find anything online mentioning this, only people talking about text conversion through command line.

Hoping someone can help me with this please.

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

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by snibgo »

We need a reproducible example. Please post a sample SVG.

Please also say what version of IM you use, on what platform. Also: what delegate does your IM use to rasterize the SVG? This might be MSVG, RSVG or Inkscape.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by fmw42 »

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
hairykid
Posts: 17
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by hairykid »

Hi thanks for both of your quick replies and sorry for not reading the post first I didn't see this, but I accept I should have checked first.

Running the command "convert -version" outputs -

Version: ImageMagick 6.9.10-8 Q16 x86_64 20180723

I am using Ubuntu 18.10

The command being run is -

convert +antialias msvg:/var/www/mydomain.co.uk/sites/default/files/tmp/preview-950397970-7EUq2J png:/var/www/mydomain.co.uk/sites/default/files/tmp/preview-573026719-dP1ZEa

The svg image is here - https://ufile.io/b8cgr

The converted png is here - https://ufile.io/6sayx

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

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by snibgo »

I don't know why IM using MSVG inserts a backslash before the quote. I suppose that is a bug.

As a workaround, remove the "MSVG:" prefix. Then IM will use RSVG (provided IM has been built with RSVG). The result seems good to me.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by fmw42 »

Or install Inkscape which is generally better than RSVG and does not need to have ImageMagick recompiled with RSVG. ImageMagick will use inkscape by default if it finds it on your system.
hairykid
Posts: 17
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by hairykid »

Thanks for your replies, appreciated.

I've tried installing inkscape, can I still use the same command? -

convert +antialias msvg:/var/www/mydomain.co.uk/sites/default/files/tmp/preview-950397970-7EUq2J png:/var/www/mydomain.co.uk/sites/default/files/tmp/preview-573026719-dP1ZEa

As this is not working, not sure if it is using Inkscape, is there anyway to tell?

I have tried without MSVG: -

convert +antialias /var/www/mydomain.co.uk/sites/default/files/tmp/preview-950397970-7EUq2J png:/var/www/mydomain.co.uk/sites/default/files/tmp/preview-573026719-dP1ZEa

This works, however it is now cutting off the right edge of my images. Hmmm, any ideas?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by snibgo »

If you have a MSVG: prefix, this forces IM to use MSVG, so it won't use Inkscape.

If you have no prefix, it will use Inkscape if it can, otherwise RSVG if it can, otherwise MSVG.

In general, Inkscape is the most powerful (it implements more SVG, and does so correctly) but is also slowest.
hairykid wrote:This works, however it is now cutting off the right edge of my images. Hmmm, any ideas?
That problem goes away if we remove all those (superfluous?) white rectangles from the SVG.
snibgo's IM pages: im.snibgo.com
hairykid
Posts: 17
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by hairykid »

Thanks, I am going to test this again soon and will report back.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
hairykid
Posts: 17
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by hairykid »

Awesome news! Great that I was of some help to find this bug.
hairykid
Posts: 17
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by hairykid »

Out of interest, is it possible to install the beta version through command line in Linux Ubuntu?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by magick »

The patch is in the current releases of ImageMagick, 7.0.8-34 and 6.9.10-35. No Beta required.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by fmw42 »

Did you not mean 6.9.10-34 and not 6.9.10.35? I see no 6.9.10.35 in the install from source list.
hairykid
Posts: 17
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Conversion of SVG image to PNG will text adds backslashes before quotation marks

Post by hairykid »

When running sudo apt upgrade imagemagick I get the following -

imagemagick is already the newest version (8:6.9.10.8+dfsg-1ubuntu2)
Post Reply