/gimp_svg_mask

Decompose RGBA image to SVG files with color image and mask image. It can be used to get a image with jpeg compression and transparency.

Primary LanguagePythonMIT LicenseMIT

Gimp Plugin for SVG Masks

With this Plugin, you can export a given RGBA image to an svg with a RGB image plus a mask image.

Example Valid SVG 1.1

As you may know, the jpeg file format cannot save an alpha-channel, which is often used for transparency, of any image. Another popular format, png, is able to save the alpha channel, but it is a lossless compression and the same image can occupy much more space.

A lot of image process program, i.e. modern Browsers (prior IE8), also support svg files. With this file format, it is possible to decompose an image to two images, one defining the color and one defining the alpha channel. This allows you to use a higher compressions from i.e. jpeg but also having transparency in your image.

This Gimp Plugin helps you, creating such a svg file from an image with alpha channel.

The top image is such a svg file (see Image Source for more details).

How to Install/Use

Place the python script file under plug-ins in the GIMP plugin folder. The directory is usually located somewhere:

  • Windows: %AppData%\Roaming\GIMP\<Version>\plug-ins
  • Linux (GIMP 2.10): ~/.config/GIMP/2.10/plug-ins

You can find a new option now under the menu: Image->Export with alpha mask...

The png/jpeg files are saved using your in GIMP configured defaults for saving these formats.

Modes

There are three modes, one mode, which creates an output color image, the mask containing the alpha channel and the svg file which stiches everything together.

The second mode, embed, saves everything in the svg file. The third mode is like embed, it just compresses the file.

  • The first mode, not embed, requires ~30% less space than the second mode, but you have to keep all the files. The produces svg just links to the images.

  • The second mode, embed, requires more space, but everything is encoded in the svg file.

  • The third mode compresses the embed file with gzip, as browser usually support the svgz format. See wikipedia.

Space Consumption Comparison

Some results from the website clipartpng.com (first found using a search engine):

format Cat White Bear Baby Fox Brown Bear Earth Trash Bin
png 11.172kb 4.151kb 4.030kb 824kb 3.602kb 2.152kb
svg+jpeg+png 2.001kb (~18%) 573kb (~14%) 833kb (~21%) 251kb (~30%) 1.342kb (~37%) 1.428kb (~66%)
embed svg 2.813kb (~25%) 762kb (~18%) 1.109kb (~28%) 332kb (~40%) 1.787kb (~50%) 1.903kb (~88%)
svgz 1.961kb (~18%) 524kb (~13%) 820kb (~20%) 235kb (~29%) 926kb (~26%) 864kb (~40%)

The svgz file format is a compressed embed svg file (using gzip method) and is usually supported by all browsers.

All images where exported as jpeg for the color image and png for the mask image (jpeg can also be used as a mask image). All jepg/gzip compressions were done with GIMP 2.10 default setting (quality 90/0.9) and 7-zip gzip method default settings.

License

MIT-License