phpimageimage-processingimagemagickgd

Upload jpg/png, convert to pdf and save with PHP?


Been doing a fair bit of digging this morning, and not seeing an obvious answer - is it possible to save an image to pdf format using PHP (or one of it's many libraries)?

I am fairly familiar with GD, although it doesn't seem to have a built in PDF format exporter/save function from my reading so far.

If anyone has any suggestions, it would be much appreciated!!


Solution

  • I tried to add this to the accepted answer. Here is an example of how to convert an image to a different format (including pdf) with the Imagick module:

    $img = new Imagick('path/to/image.jpg');
    $img->setImageFormat('pdf');
    $success = $img->writeImage('path/to/image.pdf');
    

    OR

    $img = new Imagick();
    $img->readImageBlob($imageBytes);
    $img->setImageFormat('pdf');
    $success = $img->writeImage('path/to/image.pdf');