Page 1 of 1

[SOLVED] Using Image fns in a class

Posted: Mon Jun 14, 2004 11:44 am
by anjanesh
Hello

All the image functions are working ok in my scripts so I decided to use classes for these.
I have a file which contains the GenerateImage class.
The class has - function Display($filename)

Code: Select all

function Display($filename)
 {
 .
 .
 .
 .and finally
 imagejpeg($tmp_img);
 // I tried returning imagejpeg($tmp_img),$tmp_img
 }
In the calling script I have :

Code: Select all

$AlbumThumb=new GenerateImage("somearg");
I tried 3 ways of displaying the image :
1>

Code: Select all

print('<TR><TD ALIGN=center><IMG SRC='.$AlbumThumb->Display($rowї'url']).'></TD></TR>');
2>

Code: Select all

print('<TR><TD ALIGN=center>'.$AlbumThumb->Display($rowї'url']).'</TD></TR>');
3>

Code: Select all

$AlbumThumb->Display($rowї'url']);
Neither is displaying the image. It is displaying the content of the image file like this (first & last few chars shown here)

ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC
........
ÿñïþµTÝŒ‚y|ç ·ÆsERÿÙ


I also tried adding header("Content-type: image/jpeg"); in the class/file.

Any idea how to get this working in class ?

Thanks

Posted: Mon Jun 14, 2004 11:56 am
by feyd
imagejpeg.. and all the other ones like it dump binary image data.. you need to either write a script that handles image output i.e.

Code: Select all

<img src="something.php?id=2123244">
or, you need to tell the image function to write the file to the system for use.. then echo the name of the file you save it as... [php_man]imagejpeg[/php_man] for details on the arguments to pass...

Posted: Mon Jun 14, 2004 12:03 pm
by anjanesh
Yes. I understood that part but writing to the file to the system stores it in the server's space after which we need to call that file. I thought I could store it in the client's cache.

Posted: Mon Jun 14, 2004 12:10 pm
by feyd
an image stream cannot be passed while in an html stream, or you will get the garbage you saw....

Posted: Mon Jun 14, 2004 12:19 pm
by anjanesh
Thanks very much. I had to include a third file for solving my prob. The class is in a separate file.
SOLVED