Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Image from String: imagecreatefromstring

Status
Not open for further replies.

gwinn7

Programmer
Feb 10, 2001
1,004
US
What I am trying to accomplish is the first step in taking an image from a file and storing it in PostgreSQL.

The first part of this project is to be able to load the file into a string and use the "imagecreatefromfunction" to display the picture. That function ensures that I have loaded the picture and it is displayable.

My problem is that this function is outputting nothing. No error, nothing. The code does process, that I know. Does anyone know what I am doing wrong?

<?
$filename = &quot;Sample.jpg&quot;;
$fp = fopen($filename, &quot;r&quot;);

while(!feof($fp))
{
$data = $data . fread($fp, 1);
}

fclose($fp);

imagecreatefromstring($data);

?>

The next step will be to use the PostgreSQL functions to write the string to the large object.

Gary
gwinn7
A+, Network+
 
You're creating the image but never send the output to the browser...

try this:
Code:
<?
 $filename = &quot;Sample.jpg&quot;;
 $fp = fopen($filename, &quot;r&quot;);

 while(!feof($fp))
 {
    $data = $data . fread($fp, 1);
 }

 fclose($fp);
 $new_im = imagecreatefromstring($data)
 Header(&quot;Content-Type: image/jpeg&quot;);
 Header(&quot;Content-Description: PHP Generated Image&quot;);
 Imagejpeg($new_im, &quot;MyNewPic.jpg&quot;, 100);
?>
[code]
I have this working in script I wrote a while back - lemme know if you have any problems! -gerrygerry
 Go To [URL unfurl="true"]http://quickfreewebsite.com![/URL]
 
Interesting. I will give it a try and follow-up.

Gary
gwinn7
 
It worked! Thanks.

The primary problem was missing the &quot;Header&quot; functions. However, the only way the &quot;imagejpeg&quot; function worked was by removing the other parameters. Whats up with that?

Here is your sample...

Imagejpeg($new_im, &quot;MyNewPic.jpg&quot;, 100);

This did not work for me. I don't know why. When I removed the parameters, it worked.

Imagejpeg($new_im);

If you can explain why the sample would not work but this did, I would be interested in your response.

Thanks again, gerrygerry!

Gary
gwinn7
A+, Network+

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top