Well, I have an image ans I want to write a text on it. The issue is, it is saying,
image cannot be displayed because it contains errors. Refer to the screenshot below as attachment.
to the top and comment out the header for the content type, then access the image directly. One or more of these are throwing an error, suspicion goes to imagecreatefromjpeg failing, and since you have no other error handling the rest would all throw errors too.
Yes that would be the text of the image binary. Errors would show up first though, does it show errors? If not, check the source and verify that there is no preceding whitespace. If there is, then you have a space before the <?php in the script.
Whitespace = any whitespace character. If you contain output with whitespace it will corrupt the image binary.
That image is useless as it contains no line numbers in it. I mean check the textual output of the image to see if there is preceding whitespace before the imagetype binary as well as any other errors.
Fou-Lu is not looking for part of the code on your backend. He is pointing at whitespace BEFORE you set the header. EG if your full code looks like this:
it will not work, as you have whitespace outputted before you set your header. As your screenshot only centers around your part of the code, we can not judge whether this is the only code on that page, or whether there is more somewhere which could be influential.
Look at all the whitespace there. Who knows what's above that.
You cannot embed a GD script with the output type as an image into a textual output script. The script's entire purpose is to generate and represent itself as an image. That should look more like this:
Ok, I cut the whole script and paste it above the doctype. Still not work.
Read again. You CANNOT embed a script representing itself as an image in a textual output script. You MUST give it a script of its own. You can have one and only one content type on an output header.
Facepalm to myself. I need a weed I think. My head is too heavy to understand thing. So, if I copy and paste the script in another page then INCLUDE the page to the one, will it work?