aNubies Posted March 18, 2013 Share Posted March 18, 2013 Hi guys, this would be my first post here as a new member . 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. Quote Link to comment https://forums.phpfreaks.com/topic/275801-odd-imagejpeg-output/ Share on other sites More sharing options...
requinix Posted March 18, 2013 Share Posted March 18, 2013 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 = onyou would have seen an error message telling you as much. Quote Link to comment https://forums.phpfreaks.com/topic/275801-odd-imagejpeg-output/#findComment-1419252 Share on other sites More sharing options...
aNubies Posted March 18, 2013 Author Share Posted March 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275801-odd-imagejpeg-output/#findComment-1419258 Share on other sites More sharing options...
Solution requinix Posted March 18, 2013 Solution Share Posted March 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275801-odd-imagejpeg-output/#findComment-1419263 Share on other sites More sharing options...
aNubies Posted March 18, 2013 Author Share Posted March 18, 2013 Well that's the easiest thing though, I'm gonna create a folder that will served for images only and permitted with a full control. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/275801-odd-imagejpeg-output/#findComment-1419267 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.