identify -- XML dummy -- magic says SVG

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
Wolfgang Woehl
Posts: 34
Joined: 2010-02-25T15:22:50-07:00
Authentication code: 8675308

identify -- XML dummy -- magic says SVG

Post by Wolfgang Woehl »

$ cat xml
<?xml version="1.0" encoding="UTF-8"?>
<test/>
$ identify -format "%m" xml
SVG

and that is just wrong, isn't it? Wouldn't you want to at least check for <svg>?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: identify -- XML dummy -- magic says SVG

Post by magick »

ImageMagick uses a light weight fast process for identifying an image generally by comparing the first few bytes of the image header. The image is then passed to the appropriate coder for further analysis. It is possible the identification process can get a false positive and that is considered ok since the image coder will subsequently return an exception if its not. However, if you ping an image, the deep analysis is not performed so a false-positive is possible and we find that acceptable.
Wolfgang Woehl
Posts: 34
Joined: 2010-02-25T15:22:50-07:00
Authentication code: 8675308

Re: identify -- XML dummy -- magic says SVG

Post by Wolfgang Woehl »

Makes sense. Thanks.

With a slideshow DCP glue tool I'm writing (http://wiki.github.com/wolfgangw/digita ... nemaslides) I want to be able to say

Code: Select all

$ cinemaslides *
in dirs that have decodable files and non-decodable files, skipping the latter.

So, apart from the SVG/XML dummy example is there a list of likely false positives that I'd want to catch?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: identify -- XML dummy -- magic says SVG

Post by snibgo »

For each input file, you might say:

convert infile NULL:

and check for non-zero returns.
snibgo's IM pages: im.snibgo.com
Wolfgang Woehl
Posts: 34
Joined: 2010-02-25T15:22:50-07:00
Authentication code: 8675308

Re: identify -- XML dummy -- magic says SVG

Post by Wolfgang Woehl »

Neat, but not quite, I think:

Code: Select all

$ cat resistor.svg | grep -v '<!--'
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 xmlns:ev="http://www.w3.org/2001/xml-events"
 version="1.1" baseProfile="full"
 width="700px" height="400px" viewBox="0 0 700 400">
 <line x1="0" y1="200" x2="700" y2="200" stroke="black" stroke-width="20px" />
 <rect x="100" y="100" width="500" height="200" fill="white" stroke="black" stroke-width="20px" />
 <line x1="180" y1="370" x2="500" y2="50" stroke="black" stroke-width="15px" />
  <polygon points="585 0 525 25 585 50" transform="rotate(135 525 25)" />
</svg>
$ convert resistor.svg NULL:
convert: Non-conforming drawing primitive definition `�' @ draw.c/DrawImage/3140.
display likes the file (doesn't draw the polygon, though). So the file could be used but I'd skip it on the non-zero answer to a blank convert.
(Ubuntu's default IM 6.5.7-8 2009-11-26 Q16)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: identify -- XML dummy -- magic says SVG

Post by snibgo »

Have you got the rsvg delegate?
snibgo's IM pages: im.snibgo.com
Wolfgang Woehl
Posts: 34
Joined: 2010-02-25T15:22:50-07:00
Authentication code: 8675308

Re: identify -- XML dummy -- magic says SVG

Post by Wolfgang Woehl »

Ubuntu's IM (6.5.7-8 2009-11-26 Q16) doesn't:

Code: Select all

$ convert -list configure | grep DELEGATES
DELEGATES bzlib djvu freetype gvc jpeg jng jp2 lcms openexr png tiff x11 xml wmf zlib
Thanks for the hints
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: identify -- XML dummy -- magic says SVG

Post by fmw42 »

rsvg is not in your list of delegate. so you need to install that and then reinstall IM. then check the delegates again. otherwise you are using IM's internal msvg, I believe, which may not be as good or full functioned as rsvg
Wolfgang Woehl
Posts: 34
Joined: 2010-02-25T15:22:50-07:00
Authentication code: 8675308

Re: identify -- XML dummy -- magic says SVG

Post by Wolfgang Woehl »

Fred, I will test rsvg output. I can't steer off the target platform too far, though. cinemaslides already is an exotic little bugger. But I think now I have some sort of a handle on this.

Thanks for your advice and suggestions.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: identify -- XML dummy -- magic says SVG

Post by anthony »

Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: identify -- XML dummy -- magic says SVG

Post by snibgo »

The requested URL /Usage/raw was not found on this server.
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: identify -- XML dummy -- magic says SVG

Post by fmw42 »

The requested URL /Usage/raw was not found on this server.
You mistyped. It is draw not raw.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: identify -- XML dummy -- magic says SVG

Post by snibgo »

I clicked on the link, which someone has now kindly corrected.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: identify -- XML dummy -- magic says SVG

Post by anthony »

Wasn't me and only a few people can correct other peoples emails on the list (I'm one).
It may be that I made a cut and paste error, in which case.. applogies.

getting back to the original problem.

IM SVG handler only uses basic file 'magic' (see the man page on the 'file' command) for determining what type of image file it has, regardless of the suffix of the filename. It may be that this 'magic' for SVG is not quite good enough to separate ordinary XML form XML containing SVG.

XML has become a very common file format for storing configuration data and programs, and IM does make extensive use of it for its own configuarion. It probably should differentiate the XML more than it does.

However as Cristy (aka magick) said, it does not do a deeper test in a quick 'ping' check.

Hmmm the "file" command actually looks for the string "<svg" somewhere between 23 and 400 characters into the file (just the first read block) as well as the normal "<?xml" start tag. Tis was decoded form the "/usr/share/misc/magic" file on my linux system with the help of the "magic" manpage.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply