Bug #75382 [NEW]: imagerotate() doubles the memory usage

From: Date: Sun, 15 Oct 2017 13:27:05 +0000
Subject: Bug #75382 [NEW]: imagerotate() doubles the memory usage
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211699@lists.php.net to get a copy of this message
From: marc at gutt dot it Operating system: PHP version: 5.6.31 Package: *Graphics related Bug Type: Bug Bug description:imagerotate() doubles the memory usage Description: ------------ imagerotate() doubles the memory usage instead of functions like imageflip(). Its not really a bug because the function returns a new image resource but as image resolutions grow year-by-year this increases the memory requirements, too. I think the function should not return a new resource. Instead it should be a added a 4th option to overwrite the original image resource: imagerotate ( resource $image , float $angle , int $bgd_color [, int $ignore_transparent = 0 [, bool $return = true ]] ) Test script: --------------- <?php // image $url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/Pluto-01_Stern_03_Pluto_Color_TXT.jpg/1024px-Pluto-01_Stern_03_Pluto_Color_TXT.jpg'; file_put_contents('../cache4/' . basename($url), fopen($url, 'r')); $filename = '../cache4/' . basename($url); echo 'Before imagecreate: ' . round(memory_get_usage() / pow(1024, 2)) . ' MB (Max: ' . round(memory_get_peak_usage() / pow(1024, 2)) . ' MB)<br>' . PHP_EOL; // create image resource $image = imagecreatefromjpeg($filename); echo 'After imagecreate: ' . round(memory_get_usage() / pow(1024, 2)) . ' MB (Max: ' . round(memory_get_peak_usage() / pow(1024, 2)) . ' MB)<br>' . PHP_EOL; // rotate image $image = imagerotate($image, 180, 0); echo 'After imagerotate: ' . round(memory_get_usage() / pow(1024, 2)) . ' MB (Max: ' . round(memory_get_peak_usage() / pow(1024, 2)) . ' MB)<br>' . PHP_EOL; ?> Expected result: ---------------- Before imagecreate: 0 MB (Max: 0 MB) After imagecreate: 5 MB (Max: 5 MB) After imagerotate: 5 MB (Max: 5 MB) (by using "imagerotate($image, 180, 0, 0, false);") Actual result: -------------- Before imagecreate: 0 MB (Max: 0 MB) After imagecreate: 5 MB (Max: 5 MB) After imagerotate: 5 MB (Max: 10 MB) -- Edit bug report at https://bugs.php.net/bug.php?id=75382&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75382&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75382&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75382&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75382&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75382&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75382&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75382&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75382&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75382&r=support Expected behavior: https://bugs.php.net/fix.php?id=75382&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75382&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75382&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75382&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75382&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75382&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75382&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75382&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75382&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75382&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75382&r=mysqlcfg

« previous php.bugs (#211699) next »