IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
function savePagesAsPDF($pages, $saveAs='temp.pdf')
{
if ($pages)
{
$w = NewMagickWand();
MagickAppendImages($w);
foreach ($pages as $p)
{
MagickReadImage($w, $p);
// Convert image to jpg compression (otherwise it will convert jpgs to tifs and they will be HUGE)
MagickSetImageCompression($w, MW_JPEGCompression);
MagickSetImageCompressionQuality($w, 40); // 40% compression
}
MagickSetFormat($w, 'PDF' );
MagickWriteImages($w, $saveAs, true);
}
return $saveAs;
}
function savePagesAsPDF($pages, $saveAs='temp.pdf')
{
if ($pages)
{
$w = NewMagickWand();
MagickAppendImages($w);
foreach ($pages as $p)
{
MagickReadImage($w, $p);
// Convert image to jpg compression (otherwise it will convert jpgs to tifs and they will be HUGE)
MagickSetImageCompression($w, MW_JPEGCompression);
MagickSetImageCompressionQuality($w, 40); // 40% compression
}
MagickSetFormat($w, 'PDF' );
MagickWriteImages($w, $saveAs, true);
}
return $saveAs;
}
Thanks mkoppanen. Wow, that seems to be much simpler code. It doesn't quite work though. The first page is ok, but other pages are not. If I have 3 files paths in my array, the first page is ok, but the next two pages are not created.
then it will create 3 pdf files that look right, but then if I change the second parameter of writeImages to true, it creates that problem. I'm wondering if this is a bug in the interface...
then it will create 3 pdf files that look right, but then if I change the second parameter of writeImages to true, it creates that problem. I'm wondering if this is a bug in the interface...
I tested the code here and I seem to get the correct results (??).