Click to See Complete Forum and Search --> : image not being rendered


sridhar_423
08-24-2006, 07:57 AM
Hi all,
I'm trying to display an image which is uploaded.
here is the code..

$tmp_file_name = $_FILES["file1"]["tmp_name"];
$xct_file_name = $_FILES["file1"]["name"];

@is_uploaded_file($tmp_file_name) or die("Cannot Upload file");
list($src_width,$src_height,$image_type,$html_attributes) = getimagesize($tmp_file_name);

@$image_type==2 or die("Pls Upload only JPG's");
$percentage = $_POST["percent"];

if($percentage > 0){
$dest_width = round($src_width*$percentage/100);
$dest_height = round($src_height*$percentage/100);
}else{
$dest_width = 100;
$dest_height = 100;
}

$tmp_img = @imagecreatetruecolor($dest_width,$dest_height) or die("Can't create a tmp Image");
$tmp_img = @imagecopyresampled($tmp_img,$tmp_file_name,0,0,0,0,$dest_width,$dest_height,$src_width,$src_height) or die("encountered problem in shrinking");
header("Content-Type:image/jpeg");
imagejpeg($tmp_img);

die();

nothing is being displayed. I couldnot find out whats wrong in here. I've just started learning how to stream images using PHP. cany anyone tell me where it is going wrong.

I know that my next question is going to make you laugh like anything.. . .but it has become a big sorrow for me.. what is the full form of "GD" in GD library..
I'm using Version 4.1.3. I dont know how to check whether GD is installed or something like that :(

Thanks,
Sridhar

bokeh
08-24-2006, 09:51 AM
The second argument to imagecopyresampled is a resource, not a filename.

LiLcRaZyFuZzY
08-24-2006, 09:55 AM
you should not silence function warning/errors when writing new code (@)

sridhar_423
08-24-2006, 11:54 PM
Hi Bokeh,
Thanks for the response. I made the changes as you have suggested.

$f_rsr=fopen($tmp_file_name,"r");
/*$tmp_img = imagecreatetruecolor($dest_width,$dest_height);
$tmp_img = imagecopyresampled($tmp_img,$f_rsr,0,0,0,0,$dest_width,$dest_height,$src_width,$src_height);*/

header("Content-Type:image/jpeg");
//imagejpeg($tmp_img);
fpassthru($f_rsr);

die();
works .. but without shrink.
when used the original posted code with $f_rsr defined, its giving a fatal error saying "Fatal error: Call to undefined function: imagecreatetruecolor()" which means I need to do something abt this "GD" Library.

With PHP 4.0.6 through 4.1.x this function always exists if the GD module is loaded, but calling it without GD2 being installed PHP will issue a fatal error and exit. With PHP 4.2.x this behaviour is different in issuing a warning instead of an error. Other versions only define this function, if the correct GD version is installed.

I couldnot figre out how and what I should do about this "GD" library.
Can anyone throw some light on this or guide me for finding a tutorial for this.

Lil,
I removed the "@"s.

Thanks,
Sridhar

sridhar_423
08-25-2006, 01:55 AM
GD Library - "GIF Draw" Library
Go thru this link.. You'll find some useful information.
http://www.boutell.com/gd/faq.html

The OS tat is use is Solaris .. not Windows.
As per my understanding after going thru link, I'll not be able to use the GD Library as the OS is not windows. isn't it?? :(

Thanks,
Sridhar

bokeh
08-25-2006, 04:22 AM
$var = imagecreatefromstring(file_get_contents($_FILES["file1"]["tmp_name"]));Use your original code with the return from above code as the second argument to imagecopyresampled(). See how you get on... And recommended LilCrazyFuzzy remove any "@" from your code.

sridhar_423
08-25-2006, 05:02 AM
Hi Bokeh,
Thanks for the reposnse.

Here, the problem tat I'm facing is not with "imagecopyresampled" but with any function tat is making use of gd. Here the code is failing at "imagecreatetruecolor" itslef.

The function gd_info() itself is failing.A fatal error is being displayed. So, what I inferred is, I dont have gd installed.