|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-05-15 18:21 UTC] nicolaasuni at tiscali dot it
Using php_gd2.dll and paletted image the method imagecopyresized return a monochromatic rectangle and the method imagecopyresampled return a blank rectangle. These methods works fine only with true color images. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 19:00:02 2025 UTC |
This is an examle script that produce the error explained in my previous message. For this test I've used a 1x50 pixel PNG image with 50 different paletted colours. <?php $src_img_file_name = "source_image.png"; // filename of source file $dest_img_width = 150; // destination image width $dest_img_height = 50; // destination image height $src_img_width = 1; // source image width $src_img_height = 50; // source image height // create a blank image $dest_img = @ImageCreate($dest_img_width, $dest_img_height) or die ("Cannot Initialize new GD image stream"); // create image from source image file $src_img = imagecreatefrompng($src_img_file_name); // copy source image to destination image resampled imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $dest_img_width, $dest_img_height, $src_img_width, $src_img_height); // copy source image to destination image resized //imagecopyresized($dest_img, $src_img, 0, 0, 0, 0, $dest_img_width, $dest_img_height, $src_img_width, $src_img_height); //send image to output header("Content-type: image/png"); ImagePng($dest_img); ?>I experience the same problem on the production system. For development I use rh8, php4.2.2 and GDlib I guess version 1.8.x As production rh7, php4.3.1 and the bundled GDlib 2.0 compatible I am not sure but I think the problem reside in the GD 2.0 lib. The following proble occour ONLY with palet image. Basically my script create a button starting form a basic png and adding the text. The script work fine in devel but in production has problem. When I try to resize the basic button for longer text it seems that both imagecopyresized and imagecopyresampled does not copy the image. In the example after the imagecopyresized there is a imagecolorstotal, it return correcly the number of colors in the image (if you put it before it return 1, the background). So it seems that the palet is setted correclty but not the image. If I create a trucolor image instead of a palet image it works but I do not have transparency. Here follow an example code: <?php /* The following script is only an example, the original one is a bit more complex it is made only to reproduce the problem. */ //the start button.png is a palet image with tranpsarency with around 16 colors $im = imagecreatefrompng("/path/to/base/button.png"); /* $textwidth = calculation for the new width based on the text; */ $dst_img = imagecreate($textwidth, imagesy($im)); $bkgc = imagecolorallocate ($dst_img, 0, 0, 255); /* imagecopyresized( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH ) */ imagecopyresized($dst_img, $im, 0, 0, 0, 0, $textwidth, imagesy($im), 1, imagesy($im)); //echo "<p>Total Color: " . imagecolorstotal ($dst_img) ."</p>"; imagecolortransparent($dst_img, $bkgc); header("Content-type: image/png"); Imagepng($dst_img); ?>