Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.5

Bug #841 free() - image destroy
Submitted: 2004-02-23 10:39 UTC
From: sese at lapd dot cj dot edu dot ro Assigned: jausions
Status: Closed Package: Image_Transform
PHP Version: 4.2.2 OS: rh9
Roadmaps: (Not assigned)    

 [2004-02-23 10:39 UTC] sese at lapd dot cj dot edu dot ro
Description: ------------ I get a warnnig message whe I run the code from below. I want to resize an image an save the result on disk. The problem seems to be in free() method: function free() { --> $this->imageHandle = $this->old_image; <-- $this->resized = false; ImageDestroy($this->old_image); if ($this->imageHandle){ ImageDestroy($this->imageHandle); } } After resizing $this->imageHandle has #3 resurce id, and $this->old_image #2. So, when I set the $this->imageHandle with the value of old_image resurce ID, I lost the old value, and after first ImageDestroy($this->old_image), the second ImageDestroy() will raise an warnning, because the $this->imageHandle has the same value but was destroyed before. Reproduce code: --------------- <? require_once("Image/Transform.php"); $imgt=&Image_Transform::factory("GD"); $imgt->load("test.jpg"); $imgt->scaleByFactor(0.5); $imgt->save("thumb_test.jpg"); ?> Actual result: -------------- Warning: imagedestroy(): 2 is not a valid Image resource in /usr/share/pear/Image/Transform/Driver/GD.php on line 281


 [2004-05-18 22:17 UTC] jausions
Please see bug #1406.
 [2004-12-16 00:53 UTC] powtac at gmx dot de
I get the same error. Win98 PHP 5.0.1 Code: require_once 'Image/Transform.php'; $Pic = Image_Transform::factory('GD'); $Pic->load($name); $Pic->scaleByLength(200); $successPic = $Pic->save($name, '', 90); $Pic->free(); Warning: imagedestroy(): 74 is not a valid Image resource in ...\Pear\Image\Transform\Driver\GD.php on line 271 Perhaps a PHP 5 Error?
 [2005-03-07 14:33 UTC] troels at kyberfabrikken dot dk
It's not a php5 error - it's present in php4 aswell. The reason is bad coding skills. Replace method free() of Image/Driver/GD.php with this, to fix : <pre> function free() { $this->resized = false; if ($this->imageHandle) { ImageDestroy($this->imageHandle); $this->imageHandle = NULL; } if ($this->old_image){ ImageDestroy($this->old_image); $this->old_image = NULL; } } </pre>
 [2005-04-28 04:07 UTC] jausions
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on In case this was a website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.