php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38627 Image resources seem to be reused although destroyed
Submitted: 2006-08-28 14:36 UTC Modified: 2006-08-28 14:57 UTC
From: toby@php.net Assigned:
Status: Not a bug Package: GD related
PHP Version: 5.2.0RC2 OS: Gentoo
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: toby@php.net
New email:
PHP Version: OS:

 

 [2006-08-28 14:36 UTC] toby@php.net
Description:
------------
1. Allocate an image resource $a.
2. Resample (scale) $a to a second resource $b.
3. Destroy $a.
4. Assign $a = $b.
5. Resample (crop) $a to a third resource $c.
6. Destroy $a.
7. Assign $a = $c.

For step 5 the initially allocated resource is used instead of the originally resampled one.


Reproduce code:
---------------
<?php

// http://schlitt.info/misc/gd/test_original.jpg
$res_1 = imagecreatefromjpeg( "test_original.jpg" );

$res_2 = imagecreatetruecolor( 200, 151 );

// Scale the image to 200x151
$res = imagecopyresampled(
    $res_2,     // dst_img
    $res_1,     // res_img
    0,          // dst_x
    0,          // dst_y
    0,          // src_x
    0,          // src_y
    200,        // dst_width
    151,        // dst_height
    150,        // src_width
    113         // src_height
);

// http://schlitt.info/misc/gd/test_scaled.jpg
imagejpeg( $res_2, "test_scaled.jpg" );

imagedestroy( $res_1 );

$res_1 = $res_2;

$res_3 = imagecreatetruecolor( 100, 100 );

// Crop the image to 100x100 selecting 50x150+50x150
$res = imagecopyresampled(
    $res_3,    // dst_img
    $res_1,    // res_img
    0,         // dst_x
    0,         // dst_y
    50,        // src_x
    50,        // src_y
    100,       // dst_width
    100,       // dst_height
    150,       // src_width
    150        // src_height
);

// http://schlitt.info/misc/gd/test_cropped.jpg
imagejpeg( $res_3, "test_cropped.jpg" );

imagedestroy( $res_1 );

$res_1 = $res_3;

// http://schlitt.info/misc/gd/test_final.jpg
imagejpeg( $res_1, "test_final.jpg" );

?>

Expected result:
----------------
test_cropped.jpg should be a cropped version of test_scaled.php

Actual result:
--------------
test_cropped.jpg is a cropped version of test_original.jpg

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-28 14:57 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 17:01:33 2025 UTC