Thread: PHP GD query
View Single Post
Old 03-15-2009, 01:32 AM   #3 (permalink)
ioan1k
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

This will not work as the GD library does not run the PHP script and only tries to load the JPEG image.

An alternative to this could be the following

PHP Code:
// image.php
$img imagecreate("200""150");
$bgcolor imagecolorallocate($imgmt_rand(0255), mt_rand(0255), mt_rand(0255));
$text imagecolorallocate($imgmt_rand(0255), mt_rand(0255), mt_rand(0255));

// Save image 
imagejpeg($img'testimage.jpeg');
imagedestroy($img);

// redirect to view
header('location: view.php'); 
PHP Code:
// view.php
// Redirect if there is no image
if (!file_exists('testimage.jpeg'))
{
    require(
'image.php');
}

// Load Image
$im imagecreatefromjpeg('testimage.jpeg');

// Delete image
@unlink('testimage.jpeg');
// get a color
$start_x 20;
$start_y 20;
$color_index imagecolorat($im$start_x$start_y);

// make it human readable
$color_tran imagecolorsforindex($im$color_index);

print_r($color_tran); 
Tested and works
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote