green star in blue circle in red square


Write metatags to EPS and JPG files
out of Inkscape SVG images



Files: svg2eps_jpg.py - the program (python script)
svg2eps_jpg.html - this file (You're just reading)
Summary: Converting Inkscape-SVG metadata and writing them to EPS and JPG files.
Author: Peter Burger
Revision: 2010-12-12 First edition
Copyright: ©Copyright 2010 by Peter Burger under LGPL

Disclaimer: Some people really need this (Maybe these people should better do a fair job!):
This is free software for Your personal purpose.
No warranty about this software and other software which is used with it. You should always work with copies of Your files not with the original ones. You may use this software on Your own risk only. If You destroy Your work, please don't ask me why.
You may modify or redistribute it under the terms of LGPL.
All links don't reflect my opinion, no matter if their content is true or not.

References: http://www.inkscape.org/
http://owl.phy.queensu.ca/~phil/exiftool/
http://www.imagemagick.org

Notes: Following software is needed for a proper execution:
  
  • python - should already be installed with Your distribution
  • perl - dito
  • inkscape - think You'll have it or install it if not present
  • exiftool - download from http://owl.phy.queensu.ca/~phil/exiftool/
  • imagemagick - download from http://www.imagemagick.org/

  • Imagemagick is good for graphics conversion, but poor for metadata handling.

    Excerpt from ImageMagick forum (2009-07-31):
    Imagemagick at this time has very minimal control of meta-data such
    as in EXIF profiles. It is basically not its job. Your best solution
    is the one you found, use a program more suited to that task. ExifTool
    or Jhead, etc...

    Following files are part of svg2eps_jpg.py (edit for Your own opinion!):
      
  • xmpcc2xmp.args - converts Inkscape SVG XPM-cc to XMP (used as stack file)
  • xmpcc2eps.args - converts Inkscape SVG XPM-cc to EPS (Postscript)
  • xmpcc2jpg.args - converts Inkscape SVG XPM-cc to JPG (IPTC, XMP[-dc,-iptcCore,-Photoshop])

  • sample.svg - an image with metadata to play with

  • Open a copy of this image with Inkscape and do the steps described below.

    Also added for a lookup:
      
  • sample.png - file bitmap export from inkscape
  • sample.eps.original - file save under EPS from inkscape
  • sample.jpg.original - converted png file with convert sample.png -quality 100 sample.jpg
  • sample.xml - metadata of sample.svg after program execution
  • sample.eps - with metadata after program execution
  • sample.jpg - with metadata after program execution

  • Description: Inkscape is a handy program to build vector images in SVG file format.

    If these images should be offered to the stock market, it is necessary to convert them into EPS file format and build a corresponding JPG file (mostly equal or greater than 3 megapixel).

    Authors who want to sale their images are entitled to place their copyright and other notices into their offered files. This is done via so called metadata. Unfortunately there is no general system of metadata among the different file formats.

    Inkscape uses the metadata in its own Inkscape-SVG format only. With File Save As EPS the image is converted correctly, but the metadata are lost totally. The same is with File Bitmap Export (which makes a PNG file only), but most of the metadata is blown.

    Luckily exists ExifTool by Phil Harvey (http://owl.phy.queensu.ca/~phil/exiftool/), the only tool I've found which is able to handle all the metadata stuff that have to be done. The one and only step where we need another program is the conversion from PNG to JPG. Here helps the convert program from the ImageMagick suite (http://www.imagemagick.org/).


    First (of course) You've to create our image with Inkscape (I've done this with sample.svg).

    It's a good job to save the image periodically as Inkscape SVG. At the end of our creation enter Your metadata in File Document Metadata and save the image again.

    Then select all items with Work Select All in all Layers. Now do the pixel job with File Bitmap Export. In the popup window click the Selection tab, else Your bitmap is as large as the complete page. Changing the dpi value of bitmap size lets You change the megapixel size of the output. Normally values of 150, 300 or 600 dpi are used. Changed pixel values are shown, if You click on any other entry field. Multiplying the x and y values results the pixel area size. The outfile is always a PNG file, no matter what file extension in the field file name is entered, but You should care of the right file name in this field or You've to search it later. svg2eps_jpg.py needs strictly the same name as the inkscape file with .png extension.

    The next step is to build the EPS file, we need. This is done by File Save As and selecting EPS as output file format. Be careful that Export area is the whole page is not ticked. So the EPS file contents our selected image only instead of the whole page with the blank area around it.

    You'll find now 3 more files in Your directory:

       file.svg, file.png and file.eps (maybe some backup files which doesn't matter).

    If You play with the sample.svg file You'll see

       sample.svg, sample.png and sample.eps.

    Now quit Inkscape. Inkscape asks You for saving the file as Inkscape SVG again. If You've saved the file already (hopefully) as described above, You may ignore this and quit without saving.

    The last necessary step is to update the 3 .args files. Check out for all tags which are set with equal characters ('=')! Enter Your name, copyright notice, city and so on or You will give Your rights to another person. Be sure to

       check out all 3 files!


    The following is for linux users, but in a similar manner this are the same steps for other operating system users too.

    We open a terminal window and change to our working directory (see cd command). You may use the dir or ls command to check if You're right. Our 3 files have to be present.

    Now we start the conversion:

       python svg2eps_jpg.py file     <-- note file name only without dot extension!

    With the sample file enter:

       python svg2eps_jpg.py sample

    If You think the program is too verbose, set the two variables (pout_printing and perr_printing) in svg2eps_jpg.py to Your choice (True -> False).

    If the program was successfully You'll see the new created files (.xml, .eps and .jpg in Your directory.

    Control if all metadata was written correctly with (file.xml isn't needed any longer)

       exiftool file.eps

    and

       exiftool file.jpg

    Now You're ready to upload Your files to Your image vendor -
    great success with selling Your image!

    PS: If You additional need a preview image in Your EPS file take a look at epstool by Russell Lang. This would be another blog, just as hint.




    Logouts: With the sample image I've checked the metadata usage of Inkscape:

    Extracted metadata from sample save as inkscape svg:

        <metadata id="metadata7">
      <rdf:RDF>
        <cc:Work rdf:about="">
          <dc:format>image/svg+xml</dc:format>
          <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
          <dc:title>Sample drawing</dc:title>
          <dc:date>2010-12-12 13:50:00</dc:date>
          <dc:creator>
            <cc:Agent>
              <dc:title>Author: Peter Burger</dc:title>
            </cc:Agent>
          </dc:creator>
          <dc:rights>
            <cc:Agent>
              <dc:title>© Copyright 2010 by Peter Burger</dc:title>
            </cc:Agent>
          </dc:rights>
          <dc:publisher>
            <cc:Agent>
              <dc:title>Publisher: Peter Burger</dc:title>
            </cc:Agent>
          </dc:publisher>
          <dc:identifier>Document URI</dc:identifier>
          <dc:source>Source URI</dc:source>
          <dc:relation>Reference URI</dc:relation>
          <dc:language>de-DE</dc:language>
          <dc:subject>
            <rdf:Bag>
              <rdf:li>square</rdf:li>
              <rdf:li>circle</rdf:li>
              <rdf:li>star</rdf:li>
              <rdf:li>red</rdf:li>
              <rdf:li>blue</rdf:li>
              <rdf:li>green</rdf:li>
            </rdf:Bag>
          </dc:subject>
          <dc:coverage>Document range</dc:coverage>
          <dc:description>A green star in a blue circle in a red square</dc:description>
          <dc:contributor>
            <cc:Agent>
              <dc:title>No contributors</dc:title>
            </cc:Agent>
          </dc:contributor>
        </cc:Work>
      </rdf:RDF>
    </metadata>

    Output of metadata with

       exiftool -G1 -a sample.svg:

       
    [ExifTool] ExifTool Version Number : 8.40
    ~[System] File Name : sample-inkscapesvg.svg
    [System] Directory : .
    ~[System] File Size : 4.2 kB
    ~[System] File Modification Date/Time : 2010:12:12 14:00:52+01:00
    [System] File Permissions : rw-r--r--
    [File] File Type : SVG
    [File] MIME Type : image/svg+xml
    +[SVG] Xmlns : http://www.w3.org/2000/svg
    +[SVG] Image Width : 210mm
    +[SVG] Image Height : 297mm
    +[SVG] ID : svg2
    [SVG] SVG Version : 1.1
    [SVG] Title Id : title2843
    [SVG] Title : Sample drawing
    [SVG] Metadata ID : metadata7
    *[SVG-inkscape] Version : 0.47pre4 r22446
    *[SVG-sodipodi] Docname : sample-inkscapesvg.svg
    [XMP-cc] Work Format : image/svg+xml
    [XMP-cc] Work Type : http://purl.org/dc/dcmitype/StillImage
    [XMP-cc] Work Title : Sample drawing
    [XMP-cc] Work Date : 2010:12:12 13:50:00
    [XMP-cc] Work Creator Agent Title : Author: Peter Burger
    [XMP-cc] Work Rights Agent Title : © Copyright 2010 by Peter Burger
    [XMP-cc] Work Publisher Agent Title : Publisher: Peter Burger
    [XMP-cc] Work Identifier : Document URI
    [XMP-cc] Work Source : Source URI
    [XMP-cc] Work Relation : Reference URI
    [XMP-cc] Work Language : de-DE
    [XMP-cc] Work Subject : square, circle, star, red, blue, green
    [XMP-cc] Work Coverage : Document range
    [XMP-cc] Work Description : A green star in a blue circle in a red square
    [XMP-cc] Work Contributor Agent Title : No contributors
    [Composite] Image Size : 210mmx297mm
       * not in optimized Inkscape SVG
       + same values in optimized Inkscape SVG but sequence differ
       ~ values normally differ (file name, file size and file date/time)
       Only the XMP-cc metadata are of interest and correspond to the entered ones in Inkscape.


    Extracted metadata from sample save as normal svg:

       
    No usable metadata are present!

    Output of metadata with

       exiftool -G1 -a sample.svg:

       
    No usable metadata are shown!



    Extracted metadata from sample save as optimized inkscape svg:

       
    Same metadata as sample inkscape svg (see above) but filesize about 50% less.
    Some spaces in metadata block are omitted.

    Output of metadata with

       exiftool -G1 -a sample.svg:

       
    See comments above at sample inkscape svg!



    Extracted metadata from sample save as eps:

        %!PS-Adobe-3.0 EPSF-3.0
    %%Creator: cairo 1.8.8 (http://cairographics.org)
    %%CreationDate: Sun Dec 12 14:02:02 2010
    %%Pages: 1
    %%BoundingBox: 0 0 210 210
    %%DocumentData: Clean7Bit
    %%LanguageLevel: 2
    %%EndComments
    %%BeginProlog
    :
    :
    some cairo statements with no interest for metadata
    :
    :
    %%EndProlog

    Output of metadata with

       exiftool -G1 -a sample.eps:

       
    [ExifTool] ExifTool Version Number : 8.40
    [System] File Name : sample-eps.eps
    [System] Directory : .
    [System] File Size : 49 kB
    [System] File Modification Date/Time : 2010:12:12 14:02:02+01:00
    [System] File Permissions : rw-r--r--
    [File] File Type : EPS
    [File] MIME Type : application/postscript
    [PostScript] Creator : cairo 1.8.8 (http://cairographics.org)
    [PostScript] Create Date : Sun Dec 12 14:02:02 2010
    [PostScript] Pages : 1
    [PostScript] Bounding Box : 0 0 210 210
    [Composite] Image Height : 210
    [Composite] Image Width : 210
    [Composite] Image Size : 210x210


    Output (after bitmap export) of metadata with

       exiftool -G1 -a sample.png:

       
    [ExifTool] ExifTool Version Number : 8.40
    [System] File Name : sample.png
    [System] Directory : .
    [System] File Size : 83 kB
    [System] File Modification Date/Time : 2010:12:12 14:02:43+01:00
    [System] File Permissions : rw-r--r--
    [File] File Type : PNG
    [File] MIME Type : image/png
    [PNG] Image Width : 1757
    [PNG] Image Height : 1746
    [PNG] Bit Depth : 8
    [PNG] Color Type : RGB with Alpha
    [PNG] Compression : Deflate/Inflate
    [PNG] Filter : Adaptive
    [PNG] Interlace : Noninterlaced
    [PNG] Significant Bits : 8 8 8 8
    [PNG] Pixels Per Unit X : 23622
    [PNG] Pixels Per Unit Y : 23622
    [PNG] Pixel Units : Meters
    [PNG] Software : www.inkscape.org
    *[PNG] Title : Sample drawing
    *[PNG] Author : Author: Peter Burger
    *[PNG] Description : A green star in a blue circle in a red square
    *[PNG] Creation Time : 2010-12-12 13:50:00
    *[PNG] Source : Source URI
    [Composite] Image Size : 1757x1746
       * The only metadata transferred by Inkscape to PNG file.
    These values can also be picked up from the XMP-cc namespace in the original SVG file.