From curiosity and for my own knowledge, I wanted to test whether there is any significant difference in performance between ImageMagick and the GD php library, and it seems like yes, there is a difference and it is not at all small, is huge!
The test was done on a local Windows server, based on XAMPP stack, version 7.3.0. The basic hardware configuration of the server:
- AMD Ryzen 5 1600X, 3.6 GHz, AM4, 16MB
- 32GB (2x16GB) DDR4 3200MHz – Corsair Dominator Platinum
- MSI X470 GAMING PLUS, AMD X470, AMD AM4
- SSD Samsung 850 Pro 256GB SATA-III 2.5 inch (Apache/PHP)
- SSD 960 EVO NVMe M2 500GB MZ V6E500BW (WIN)
For the first time I installed ImageMagick what gave me a little headache, 3 separate archives, a change in php.ini and manual file copying, but in the end everything was perfect, with no problems!
On a Linux server it still did not do the test, because I did not have the patience to install ImageMagick there, but I come back with details in the future.
I do not go into details, because the image in the article says exactly what’s needed:
“imagick” is much faster than “gd” , even 3 times more faster!
I have not tested the entire library but only what is most important for a wordpress photo gallery site: resizing images.
Unfortunately, on the Windows platform, ImageMagick does not come with OpenCL enabled, meaning it does not automatically use the best performing device: CPU or GPU. is compiled only with the OpenMP (Open Multi-Processing) option that only uses the processor in a more efficient way. From ImageMagick documentation, the performance using a GPU can be very large, even 10 times higher (a magnitude order). It remains to be seen in the future that there will be results on linux with OpenCL, but for now the results are clear:
GD is far inferior than ImageMagick!
Ca si test, practic am redimensionat o imagine in format JPG de 6.61Mb cu o rezoultie de 4752 x 3168 pixeli, calitate 97% intr-o alta imagine in acelasi format JPG dar la o rezolutie mai mica, 640 x 427 px si o calitate/compresie de 90%. Imaginea folosita o gasiti aici: Gemstone Collection.
Pentru cei care vor sa verifice performantele scriptul folosit de mine este mai jos:
<?php PHP_OS == "Windows" || PHP_OS == "WINNT" ? define("DIRSEPARATOR", "\\\\") : define("DIRSEPARATOR", "/"); function get_FileFullPath($img) { $folder_img = dirname(__FILE__); return str_replace("\\", DIRSEPARATOR, $folder_img).DIRSEPARATOR.$img; } $fsource = "benchmark-img.jpg"; $fdest_imagick = "test-imagick.jpg"; $fdest_gd = "test-gd.jpg"; $file_source = get_FileFullPath($fsource); $file_dest_imagick = get_FileFullPath($fdest_imagick); $file_dest_gd = get_FileFullPath($fdest_gd); $w = 640; $h = 640; // ~~~~~~~~~~~~~~~~~ ImageMagick ~~~~~~~~~~~~~~~~~~~~~ $start_time = microtime(true); $im = new imagick( $file_source ); $im->setImageCompression(Imagick::COMPRESSION_JPEG); $im->setImageCompressionQuality(90); $im->stripImage(); $im->thumbnailImage($w, 0); //$im->resizeImage(320,240,Imagick::FILTER_LANCZOS,1); $im->writeImage( $file_dest_imagick ); $end_time = microtime(true); echo ($end_time-$start_time) . " sec"; echo "<br />"; echo "<img src='$fdest_imagick'>"; echo "<hr />"; // ~~~~~~~~~~~~~~~~~~ GD php library ~~~~~~~~~~~~~~~~~~~~ $start_time = microtime(true); list($width, $height) = getimagesize( $file_source ); $r = $width / $height; if ($w/$h > $r) { $newwidth = $h*$r; $newheight = $h; } else { $newheight = $w/$r; $newwidth = $w; } $src = imagecreatefromjpeg($file_source); $dst = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($dst, $file_dest_gd, 90 ); $end_time = microtime(true); echo ($end_time-$start_time) . " sec"; echo "<br />"; echo "<img src='$fdest_gd'>"; ?>
Resource:
- ImageMagick Downloads area
https://imagemagick.org/script/download.php - instructions, How to install and enable the Imagick extension in XAMPP for Windows
https://ourcodeworld.com/articles/read/349/how-to-install-and-enable-the-imagick-extension-in-xampp-for-windows - How to Install the PHP ImageMagick Extension (IMagick) for Linux
https://serverpilot.io/docs/how-to-install-the-php-imagemagick-extension - Image Processing (ImageMagick) – PHP
https://www.php.net/manual/en/book.imagick.php
Be First to Comment