Upgraded to GD 2.0: Now thumbnail pics are 16 colors??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Upgraded to GD 2.0: Now thumbnail pics are 16 colors??

Post by camarosource »

We had a PHP script made for us which holds a database of vehicle information. A file "thumbnail.php" script is a program that was written that displays the full sized image as a resized image on the browser screen.

Our server recently changed to PHP 4.3.1 and GD 2.X and now the thumbnail.php script is having problems.

The thumbnail.php images (jpg) that display are displayed as 16 colors and very much washed out.

From reading up on forums, particularily:

http://forum.rackshack.net/showthread.p ... yresampled

It seems we need to add a new function "imagecreatetruecolor()" to the small thumbnail.php script.

Personally I don't know PHP and so I need someone here who could help implement this function to my thumbnail.php script:

[THUMBNAIL.PHP]

(removed opening php tag)

isset($_GET['img']) or die();

$loc_full = $_SERVER['DOCUMENT_ROOT'].'/new_site/camaro_info_db/images/'.$_GET['img'];

if (preg_match('/\.gif$/i', $loc_full)) {
header('Content-type: image/gif');
readfile($loc_full);
die();
}

header('Content-type: image/jpeg');

//get original image's size
list($full_x, $full_y) = getimagesize($loc_full);

//get thumbnail's size
$thumb_x = isset($_GET['x']) ? $_GET['x'] : 120;
$thumb_y = isset($_GET['y']) ? $_GET['y'] : 90;

//create an image object from the original, and create a new blank object
$full = imagecreatefromjpeg($loc_full);
$thumb = imagecreate($thumb_x, $thumb_y);

//copy and resize the original into $thumb
imagecopyresampled($thumb, $full, 0, 0, 0, 0, $thumb_x, $thumb_y, $full_x, $full_y);

imagejpeg($thumb, '', 80);

(removed closing php tag)

Thanks
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

the script you have there uses a proprietary GD2+ function - namely imagecopyresampled (imagecopyresized is the < 2 equivalent)

as you figured - changing imagecreate to imagecreatetruecolor should effect a functionality you want - though why it's gone 16 colour (not 256) now and not before is a mystery.

If you really want to do a bit of bullet biting - I wrote a GD2+ class that handles everything you want - also does bevel, drop-shadow, motion-blur, overlay, frame etc etc

available from http://www.phpclasses.org/browse.html/package/1007.html - don't click the online demo though as my server is having snags atm.

One thing to note: since GD1.6.4 gif support has been pretty much dropped totally due to patenting restrictions on the LZW comperssion algorythm imposed by unisys
Post Reply