TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-13-2009, 04:04 AM   #1 (permalink)
The Visitor
 
Farmer's Avatar
 
Join Date: Dec 2008
Posts: 4
Thanks: 0
Farmer is on a distinguished road
Red face PHP GD query

I am trying to get the index color of a image but still no luck. I have 2 files.

-- image.php [GD generated image]
-- view.php [File to view the index color of image.php]

image.php

Code:
header("Content-Type: image/jpeg");

$img = imagecreate("200", "150");
$bgcolor = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$text = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));

imagejpeg($img);
imagedestroy($img)
view.php
Code:
$im = imagecreatefromjpeg('image.php');

// 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);
when i try other normal jpeg file it return values but when i try image.php file it'll not to return the value. Can you help me here.
Farmer is offline  
Reply With Quote
Old 03-14-2009, 10:24 AM   #2 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default

Now thats just an assumption. But as far as I know imagecreatefromjpeg can only retrieve files with an .jpg and .jpeg ending. Thats why theres also a imagecreatefromJPEG -> for .JPG and .JPEG files.
Now, I might lie - but I think thats where you error occurs. I guess you can't fetch "jpg's" where the image is actually created by PHP/ -> or has an .php ending. But as I said - not sure whether I talk some bullshit here, just an theory...
Sakakuchi is offline  
Reply With Quote
Old 03-15-2009, 01:32 AM   #3 (permalink)
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
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get PHP 5. to work? Newbie windows PHP guy DotNetTim Absolute Beginners 11 02-01-2013 11:02 AM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
what are all the subjects in php? sarmenhb General 7 01-21-2008 05:41 PM
php within a query CoryMathews Absolute Beginners 4 12-07-2007 03:20 PM


All times are GMT. The time now is 11:21 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design