php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12780 ImageCopyResampled ignores srcX and srcY parameters
Submitted: 2001-08-15 22:31 UTC Modified: 2002-05-13 16:21 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: barnabas at kendall dot net Assigned:
Status: Closed Package: GD related
PHP Version: 4.0.6 OS: Windows 2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: barnabas at kendall dot net
New email:
PHP Version: OS:

 

 [2001-08-15 22:31 UTC] barnabas at kendall dot net
The Source X and Y parameters are ignored by the function ImageCopyResampled. This may be a bug with the GD 2.0.1 library itself, since an examination of gd.c lines 1960-2085 reveal no significant reference to these parameters. My e-mail to the developers is getting bounced, so I turn to you. I used the setup program for Windows to install PHP 4.0.6 on a fresh Windows 2000 machine, but I believe the problem is platform independant.

Here's how to reproduce the bug:

1: Create a 200 x 200 JPEG image named "grid.jpg". Divide it into four colored sqares of equal size, just for the demonstration.

2: Create an HTML page with the following content:

<p>
<img src="imgTest.php?src_w=100&src_h=100" alt="(src_w=100, src_h=100)"><br>
<img src="imgTest.php?src_w=100&src_h=100&src_x=100" alt="(src_w=100, src_h=100, src_x=100)"><br>
<img src="imgTest.php?src_w=100&src_h=100&src_y=100" alt="(src_w=100, src_h=100, src_y=100)"><br>
<img src="imgTest.php?src_w=100&src_h=100&src_x=100&src_y=100" alt="(src_w=100, src_h=100, src_x=100, src_y=100)"><br>
</p>

<p>
<img src="imgTest.php?mode=sample&src_w=100&src_h=100" alt="(src_w=100, src_h=100)"><br>
<img src="imgTest.php?mode=sample&src_w=100&src_h=100&src_x=100" alt="(src_w=100, src_h=100, src_x=100)"><br>
<img src="imgTest.php?mode=sample&src_w=100&src_h=100&src_y=100" alt="(src_w=100, src_h=100, src_y=100)"><br>
<img src="imgTest.php?mode=sample&src_w=100&src_h=100&src_x=100&src_y=100" alt="(src_w=100, src_h=100, src_x=100, src_y=100)"><br>
</p>

3: Create a PHP page named "imgTest.php" with the following content:
<?php
// test of the GD functions...

$src_img = ImageCreateFromJPEG("./grid.jpg"); 

if (empty($dest_x)) $dest_x = 0;
if (empty($dest_y)) $dest_y = 0;
if (empty($dest_w)) $dest_w = 100;
if (empty($dest_h)) $dest_h = 100;

if (empty($src_x)) $src_x = 0;
if (empty($src_y)) $src_y = 0;
if (empty($src_w)) $src_w = ImageSX($src_img);
if (empty($src_h)) $src_h = ImageSY($src_img);

$dst_img = ImageCreateTrueColor($dest_w, $dest_h);

if ($mode == "sample") {
	ImageCopyResampled( $dst_img, $src_img, $dest_x, $dest_y, $src_x, $src_y, $dest_w, $dest_h, $src_w, $src_h);
} else {
	ImageCopyResized( $dst_img, $src_img, $dest_x, $dest_y, $src_x, $src_y, $dest_w, $dest_h, $src_w, $src_h);
}

header("Content-type: image/JPEG");
ImageJPEG($dst_img);
ImageDestroy($dst_img);
ImageDestroy($src_img);
?>

The result is that the bottom group of squares will all be from the upper left corner, while the top group of squares will be separate corners. This shows that the functions are not interchangable.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-31 06:42 UTC] sander@php.net
[User input: vwallen@antlab.net]
I have experienced an issue identical to bug #12780, on a
Linux machine running RedHat 7.1, Apache 1.3.20, PHP
4.0.6, and GD 2.0.1. The original bug was running under
Win2000.
 [2001-10-20 17:36 UTC] barnabas at kendall dot net
The following was in the user manual. Could someone please apply this fix for the next release?

andrew@2mx.co.uk
01-Oct-2001 03:42 
 
As reported above, there is a bug in this function which basically means it ignores the srcX and srcY parameters. The fix is really easy, assuming you don't mind recompiling GD. 

You need to change the lines in gd.c that read: 

p = gdImageGetTrueColorPixel ( src, (int) sx, 
(int) sy; 

to read: 

p = gdImageGetTrueColorPixel ( src, (int) sx + srcX, 
(int) sy + srcY; 

 [2002-05-13 16:06 UTC] hannes at phpug dot ch
If you need a quick fix for this issue, just take this tiny patch proposed in the manual:

http://phpug.ch/patches/gd.diff

could somebody then tell me why such a bug can remain unfixed for such a long time?
 [2002-05-13 16:21 UTC] rasmus@php.net
Well, the bug is not in PHP, so I am not sure why you are complaining here.  We have gotten frustrated as well with the slow pace of development of GD so in 4.3 or later GD will be bundled with PHP.  I have fixed this issue in this bundled version of GD.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 22:01:26 2024 UTC