[Clipart] SVG support for getid3

Bryce Harrington bryce at bryceharrington.org
Tue Jul 4 18:56:34 PDT 2006


In case anyone else is interested in taking on ccHost work, the
following is as far as I'd gotten with implementing svg support in
ccHost.  Basically, install the ccHost and getid3 packages, then put
this file in the getid3 directory.

Here's a wiki page with some info and tasks that looked like they needed
doing:

   http://openclipart.org/wiki/index.php/CcHost

We'd had some good discussions back in Feb about getting ccHost working,
and the issues we'd discovered:

   http://lists.freedesktop.org/pipermail/clipart/2006-February/thread.html

In particular, see the "SVG support for getID3" thread.

Jonadab also posted this potential solution to the problem I'd run into,
but by then I'd gotten tied up with other stuff so never got around to
testing it (sorry jonadab!)  :-/

   http://lists.freedesktop.org/pipermail/clipart/2006-March/005373.html

ccHost is reasonably easy to get set up and running, if you have ever
set up php apps before, and it's got the necessary documentation and
stuff.  I was a bit in the dark about how to start doing the svg module,
but I found the authors of cchost and getid3 were friendly and helpful.
Even though I don't think the code I wrote actually worked, it should
hopefully be in the right direction, so if someone else would like to
take it from here it may be worth referencing.

Bryce

----- Forwarded message from Bryce Harrington <bryce at bryceharrington.org> -----

Date: Mon, 20 Feb 2006 01:23:04 -0800
From: Bryce Harrington <bryce at bryceharrington.org>
To: Tobias Jakobs <tobias.jakobs at web.de>
Cc: clipart at lists.freedesktop.org
Subject: Re: [Clipart] SVG support for getid3

On Sun, Feb 19, 2006 at 05:52:51PM +0100, Tobias Jakobs wrote:
> Hi,
> 
> a friend of mine hacked a little bit on getid3, to get the SVG metadata.
> You can see the results here:
> http://hagemaenner.de/stuff/openclipart/getid3/

Cool, this looks like it'll be a good start for us.
 
> It is just a beginning which just prints some metadata to stdout. He
> will not continue to work on it, because he is out off town for quit
> some time. So it's our turn again.

I've added a bit to it (below)...

Bryce



<?php
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info at getid3.org>               //
//  available at http://getid3.sourceforge.net                 //
//            or http://www.getid3.org                         //
/////////////////////////////////////////////////////////////////
// See readme.txt for more details                             //
/////////////////////////////////////////////////////////////////
//                                                             //
// module.graphic.svg.php                                      //
// module for analyzing SVG Image files                        //
// dependencies: XMLReader                                     //
//                                                             //
/////////////////////////////////////////////////////////////////


class getid3_svg
{
                
    const cc="http://web.resource.org/cc/";
    const dc="http://purl.org/dc/elements/1.1/";
    const rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";


    private function readTitle(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "title")) {
            $xml->read();
            echo "readTitle: ",$xml->name,"\n";
        }
    }

    private function readDescription(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "description")) {
            $xml->read();
            echo "readDescription: ",$xml->name,"\n";
        }
    }

    private function readSubject(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "subject")) {
            $xml->read();
            echo "readSubject: ",$xml->name,"\n";
        }
    }

    private function readPublisher(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "publisher")) {
            $xml->read();
            echo "readPublisher: ",$xml->name,"\n";
        }
    }

    private function readRights(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "rights")) {
            $xml->read();
            echo "readRights: ",$xml->name,"\n";
        }
    }

    private function readCreator(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "creator")) {
            $xml->read();
            echo "readCreator: ",$xml->name,"\n";
        }
    }
    
    private function readDate(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "date")) {
            $xml->read();
            echo "readDate: ",$xml->name,"\n";
        }
    }
    
    private function readFormat(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "format")) {
            $xml->read();
            echo "readFormat: ",$xml->name,"\n";
        }
    }
    
    private function readLicense(&$xml) {
        $xml->read();
        while (($xml->nodeType != XMLReader::END_ELEMENT) && ($xml->localName != "license")) {
            $xml->read();
            echo "readLicense: ",$xml->name,"\n";
        }
    }
    
    

    function getid3_svg(&$fd, &$ThisFileInfo) {
	echo "found svg file";
	echo $ThisFileInfo['svg'], "\n";

	$contents = file_get_contents($ThisFileInfo['svg']);

        $xml = new XMLReader();
        $xml->open($ThisFileInfo['svg']);

        while ($xml->read()) {
            /* TODO:  Read the <svg> tag attributes, height and width */
            if (($xml->localName == "svg")) {
                $ThisFileInfo['svg']['width']  = $xml->getAttribute("width");
                $ThisFileInfo['svg']['height'] = $xml->getAttribute("height");
            }

            if ($xml->nodeType == XMLReader::ELEMENT) {

                if ($xml->prefix != "")
                    $namespace = $xml->lookupNamespace($xml->prefix);

                if ($namespace == self::dc) {
                  switch ($xml->localName) {
                    case "publisher":
                      getid3_svg::readPublisher($xml);
                      break;
                    case "creator":
                      getid3_svg::readCreator($xml);
                      break;
                    case "rights":
                      getid3_svg::readRights($xml);
                      break;
                    case "title":
                      getid3_svg::readTitle($xml);
                      break;
                    case "description":
                      getid3_svg::readDescription($xml);
                      break;
                    case "subject":
                      getid3_svg::readSubject($xml);
                      break; 
                  }           
                }
            }

        }

        $ThisFileInfo['fileformat']                   = 'svg';
        $ThisFileInfo['video']['dataformat']          = 'svg';
        $ThisFileInfo['video']['lossless']            = true;
        $ThisFileInfo['video']['bits_per_sample']     = 24;
        $ThisFileInfo['video']['pixel_aspect_ratio']  = (float) 1;

        $ThisFileInfo['video']['resolution_']         = $ThisFileInfo['svg']['width'];
        $ThisFileInfo['video']['resolution_']         = $ThisFileInfo['svg']['height'];

/* 
        foreach ($xml->metadata->children('http://www.w3.org/1999/02/22-rdf-syntax-ns#') as $rdf) {
            var_dump $rdf->children('http://web.resource.org/cc/');
            //->children('http://purl.org/dc/elements/1.1/');
        } 
	echo "\n \n";
	echo $xml->metadata[0]->RDF[0]->Work[0]->title[0];
*/
        return true;
	}
}


?>
_______________________________________________
clipart mailing list
clipart at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/clipart

----- End forwarded message -----



More information about the clipart mailing list