Multicolor single SVG file

Talk about Pixelmator Pro, share tips & tricks, tutorials, and other resources.
User avatar

2022-09-11 15:31:05

I would like to ask to the Pixelmator team and Community if it's possible to make a single SVG file having multiple colored shapes in it. At the moment, from my experience with Pixelmator Pro, I am able to create, in a new project for example, several (shape type) layers where every layer has the shapes in it of a particular, defined by shape tools, color. At that point if I want to export everything as a single file I tried two ways:

1. 'Merge' the layers. But this doesn't work because the file exported, even if it has the svg file extension it's a raster file and not a svg file so it's not accepted by the destination platform I'm trying to use. Infact if you open the file with TextEdit you have no information about paths.

2: 'Unite' the shapes. In this case all the shapes become 'united' but all the colors become one color destroying all the previously defined colors. In this case by the way if I open the exported file with a TextEdit program I can see this is a real SVG file because I see all the coordinated of nodes and the result is that this file is accepted by the target platform.

So the question is: Is there a way to export a single file with all (the shapes) colors which is a real SVG file and not a RASTER file which is not useful ?

Thanks for any suggestion or support.
User avatar

2022-09-11 18:36:49

According to the SVG specs a single vector object just can have 1 style in terms of stroke+fill. So you won´t "Merge" or "Combine" any of your drawn shapes - just export to SVG and you´re good to go.
User avatar

2022-09-12 06:50:00

I partially agree that this is a SVG spec limitation. To check that, in case you have time to do it, open a single SVG file layer with a single red shapein it (any position) with textedit and copy the path part into another SVG file with a single green shape in it and when you save it you can see (regardless of the position of the shapes that are positioned all to the top left) the two shapes green and red in the same svg file. So technically it's possible to have a single file with several paths and colors in it. The problem is that if you have a logo with 5 colors then you have to export all the layers as separate files and then you have to manually recreate the logo combining the positions of the 5 layers which is not practical. But probably/hopefully I'm doing something wrong. I cannot believe this is the way.
User avatar

2022-09-12 09:15:57

I have the impression that you are doing something crucially wrong. I just created this stupid little logo and exported it as SVG via cmd+E. As you can see, all shapes and colours are intact except for the gradient which is due to a bug - which has already been reported (checked in Inkscape):
Image
(I´m making SVGs since DTP was invented in the 80ties - so you can call me a vector veteran.)
User avatar

2022-09-12 21:29:02

Thanks for you answer but I need explanation from someone who knows the technical details here between a pure SVG file (one with paths clearly readable when you open it with textedit) and fake SVG file (which is the one you are obtaining by exporting with cmd-E). To see what I mean try saving a SVG file (simple shape one color) then open it with textedit. Then open your SVG file (the one in your example) with textedit and see the difference:

in the first type you have something like this which is a pure vector file:

Image

In the second type (the one in your example) you have a PNG embedded in a SVG file which is technically different and it's probably the reason that not all the target platforms accept this kind of file:

Image

The reason why Pixelmator decided to implement this way is something I'd like to ask them.

Thanks in any case.
User avatar

2022-09-13 08:54:02

Look; SVG is just a container file format like PDF - you can put in any vector data along any raster graphics file formats embedded or linked, formatted text and animation data dynamic or interactive. So my guess is you have applied an effect somewhere in your drawing that needs to be rasterised upon export to SVG to make it compatible with browsers CSS styling purposes for instance.
Here´s a quote from my silly SVG logo file above:
Image
All vector data no rasterisation.
At least "them" need an example file to check.
User avatar

2022-09-13 09:29:30

Yep, EllenM is indeed a true vector veteran and has hit the nail on the head! If any layers have effects/styles that cannot be represented in vector terms in SVGs, they get rasterized to bitmap. It might be nice to warn users during export that your SVG file has raster data, but this isn't entirely straightforward to implement (certainly doable, though). Plus, SVG files fully support raster data, so calling such a file a fake SVG is not really fair. But I do agree that most users would expect your run-of-the-mill SVG to be vector only.
User avatar

2022-09-13 16:54:51

Andrius and EllenM, thanks for your interesting replies. Actually 'fake' is a bit unfair because it's not your fault and it's a feature of the official SVG specs...but I hope you know what I meant. In any case I tried again with a simple example (3 layers with different standard shapes (fill red circle, blue rectangle, yellow in another shape) then cmd-e and then I opened the svg file with textedit and... surprise, the real vector stuff now is there, No embedded PNG as before. So now I have to check what happened with my project because I did the same cmd-e but the result were always generated with an embedded PNG. Hopefully in future a warning would help. :wink: Thanks for your prompt support.

Andrea