php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24120 imagecopyresized / imagecopyresampled result is bad
Submitted: 2003-06-11 03:03 UTC Modified: 2003-06-11 03:12 UTC
From: mail at martin-schultheiss dot de Assigned:
Status: Not a bug Package: GD related
PHP Version: 4.3.2 OS: RedHat-Linux 7.3
Private report: No CVE-ID: None
 [2003-06-11 03:03 UTC] mail at martin-schultheiss dot de
Hi! 
 
I have upgraded from php 4.1.x to 4.3.2 with the builtin 
gd library. 
 
Now the result of the imagecopyresized funtion is very 
bad, and the result of the imagecopyresampled function 
too.  
 
I don`t know how to describe the error exactly, so please 
take a look at http://www.martin-schultheiss.de/test.jpg 
and http://www.martin-schultheiss.de/test2.jpg 
 
If I dont resize the image but simply read it with 
imagecreatefromjpeg the result is OK.  
 
The code used to create the image is: 
$source = imagecreatefromjpeg ($filename); 
$x = imagesx($source); 
$y = imagesy($source); 
$max = max($x, $y); 
$format = $y > $x; //Portrait or Landscape 
 
$size = 640; 
if ($size != $max) { //Image has to be resized 
if ($format) { 
$result = imagecreate(($x*$size)/$y,$size); 
imagecopyresized($result, $source, 0, 0, 0, 0, 
(($x*$size)/$y) - 1, $size - 1, $x - 1, $y - 1); 
} else { 
$result = imagecreate($size,($y*$size)/$x); 
imagecopyresized($result, $source, 0, 0, 0, 0, $size - 1, 
(($y*$size)/$x) - 1, $x - 1, $y - 1); 
} 
imageDestroy($source); 
} else { 
$result = $source; 
} 
imagejpeg($result); 
imageDestroy($result); 
 
Bye, 
	Martin 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-11 03:06 UTC] rasmus@php.net
Didn't I already answer this exact report a while ago?  You need to use 
imagecreatetruecolor() instead of imagecreate() in your code to avoid getting a palletted image.
 [2003-06-11 03:12 UTC] mail at martin-schultheiss dot de
I`m sorry, my english is very bad because it`s not my 
nativ language and I didn`t understand the old bug-report 
correctly. I thought there would be a function which 
specially creates non-true-color images, and this function 
must not be used. 
 
This solved the problem, thanks!
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Mar 14 23:00:02 2026 UTC