php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23398 Thumbnails generation broken
Submitted: 2003-04-29 01:08 UTC Modified: 2003-04-29 03:02 UTC
From: len at abcda dot com Assigned:
Status: Not a bug Package: GD related
PHP Version: 4.3.2RC2 OS: RedHat Linux 7.2
Private report: No CVE-ID: None
 [2003-04-29 01:08 UTC] len at abcda dot com
I am generating a thumbnail from a submitted image and i get a broken image, the colors there are inadequate.

Here's the code i use:

function ImageName () {

    if($_FILES['userfile']['type']!='image/gif' && $_FILES['userfile']['type']!='image/jpeg' && $_FILES['userfile']['type']!= 'image/pjpeg' || !isset($_SESSION['SESSION_UNAME'])){

	return '';
    } else {

	$time = time();

	switch($_FILES['userfile']['type']) {
	    case 'image/gif':
		$newname = './upload/' . $_FILES['userfile']['name'] . $time . ".gif";
		if(!copy($_FILES['userfile']['tmp_name'],$newname)) {
		    echo "Can't copy";
		}
		$newname = $_FILES['userfile']['name'] . $time . ".gif";
		break;
	    case 'image/jpeg':
		case 'image/pjpeg':
		$newname = './upload/' . $_FILES['userfile']['name'] . $time . ".jpg";		
		if(!copy($_FILES['userfile']['tmp_name'],$newname)) {
		    echo "Can't copy";
		}
		$im = @ImageCreateFromJPEG($newname);
		$im_X = ImageSX($im);
		$im_Y = ImageSY($im);
	    $ThumbSize = getthumbSize($im_X,$im_Y);
		$im_thumb = ImageCreate($ThumbSize['x'],$ThumbSize['y']);
		ImageCopyResized($im_thumb,$im,0,0,0,0,$ThumbSize['x'],$ThumbSize['y'],$im_X,$im_Y);
		$thumb_name = './upload/thumb-' . $_FILES['userfile']['name'] . $time . ".jpg";
		ImageJPEG($im_thumb,$thumb_name);		
		$newname = $_FILES['userfile']['name'] . $time . ".jpg";
		break;
	}
	return $newname;
    }
}


this same thing happened in PHP 4.3.1, then it was fixed in PHP 4.3.2RC1, now it's present in PHP 4.3.2RC2 again...
I think it has to do with the new version of built-in GD library 2.0.12 against 2.0.11 in PHP 4.3.2RC1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-29 01:18 UTC] derick@php.net
Can you please try to com eup with a short script that doesn't depend on anything else but the script (and of course an image) so that we can copy and paste it from this bugreport? Please provide an URL to the image as you obviously can not paste it onto this bugreport.

Derick
 [2003-04-29 01:47 UTC] len at abcda dot com
Here's the image i used to get when i tried using built-in GD library in PHP 4.3.1:
http://www.abcda.com/upload/thumb-lyonchik22.jpg1045676715.jpg


Same generated thumbnail, but with PHP 4.3.2RC1 built-in 2.0.11 GD:
http://www.abcda.com/upload/thumb-lyonchik22.jpg1045677288.jpg

And i just downloaded the new PHP 4.3.2RC2 and compiled it with the same options i used when i compiled PHP 4.3.2RC1, and here's what i get when it generates a thumbnail:
http://www.abcda.com/upload/thumb-lyonchik22.jpg1051596060.jpg

the function i posted here does everything in the script.
I just upload an image and call this function and it uploads the selected image and generates a thumbnail from it.
 [2003-04-29 02:44 UTC] pajoye@php.net
Hello,

Can you provide a shorter script with only the resize functions, with the original image used.

This script is not complete and will not help a lot to debug.

Can you try imagecopyresampled instead of imagecopyresize?

You should use imagecreatetruecolor, imagecreate creates palette based image. Palette can be too small for jpeg images.

hth

pierre
 [2003-04-29 02:50 UTC] len at abcda dot com
imagecreatetruecolor() did the trick, thank you...
although imagecreate() worked fine on PHP 4.3.2RC1 with GD 2.0.11... something has still changed since then.
 [2003-04-29 03:02 UTC] pajoye@php.net
truecolor is your way :).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 10:01:32 2024 UTC