Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

header() causing error

Asked Modified Viewed 1,419 times
S
skpacman
S
My PHP-Fusion site: https://skpacman.live
  • Member, joined since
  • Contributed 150 posts on the community forums.
  • Started 25 threads in the forums
  • Started this discussions
asked
Member

I have a function that creates a random image via GD and saves the data to $img, then I want to output the resulting png image to the browser. i've done it this way in the past:
   ob_start();
      header( "Content-type: image/png" );
      imagepng($img,NULL,9);
      imagedestroy($img);
      $i = ob_get_clean();
   echo "<img src='data:image/png;base64," . base64_encode( $i )."'>";

But I seem to get an error that doesn't allow the page to load at all.

I tried it outside of the php-fusion environment and it works fine. Did i miss something?

Merged on Dec 09 2014 at 15:29:38:
Ah, nevermind. My brain didn't catch it until it was too late. Here's some code that actually works.
   ob_start();
   imagepng($img);
   $output = ob_get_contents();
   ob_end_clean();
   echo "<img src='data:image/png;base64,".base64_encode($output)."'>";

catch the contents, not the end. duh.
Edited by skpacman on 09-12-2014 23:29,
0 replies
There are no post found.

Labels

None yet

Statistics

  • Views 0 views
  • Posts 0 posts
  • Votes 0 votes
  • Topic users 1 member

1 participant

S
S
My PHP-Fusion site: https://skpacman.live
  • Member, joined since
  • Contributed 150 posts on the community forums.
  • Started 25 threads in the forums
  • Started this discussions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet