Convert SVG with clippath to PNG

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
anaiappan
Posts: 5
Joined: 2013-07-24T22:05:50-07:00
Authentication code: 6789

Convert SVG with clippath to PNG

Post by anaiappan »

Hi,

I am using imagemagick 6.8 to convert a svg with clip path to PNG. i have tried the following command

/usr/local/bin/convert page_1_g_0.svg -clip /tmp/page_1.png .

But it throws an error like this:
convert: no clip path defined `page_1_g_0.svg': No such file or directory @ error/image.c/ClipImagePath/719.

But my SVG has clip-paths

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

Re: Convert SVG with clippath to PNG

Post by fmw42 »

I believe you have to convert the clip-path to a clip-mask and then use that. But I am not sure it works except for tiff files. I am not an expert on this.

see
http://www.imagemagick.org/Usage/masking/#clip_mask

Best to provide your svg file so others can test with it.
anaiappan
Posts: 5
Joined: 2013-07-24T22:05:50-07:00
Authentication code: 6789

Re: Convert SVG with clippath to PNG

Post by anaiappan »

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

Re: Convert SVG with clippath to PNG

Post by fmw42 »

I do not know enough about clip-paths to really help. But I get error messages when just trying to convert to png. I am using IM's internal MSVG. Perhaps using the delegate RSVG might work better. But I do not have it installed.

convert page_1_g_0.svg 1tmp1.png
convert: unable to open image `img-1_0.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_0.png' @ error/png.c/ReadPNGImage/3994.
convert: unable to open image `img-1_1.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_1.png' @ error/png.c/ReadPNGImage/3994.
convert: unable to open image `img-1_2.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_2.png' @ error/png.c/ReadPNGImage/3994.



convert page_1_g_0.svg -clip 1tmp1.png
convert: unable to open image `img-1_0.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_0.png' @ error/png.c/ReadPNGImage/3994.
convert: unable to open image `img-1_1.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_1.png' @ error/png.c/ReadPNGImage/3994.
convert: unable to open image `img-1_2.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_2.png' @ error/png.c/ReadPNGImage/3994.
convert: no clip path defined `page_1_g_0.svg': No such file or directory @ error/image.c/ClipImagePath/719.
convert: unable to open image `img-1_0.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_0.png' @ error/png.c/ReadPNGImage/3994.
convert: unable to open image `img-1_1.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_1.png' @ error/png.c/ReadPNGImage/3994.
convert: unable to open image `img-1_2.png': No such file or directory @ error/blob.c/OpenBlob/2643.
convert: unable to open file `img-1_2.png' @ error/png.c/ReadPNGImage/3994.
convert: no clip path defined `page_1_g_0.svg': No such file or directory @ error/image.c/ClipImagePath/719.
anaiappan
Posts: 5
Joined: 2013-07-24T22:05:50-07:00
Authentication code: 6789

Re: Convert SVG with clippath to PNG

Post by anaiappan »

please use this link:
http://www.fileconvoy.com/dfl.php?id=g0 ... 5a5c8d100c
to download the other images that are mentioned in the SVG
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG with clippath to PNG

Post by fmw42 »

anaiappan wrote:please use this link:
http://www.fileconvoy.com/dfl.php?id=g0 ... 5a5c8d100c
to download the other images that are mentioned in the SVG
These are all PNG files. What do they have to do with the SVG problem and clip paths?

The issue is whether IM can extract and use a clip path from anything other than TIFF, in particular, from an SVG.

I do not know that answer. One of the IM developers would need to answer that. That was why I had you post the SVG file, so they can check that out. Perhaps it is malformed or IM cannot extract the clip path from it.
anaiappan
Posts: 5
Joined: 2013-07-24T22:05:50-07:00
Authentication code: 6789

Re: Convert SVG with clippath to PNG

Post by anaiappan »

My svg has image elements(https://developer.mozilla.org/en-US/doc ... _Image_Tag) also. Thats why it's failed for you with missing image error..
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG with clippath to PNG

Post by fmw42 »

Are you using RSVG or the IM MSVG?

Type

convert -list format

and see what you have listed for SVG. Does is say RSVG?

I am not using it so mine says


SVG SVG rw+ Scalable Vector Graphics (XML 2.8.0)


It would also be listed as a delegate when you do

convert -version
Version: ImageMagick 6.8.6-7 2013-07-25 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib mpeg fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr lzma openexr png ps tiff x xml zlib

If you do not see RSVG, then get the delegate library and install it and recompile IM from source.

See if that works better. IM's MSVG is pretty basic, only. see http://www.imagemagick.org/Usage/draw/#svg_drivers
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert SVG with clippath to PNG

Post by snibgo »

"-clip" restricts subsequent raster processing to within the clip area. If there is no subsequent processing, "-clip" will have no effect. See http://www.imagemagick.org/script/comma ... s.php#clip

Next problem: clipping paths that are within an svg file should be processed by the SVG processing, and should already be taken account of when IM rasterises the image.

IM's "-clip" restricts processing to the clipping path in an 8bim profile. For example, abClip.tiff:

https://dl.dropboxusercontent.com/s/4az ... 4S8QQ&dl=1

The raster data in this file is solid green. But it contains a clipping path; use "identify -verbose abClip.tiff".

To use the clipping path, do some processing, eg:

Code: Select all

%IM%convert abclip.tiff -clip -channel R -evaluate set 100% a.png
The result should be a yellow letter "A" on a green background.
Post Reply