Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8753651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:28:05+00:00 2026-06-13T13:28:05+00:00

I am using Imagick to convert the first page of a PDF to a

  • 0

I am using Imagick to convert the first page of a PDF to a PNG image. It is working, but it is very slow.

A conversion takes between 8 and 20 seconds for a ~100kb PDF.

Is there a way to speed up the conversion?

My code :

$im = new Imagick($url);
$im->setIteratorIndex(0);
$im->setCompression(Imagick::COMPRESSION_LZW);
$im->setCompressionQuality(90);
$im->setImageFormat("png");
$im->writeImage('C:/Shared/test.png');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:28:06+00:00Added an answer on June 13, 2026 at 1:28 pm

    In fact , I don’t need Imagick library to generate a simple JPG preview of the first page of a PDF, I just need GhostScript.

    Command line conversion with GhostScript is always faster than Imagick (command line or through PHP)

    Example with a 12 pages and 650kb :

    • Command line GhostScript => 0.6 second
    • Command line Imagick => 0.8 second
    • PHP extension Imagick => 2.22 seconds

    With some documents, Imagick takes 20 seconds against 1.5 second with direct GS command line.

    Here is my test script

       <?php
    
        $pathToPdf = realpath("in.pdf");
    
        $pathToJpg = "./out.jpg";
        $pathToPng = "./out.png";
    
        try
            {
    
            $time_start = microtime(true);      
            $gsCall = "\"C:\Program Files (x86)\gs\gs9.06\bin\gswin32.exe\" -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dFirstPage=1 -dLastPage=1 -sOutputFile=\"{0}\" \"{1}\" -c quit";
            $gsCall = str_replace(array('{0}', '{1}'), array($pathToJpg, $pathToPdf), $gsCall); // or use sprintf
            $str = exec($gsCall, $output=array(), $returnValue);
            echo $gsCall.'<br><br>';
            $time_end = microtime(true);
            $time = $time_end - $time_start;        
            if($returnValue == 0)              
                print "<br><br>Conversion OK ".$time;
            else 
                print "<br><br>Conversion failed.<br />".var_dump($output);     
    
            $time_start = microtime(true);          
            exec('convert "'.$pathToPdf.'[0]" "'.$pathToPng.'"', $output, $returnValue);                        
            $time_end = microtime(true);
            $time = $time_end - $time_start;
            if($returnValue == 0)              
                print "<br><br>Conversion OK ".$time;
            else 
                print "<br><br>Conversion failed.<br />".var_dump($output);
    
            $time_start = microtime(true);
            $im = new Imagick($pathToPdf);
            $im->setIteratorIndex(0);
            $im->setCompression(Imagick::COMPRESSION_LZW);
            $im->setCompressionQuality(90);
            $im->setImageFormat("png");
            $im->writeImage('\\\\DELL-PC\Shared\test.png');
            //$im->thumbnailImage(200, 0);
            //echo $im;
            $time_end = microtime(true);
            $time = $time_end - $time_start;
            print "<br><br>Conversion OK ".$time;
        }
    catch(Exception $e)
    {
        echo $e->getMessage();
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ImageMagick to convert a pdf file to a png (thumbnail) image, and
I am working on creating thumbnail image from the first page of pdf file.
I'm currently using php's imagick to convert some PDF to images - This works
I'm trying to convert PDF to IMG (JPG) with help PHP. I'm using imagick
I am having different result when cropping two png files. Imagick Version using convert
I'm using a litte script to convert PDF to JPG. That works but the
I need to annotate an image with Chinese Text and I am using Imagick
I'm looking to center crop and image using Imagick PHP apis (not command line
I am trying to remove transparent areas of an image with php using imagick.
I'm using Imagick lib to do some modifications to original image. Then I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.