Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Created January 28, 2010 16:35
Show Gist options
  • Save pifantastic/288895 to your computer and use it in GitHub Desktop.
Save pifantastic/288895 to your computer and use it in GitHub Desktop.
<?php
// Get uncompressed size of file
$fp = fopen($filename, 'rb');
fseek($fp, -4, SEEK_END);
$buf = fread($fp, 4);
$size = end(unpack('V', $buf));
fclose($fp);
// Get uncompressed contents of file
$zd = gzopen($filename, 'rb');
$contents = gzread($zd, $size);
gzclose($zd);
// Write svg file
$svg = pathinfo($filename, PATHINFO_FILENAME).'.svg';
$fp = fopen($svg, 'wb');
fwrite($fp, $contents);
fclose($fp);
// Read svg meta
$svgxml = simplexml_load_string($contents);
// Extract width and height
$width = (string) $svgxml['width'];
$height = (string) $svgxml['height'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment