[php-src] Issue #23457: imagebmp is extremely slow on Windows
[email protected] (divinity76)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Issue: https://github.com/php/php-src/issues/23457
Author: divinity76
### Description
imagebmp is extremely slow on Windows.
(PS, there is also a performance issue with `imagegrabscreen()`, it is much slower than equivalent Python [https://github.com/BoboTiG/python-mss](Python mss) code,
but I figure I'll make a file a separate issue for `imagegrabscreen`)
The following code:
```php
<?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
```plain
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