fopen/imagejeg error

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
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

fopen/imagejeg error

Post by Coco »

ok i just last night started my first fumbling steps into the graphics dictionary.
Problem ive come accross is that I cant output created images direct to the browser at the same time as text, it just results in a pile of garbage.
So i resort to saving the image in a precreated file, with chmod set to 777.

thing is imagejpeg is now throwing errors :/

Code: Select all

<?php
$out = fopen('test.jpg', 'wb');

Imagejpeg($im,$out,50);     //line 95

fclose($out);

ImageDestroy($im);
?>
the error given is:

Warning: imagejpeg(): Unable to open 'Resource id #3' for writing in gdtests.php on line 95

the first problem (not being able to output text with an image) is np because the end code will be wanting to save the image for later use anyway. Any ideas whats causing this error and how to solve it?
Thanks
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Imagejpeg writes directly to the file itself - i.e. you don't need to fopen anything first. Just specify the exact filename (test.jpg in this case) as the 2nd parameter for it.
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

ah ok
and it works
thanks :)

now i know why i dont entirely trust tutorials :P
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Yeah, I know what you mean :)
Although you can trust my tutorials in International PHP Magazine ;)
Post Reply