Embedded images in SVG are colour inverted when converted to PNG

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.
User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by fmw42 »

What format is preview-547830085-NHHgtJ ? There is no suffix on that file. Likewise on your output, there is no suffix, though your have prefaced it with png:. +antialias will not help except when adding text to an image using one of the text to image commands such as -annotate. IM 6.9.7-4 is ancient. What delegates do you have on both systems? Are they the same and the same versions? Please provide more details and your input image so we can test. If your input is an SVG file, then are you using the same SVG renderer (and versions) on both systems? (MSVG/XML, RSVG or Inkscape)

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

Ok, sorry for the multiple messages but i am still having issues. As I mentioned I can get things working locally but not on my server. Here are the specs

Both using simple command- convert -verbose +antialias tobeconverted png:/converted.png

Locally: (THIS WORKS)
Version: ImageMagick 7.0.9-10 Q16 x86_64
Verbose:
'inkscape' '/tmp/magick-27806C7C0XqekqHHK' --export-png='/tmp/magick-27806jalA3qw9qR4L' --export-dpi='96,96' --export-background='rgb(100%,100%,100%)' --export-background-opacity='1' > '/tmp/magick-27806ypOAw06K3qUI' 2>&1
/tmp/magick-27806jalA3qw9qR4L PNG 694x662 694x662+0+0 8-bit sRGB 228748B 0.020u 0:00.012
tobeconverted SVG 694x662 694x662+0+0 8-bit sRGB 228748B 0.000u 0:00.000
tobeconverted=>fd.png SVG 694x662 694x662+0+0 8-bit sRGB 228748B 0.110u 0:00.063

On server: (DOESN'T WORK -> IMAGE INVERTED)
Version: ImageMagick 7.0.9-14 Q16 x86_64
Verbose:
'inkscape' '/tmp/magick-1731j1G_knbBv4BE' --export-png='/tmp/magick-1731yw9ktWhP8CeN' --export-dpi='96,96' --export-background='rgb(100%,100%,100%)' --export-background-opacity='1' > '/tmp/magick-1731Rj0kLogggcRV' 2>&1
mvg:/tmp/magick-17310_xKPp2occu4=>/tmp/magick-17310_xKPp2occu4 MVG 694x662 694x662+0+0 16-bit sRGB 2426B 0.250u 0:00.156
tobeconverted MVG 694x662 694x662+0+0 16-bit sRGB 2426B 0.000u 0:00.000
tobeconverted=>converted.png MVG 694x662 694x662+0+0 16-bit sRGB 2426B 0.190u 0:00.185

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

"What format is preview-547830085-NHHgtJ" - This is SVG

"Likewise on your output, there is no suffix" - Yes this is always PNG, is this important because if possible I would rather not have to add this, I'm working with an application that I didn't build and I don't know why this has been omitted, it doesn't seem to cause issues from my testing, if I add the suffix on afterwards manually it opens.

"+antialias will not help except when adding text to an image -" - Sometimes our application will need to use text, so can we just leave that in there without having to check each time an image is converted to check whether or not it contains text, will it cause problems when converting SVG's with no text?

"What delegates do you have on both systems" - Does the above help with this? I see the non-working output has 'mvg:/' - I'm guessing this is significant?

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by fmw42 »

Are the two versions of Inkscape the same?

Have you tried using magick rather than convert for IM 7? Also try removing +antialias, it does nothing in your command. If that fails, then the IM developers will need to respond.

I see in the first one the verbose output says SVG. But in the second one, it says MVG.

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

It was the inkscape version! Thanks for that it is working now :)))

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by fmw42 »

Great!

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

However, as is life, I have now found another issue, the image linked in the SVG now won't accept a URL, it will only work with a relative or absolute path

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

Seems to be related to inkscape, I found this documentation of the issue on github - https://github.com/ImageMagick/ImageMagick/issues/779

The only way I can think to resolve this is to move the svg and any linked images into the same folder, and then parse the SVG to replace each linked images URL with an absolute server path.

The reason my SVG's have linked images using URL's rather than paths is that in my application the user edits a design in the browser and can upload an image to embed into the design, which is essentially embedded into the SVG using xlink:href.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by fmw42 »

The SVG file you had before with this issue specifically calls the image from a local directory. Did you change the SVG file to link to a URL image? Please post the original SVG file and any linked images.

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

That's true, I edited the SVG in my text editor to make the embedded CMYK image exist in the same directory, so that I didn't need to leave a URL in there, I didn't want to share the ip or url I was using on this server if I'm honest. Will provide an image tomorrow, it's getting late now. Thanks again.

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

Here is an SVG image with an embedded CMYK jpg that uses a URL rather than a server path. I'm sure this will help with recreating the issue

https://easyupload.io/gsxygd

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by fmw42 »

It does not work for me either.

I suppose that Inkscape does not know how to handle URL images linked in the file. But I will leave this to the IM developers to comment further.

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

Thanks for confirming this isn't working. Feels like I'm playing wack a mole at the minute!

If there isn't a fix for this, I think my idea above will be my only solution i.e. converting the URL to a server path, I'm also not sure if both the svg and the linked image need to be in the same folder, so this might be another complication.

muy apreciado!

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by fmw42 »

You might try using Inkscape by itself. If that works, then there is likely an ImageMagick issue that can be fixed. Otherwise, ask on an Inkscape forum.

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: Embedded images in SVG are colour inverted when converted to PNG

Post by hairykid »

Tried posting on the inkscape forum but my thread was closed without any reason, don't think I broke any rules.

It doesn't look hopeful, so I will need to parse the SVG to convert the URL to a server path.

Thanks for any help, you can consider this issue closed unless the MSVG method can be fixed to prevent this colour inversion. Doesn't seem high priortiry through since it works with Inkscape, just not my edge case.

Locked