How to Convert ImageMagick PDF to Image PHP

Written by kevin walker
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert ImageMagick PDF to Image PHP
(Burke/Triolo Productions/Brand X Pictures/Getty Images)

PHP is a programming language commonly used on web servers. ImageMagick is a suite of tools that allows web servers to quickly and easily modify images when generating web content. Used together, ImageMagick and PHP are well suited to the task of taking Adobe Acrobat PDF files and converting them to ordinary images, such as GIFs, JPEGs, or PNGs.

Skill level:

Other People Are Reading


  1. 1

    Open a text editor.

  2. 2

    Paste the PHP tags into the text editor:



    The rest of the code will go between these two tags.

  3. 3

    Paste the following within the PHP tags:

    $args = func_get_args();

    $input = $args[0];

    $output = $args[1];

    exec("convert $input $output");

    This provides the first and second arguments to the script from the command line, and assumes the first is the PDF file to be converted and the second is the file name that should be used for the new file.

  4. 4

    Save your work as "pdf2img.php."

Tips and warnings

  • For example, run the following to convert a PDF named "ws.pdf" to a JPG named "ws.jpg."
  • php pdf2img.php ws.pdf ws.jpg
  • A multipage PDF will generate an image for each page with a count, so the above command on a PDF with two pages will generate the following files:
  • ws-0.jpg
  • ws-1.jpg
  • You can change the image format by changing the extension. ImageMagick will detect the extension and create the appropriate file. By changing "ws.jpg" to "ws.png" in the command line, you can use ImageMagick to create PNG files instead.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.