[Clipart] SVG support for getid3

Bryce Harrington bryce at bryceharrington.org
Mon Feb 20 01:23:04 PST 2006


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;
	}
}


?>



More information about the clipart mailing list