Page 1 of 1

identify -- XML dummy -- magic says SVG

Posted: 2010-06-10T12:13:42-07:00
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>?

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

Posted: 2010-06-10T12:28:03-07:00
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.

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

Posted: 2010-06-10T13:15:27-07:00
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?

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

Posted: 2010-06-10T13:29:49-07:00
by snibgo
For each input file, you might say:

convert infile NULL:

and check for non-zero returns.

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

Posted: 2010-06-10T14:03:48-07:00
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)

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

Posted: 2010-06-10T14:56:28-07:00
by snibgo
Have you got the rsvg delegate?

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

Posted: 2010-06-10T15:57:29-07:00
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

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

Posted: 2010-06-10T18:41:50-07:00
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

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

Posted: 2010-06-11T14:16:41-07:00
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.

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

Posted: 2010-06-14T23:58:41-07:00
by anthony

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

Posted: 2010-06-15T07:33:38-07:00
by snibgo
The requested URL /Usage/raw was not found on this server.

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

Posted: 2010-06-15T11:34:09-07:00
by fmw42
The requested URL /Usage/raw was not found on this server.
You mistyped. It is draw not raw.

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

Posted: 2010-06-15T11:47:09-07:00
by snibgo
I clicked on the link, which someone has now kindly corrected.

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

Posted: 2010-06-15T17:41:56-07:00
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.