Combine JPG into one PDF with PHP

I am trying to take a series of JPGs and combine them into one PDF, with each JPG being its own page. I guess ImageMagick is the best way to do this, but I can't figure out how to combine the files. I can see the combImages method:

http://php.net/manual/en/imagick.combineimages.php

But can't find any examples. I am new to imagemagick so I am still trying to understand the syntax.

Can ImageMagick do what I ask? And if this can anyone write a quick example?

Thank!

+3


source to share


1 answer


As PHP

you can use:

$images = array("file1.jpg", "file2.jpg");

$pdf = new Imagick($images);
$pdf->setImageFormat('pdf');
$pdf->writeImages('combined.pdf', true); 

      

The true

c parameter is writeImages

important because it will force the method to write a sequence of images, not just one.




You can also do this from the command line:
convert file1.jpg file2.jpg output.pdf

      

+15


source







All Articles