For those who don't have ImageMagick for whatever reason, GD functions will also work, in conjunction with GhostScript. Run the ghostscript command with exec()
to convert a PDF to JPG, and manipulate the resulting file with imagecreatefromjpeg()
.
Run the ghostscript command:
exec('gs -dSAFER -dBATCH -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r300 -sOutputFile=whatever.jpg input.pdf')
To manipulate, create a new placeholder image, $newimage = imagecreatetruecolor(...)
, and bring in the current image. $image = imagecreatefromjpeg('whatever.jpg')
, and then you can use imagecopyresampled()
to change the size, or any number of other built-in, non-imagemagick
commands