Home » Images » Image_Transform » Bug #841
free() - image destroy
Details
| 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) |
Comments
[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-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>