Reputation: 21440
I have installed ImageMagick on my server for the purpose of converting a PNG image to PDF. I came across this code:
convert image1.png image2.png image3.png output.pdf
Ref. http://www.wizards-toolkit.org/discourse-server/viewtopic.php?f=1&t=16778
I am not sure how to run this from PHP. Also, I don't have image files, but rather, I have a stream like so:
<?php
$im = imagecreatefrompng("test.png");
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
Can someone tell me how to convert this image stream, $im
to PDF using ImageMagick? I've tried google'ing but I haven't found any examples. Thanks.
Upvotes: 1
Views: 6722
Reputation: 21440
This worked for me:
$yourPngImage = imagecreatefrompng("test.png");
$im = new Imagick();
ob_start();
imagepng($yourPngImage);
$image_data = ob_get_contents();
ob_end_clean();
// Get image source data
$im->readimageblob($image_data);
$im->setImageFormat('pdf');
header("Content-Type: application/pdf");
echo $im;
Upvotes: 1