Created
February 14, 2013 09:29
-
-
Save hubgit/4951551 to your computer and use it in GitHub Desktop.
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 | |
function readInput() { | |
$file = 'test.png'; | |
if (!file_exists($file)) { | |
copy('http://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png', $file); | |
} | |
$im = new Imagick(); | |
$im->readImage($file); | |
$im->setImageFormat('JPEG'); | |
$im->setImageCompression(\Imagick::COMPRESSION_JPEG); | |
return $im; | |
} | |
// write directly to file with .jpg extension | |
$im = readInput(); | |
$im->writeImage('test-writeimage.jpg'); | |
// less test-writeimage.jpg: | |
// test-writeimage.jpg JPEG 800x600 800x600+0+0 8-bit DirectClass 47.7KB 0.000u 0:00.000 | |
// write to file via string | |
$im = readInput(); | |
file_put_contents('test-getimageblob.jpg', $im->getImageBlob()); | |
// less test-getimageblob.jpg: | |
// test-getimageblob.jpg JPEG 800x600 800x600+0+0 8-bit DirectClass 47.7KB 0.000u 0:00.000 | |
// write to resource | |
$im = readInput(); | |
$output = fopen('test-writeimagefile.jpg', 'w'); | |
$im->writeImageFile($output); | |
// less test-writeimagefile.jpg: | |
// test-writeimagefile.jpg PNG 800x600 800x600+0+0 8-bit DirectClass 235KB 0.000u 0:00.000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment