Repository navigation
imagebmp is extremely slow on Windows #23457
Copy link
Copy link
Closed
Labels
Description
Description
imagebmp is extremely slow on Windows.
(PS, there is also a performance issue with imagegrabscreen(), it is much slower than equivalent Python-mss code: #23459 )
The following code:
<?php
$t = microtime(true);
$h = imagegrabscreen();
$grab = microtime(true) - $t;
echo 'Grab: ' . sprintf('%.9f', $grab) . " s\n";
$t = microtime(true);
$r = imagebmp($h, 'bmp0.bmp', false);
$dt = microtime(true) - $t;
echo 'BMP no compression: ' . sprintf('%.9f', $dt) . ' s (result: ' . var_export($r, true) . ')' . "\n";
$t = microtime(true);
$r = imagebmp($h, 'bmp1.bmp', true);
$dt = microtime(true) - $t;
echo 'BMP compressed: ' . sprintf('%.9f', $dt) . ' s (result: ' . var_export($r, true) . ')' . "\n";
$t = microtime(true);
$r = imagepng($h, 'png0.png', 0);
$dt = microtime(true) - $t;
echo 'PNG no compression: ' . sprintf('%.9f', $dt) . ' s (result: ' . var_export($r, true) . ')' . "\n";
$t = microtime(true);
$r = imagepng($h, 'pngd.png', -1);
$dt = microtime(true) - $t;
echo 'PNG default compression: ' . sprintf('%.9f', $dt) . ' s (result: ' . var_export($r, true) . ')' . "\n";
imagedestroy($h);Resulted in this output:
PS C:\Users\hansh> php test.php
Grab: 7.558355093 s
BMP no compression: 48.639475107 s (result: true)
BMP compressed: 52.303011179 s (result: true)
PNG no compression: 0.094882011 s (result: true)
PNG default compression: 0.109680176 s (result: true)
PHP Deprecated: Function imagedestroy() is deprecated since 8.5, as it has no effect since PHP 8.0 in C:\Users\hansh\test.php on line 29
Deprecated: Function imagedestroy() is deprecated since 8.5, as it has no effect since PHP 8.0 in C:\Users\hansh\test.php on line 29
But I expected this output instead:
BMP no compression: 0.019475107 s (result: true)
BMP compressed: 0.013011179 s (result: true)
- png executed in 0.01 seconds, BMP needs 40 seconds.
PHP Version
Observed both windows 11 with
PHP 8.5.1 (cli) (built: Dec 17 2025 10:55:54) (ZTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Zend Engine v4.5.1, Copyright (c) Zend Technologies
with Zend OPcache v8.5.1, Copyright (c), by Zend Technologies
and Windows Server 2025 with
PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
Operating System
Observed on both Windows Server 2025, and Windows 11, both x86-64
Activity
divinity76 commentedon Aug 25, 2026
For comparsion, Python-mss +PIL does everything combined in <1s:
Fix phpGH-23457: imagebmp() is extremely slow when writing to a file
Merge branch 'PHP-8.4' into PHP-8.5
Merge branch 'PHP-8.5'