Create PDF from an image on PHP

Recently a friend asked me to create a script to make a PDF document from a set of images. The initial idea was get a table of 3x3 images randomly from a bunch. He need to run it into his web server, for this reason I think PHP (language supported) is the best option. He has a lot of cards, for example (the full set is about 25-30 cards):

Image of exampleExample cardExample card

And he want to allow people to download random cards from Internet. This random characteristic is the key he wants to reach. The solution is very simple as you can see below.

Example of final image of random cards

Example of final image of random cards

First, as always, I look for information on the net and I get a couple pages of interest.

Here we can get basics functions to create simple images as rectangles or lines:
As you can see the simplest way is use "gd" library. This library is commonly installed on PHP web servers. I make a couple of test and everything works, so I'll develop the script with it. Another solution will be "ImageMagick" library, in my case I can use both, but if you are interested you must test wich one you can use.

On this other page I find some function to get my image on a PDF file.
With R&OS library you get "ezImage" function that is your solution. I must dig in by source code to understand all parameters because I can't find good documentation, but after couple tests I get my script work!

This script can be configured with the number of images on columns and rows. You can select the distance between images in pixels too. It's easy, I left some comments along the code.

I hope it will be usefull, here you can get my final script.

The script must be located on a folder next to all cards and the PDF library. I put here a compressed file with all together.

I hope it will be usefull, here you can get my final script.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos necesarios están marcados *

Puedes usar las siguientes etiquetas y atributos HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">