Problem with images?

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
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Problem with images?

Post by InternetX »

Hello...
PHP is showing me errors, but I don't know why.
The errors:

Warning: imagejpeg(): supplied argument is not a valid Image resource in h:\wampp1\htdocs\profile.php on line 4
Warning: imagedestroy(): supplied argument is not a valid Image resource in h:\wampp1\htdocs\profile.php on line 5

And the source code:

<?php
IF($pic == "create" && isset($uid) && isset($pid) && isset($pno)) {
$image = @ImageCreateFromJPEG("gallery/".$uid.".".$pid.".".$pno.".jpg");
ImageJpeg($image);
ImageDestroy($image);
exit;
}
?>

What's wrong with my PHP or with my Script?
I don't find any errors :(
Please help me :(
Judas
Forum Commoner
Posts: 67
Joined: Tue Jun 10, 2003 3:34 pm
Location: Netherlands

Post by Judas »

this is a "path error" check the image path before processing you should remove the @ in front of "@ImageCreateFromJPEG("gallery/".$uid.".".$pid.".".$pno.".jpg");" then check the path in the warning msg

b_t_w a beter way for naming is a underscore "_" inplace of a dot "."
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Post by InternetX »

I already checked the path... the file exists...
But the script don't load this file :(
I will test it with "_" instead of "."

Thanks...
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Post by InternetX »

The script doesn't work because in the ImageCreateFromJPEG() command
is the file not in the same directory ("gallery/")
If the file is in the same dir the script works...
Can I correct or bypass this?
Judas
Forum Commoner
Posts: 67
Joined: Tue Jun 10, 2003 3:34 pm
Location: Netherlands

Post by Judas »

the imageCreate must read a existing file

i thought, for output u can use ImageJpeg($image,"path_to_write_image_to");
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

use a root path to define the imagecreate

ImageCreateFromJPEG('/home/site/pub/gallery/' .$args. '.jpg');

As you are not doing anything to the image, why not just run a readfile and output it directly (sure saves the overhead of converting it to .gd format then back to jpeg - about 10 times the process)
I assume you are calling that script within an img src tag, so you'd also need a header output.

if(file_exists('/home/site/pub/' .$args. '.jpg');
{
header("Content-type: image/jpeg");
readfile('/home/site/pub/' .$args. '.jpg');
}
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Post by InternetX »

Ok, Thanks :)
Post Reply