Page 1 of 1

fopen/imagejeg error

Posted: Sat May 22, 2004 5:41 am
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

Posted: Sat May 22, 2004 5:45 am
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.

Posted: Sat May 22, 2004 6:55 am
by Coco
ah ok
and it works
thanks :)

now i know why i dont entirely trust tutorials :P

Posted: Sat May 22, 2004 7:00 am
by launchcode
Yeah, I know what you mean :)
Although you can trust my tutorials in International PHP Magazine ;)