function getMetadata($image, $filename) { if (!isset($image->parsedPNGMetadata)) { try { $image->parsedPNGMetadata = PNGMetadataExtractor::getMetadata($filename); } catch (Exception $e) { // Broken file? wfDebug(__METHOD__ . ': ' . $e->getMessage() . "\n"); return '0'; } } return serialize($image->parsedPNGMetadata); }
public function testPngGreyscaleNoAlphaColour() { $meta = PNGMetadataExtractor::getMetadata($this->filePath . 'greyscale-na-png.png'); $this->assertEquals('greyscale', $meta['colorType']); }
/** Entry point for png * At some point in the future this might * merge the png various tEXt chunks to that * are interesting, but for now it only does XMP * * @param string $filename full path to file * @return Array Array for storage in img_metadata. */ public static function PNG($filename) { $showXMP = function_exists('xml_parser_create_ns'); $meta = new self(); $array = PNGMetadataExtractor::getMetadata($filename); if (isset($array['text']['xmp']['x-default']) && $array['text']['xmp']['x-default'] !== '' && $showXMP) { $xmp = new XMPReader(); $xmp->parse($array['text']['xmp']['x-default']); $xmpRes = $xmp->getResults(); foreach ($xmpRes as $type => $xmpSection) { $meta->addMetadata($xmpSection, $type); } } unset($array['text']['xmp']); $meta->addMetadata($array['text'], 'native'); unset($array['text']); $array['metadata'] = $meta->getMetadataArray(); $array['metadata']['_MW_PNG_VERSION'] = PNGMetadataExtractor::VERSION; return $array; }
/** Entry point for png * At some point in the future this might * merge the png various tEXt chunks to that * are interesting, but for now it only does XMP * * @param string $filename Full path to file * @return array Array for storage in img_metadata. */ public static function PNG($filename) { $showXMP = XMPReader::isSupported(); $meta = new self(); $array = PNGMetadataExtractor::getMetadata($filename); if (isset($array['text']['xmp']['x-default']) && $array['text']['xmp']['x-default'] !== '' && $showXMP) { $xmp = new XMPReader(LoggerFactory::getInstance('XMP')); $xmp->parse($array['text']['xmp']['x-default']); $xmpRes = $xmp->getResults(); foreach ($xmpRes as $type => $xmpSection) { $meta->addMetadata($xmpSection, $type); } } unset($array['text']['xmp']); $meta->addMetadata($array['text'], 'native'); unset($array['text']); $array['metadata'] = $meta->getMetadataArray(); $array['metadata']['_MW_PNG_VERSION'] = PNGMetadataExtractor::VERSION; return $array; }
foreach ($dir as $fileinfo) { if (!$fileinfo->isDot()) { $fileName = $fileinfo->getFilename(); $ext = pathinfo($fileName, PATHINFO_EXTENSION); if ($ext == "dmi") { $dmiFiles[] = $fileName; } } } print "<body style='background-color: #888888;'></body>"; $verbose = false; foreach ($dmiFiles as $i => $inFile) { //if($verbose){ print "<h1>{$inFile}</h1>"; //} $metadata = PNGMetadataExtractor::getMetadata("in/" . $inFile); $dmi = $metadata["text"]["ImageDescription"]["x-default"]; $metadata = explode("\n", trim($dmi)); $width = 32; $height = 32; $version = 0; $state = ""; $dirs = ""; $frames = ""; $delay = ""; $loop = ""; $hotspot = ""; $rewind = ""; $movement = ""; $first = true; $sprites = array();