Jump to content

Odd ImageJpeg() Output


Go to solution Solved by requinix,

Recommended Posts

Hi guys, this would be my first post here as a new member :pirate: .

 

Let me start what my purpose right away, I have this piece of code trying out the ImageJpeg() function.

 


<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');

// Output the image
imagejpeg($im);

// Free up memory
imagedestroy($im);
?>

 

The site that I got the code showned the supposed right output. But mine give me this output (see the attached image).

Why is that happening? Sorry I'm new in PHP and don't know what to do. Please help me out thank you in advance.

post-143703-0-45774300-1363583133_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/275801-odd-imagejpeg-output/
Share on other sites

You have whitespace before your opening <?php tag. Since there's output your header() won't work, and if you had error settings set up appropriately in your php.ini for a development environment

error_reporting = -1
display_errors = on
you would have seen an error message telling you as much.

Sorry for the late reply and thank you for the quick response, I figured it out now it is because of whitespace. Is PHP that strict?

 

And now my problem is Permission Denied, I figured it out because of the writeprotection of the folder since what im doing right now is creating a new resize image base on the original image.

But I can't set up the folder into everyone with full control, can anyone point me out how to do this.

  • Solution

Yes, it is. Since you put the whitespace there PHP assumed you wanted it, so it dutifully outputted it, and because of how HTTP works once output has started you can't add more header()s.

 

You need to give full control for creating files to something at some point. The normal solution is to do it on the upload folder. You can change permissions if you have SSH or (in most cases) FTP access.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.