Created
September 28, 2012 15:15
-
-
Save smasty/3800452 to your computer and use it in GitHub Desktop.
Converts unprintable PDFs exported to SVG by Evince to PNG images.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = file_get_contents($argv[1]); | |
$offset = isset($argv[2]) ? $argv[2] : 0; | |
if(preg_match_all('~data:image\/png;base64,([^"]+)"~i', $data, $matches)){ | |
foreach($matches[1] as $k=>$i){ | |
$id = $k+1+$offset; | |
echo "Processing page $id..."; | |
$image = imagecreatefromstring(base64_decode($i)); | |
imagepng($image, "pages/$id.png"); | |
imagedestroy($image); | |
echo "Done\n"; | |
} | |
} else{ | |
echo "No pages found.\n"; | |
exit(1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment