Omar Shamali

GdImage VS Imagick PHP Libraries Performance Benchmark of Reading Image Width

Author: Omar Shamali
Writing Date:

The whole story began when I needed to convert images from types other than JPEG, PNG..etc that are supported with GD Library. Before depending fully on Imagick for everything not only conversion, I decided to make benchmarks.

Number of Different Tests

Surprisingly, I stopped after one test for getting shocked of the results. Maybe I will do further tests in the future.

The Test Focus

The test focused on a very simple task, which is just to get the image file width.

Test Results

GDImage crushed Imagick in this test, GdImage is faster by at least ten times in getting image width.

Test Algorithm

Use the most direct methods in order to get specific image's width, without actually reading or fully loading the image.

Put the reading width methods inside for loops of 10000 cycles.

Result in Numbers

  Process Time
GD Image 0.0592770576 Seconds
Imagick 1.2443468571 Seconds

Test Code in PHP

$___time_started=microtime(true);

    for($i=0;$i<10000;$i++){
        getimagesize('168527xxxxxxx87.jpg');
    }
    $final=round((microtime(true) - $___time_started),10);

    echo $final.'<br><br>';

    

    $___time_started=microtime(true);

    for($i=0;$i<10000;$i++){
        $imagick=new Imagick;
        $imagick->pingImage('168527xxxxxxx87.jpg');
        $imagick->getImageWidth();
    }

    $final=round((microtime(true) - $___time_started),10);
    echo $final;

Test Environment

PHP version 8.1