5 Replies - 364 Views - Last Post: 07 March 2011 - 03:33 AM Rate Topic: -----

#1 IrisBlaze  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-August 10

Cannot create image

Posted 07 March 2011 - 12:45 AM

Hello, so i was trying to create an image when i tested the page on chrome, nothing happened, on firefox it gave me the error "the image blahblahblah' cannot be displayed because it contains errors, i thought my coding was the problem, so i went to php site and grabbed the simplest example i had:

$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);



and put it in my page, still same errors and here's the phpinfo output about GD: in the attachment.

now how can i debug this situation? btw when i remove the header content type, i get the JPEG header (in text) and a bunch of weird characters, any help? :)

Edit: i tried to save the image into a file and it's saved correctly, so why it isn't displaying in any browser?

This post has been edited by IrisBlaze: 07 March 2011 - 12:47 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Cannot create image

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3039
  • View blog
  • Posts: 4,554
  • Joined: 08-June 10

Re: Cannot create image

Posted 07 March 2011 - 01:48 AM

If you add this to the top of the page, to enable all error reporting:
ini_set('display_errors', true);
ini_set('html_errors', false); // So they won't be HTML formatted.
error_reporting(E_ALL + E_NOTICE);



And then run the code using a Cotnent-type: text/plain header instead of the image content-type, what exactly is printed? Are there any error messages in the output that this generates?

Have you made sure there are no white-spaces before the opening PHP tag? (Easy to overlook.)
Was This Post Helpful? 1
  • +
  • -

#3 IrisBlaze  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-August 10

Re: Cannot create image

Posted 07 March 2011 - 02:29 AM

View PostAtli, on 07 March 2011 - 01:48 AM, said:

If you add this to the top of the page, to enable all error reporting:
ini_set('display_errors', true);
ini_set('html_errors', false); // So they won't be HTML formatted.
error_reporting(E_ALL + E_NOTICE);



And then run the code using a Cotnent-type: text/plain header instead of the image content-type, what exactly is printed? Are there any error messages in the output that this generates?

Have you made sure there are no white-spaces before the opening PHP tag? (Easy to overlook.)


no errors, it displays the binary data of the image, as i said i tried to save the image in a file by switching
imagejpeg($im);

to

imagejpeg($im, 'filename.jpg');


and it saved a handsome image, the problem is why no browser wants to display my image directly in the browser or by using
<img src="thatfile.php" alt="some alt" />


it's just shows a broken image
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3039
  • View blog
  • Posts: 4,554
  • Joined: 08-June 10

Re: Cannot create image

Posted 07 March 2011 - 02:45 AM

Ok. There is something else being printed, though, otherwise the browsers would show the image.
Only other alternative I can think of is some odd server problem. Perhaps a compression bug. (Unlikely, though.)

Could you post the whole code here? In fact, it may help if you posted the file itself here. Things like Unicode BOM chars commonly cause problems like this, which would not be immediately apparent in editors that read Unicode files correctly.
Was This Post Helpful? 2
  • +
  • -

#5 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Cannot create image

Posted 07 March 2011 - 03:29 AM

You code works just fine on chrome and firefox both.
Was This Post Helpful? 0
  • +
  • -

#6 IrisBlaze  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-August 10

Re: Cannot create image

Posted 07 March 2011 - 03:33 AM

View PostAtli, on 07 March 2011 - 02:45 AM, said:

Ok. There is something else being printed, though, otherwise the browsers would show the image.
Only other alternative I can think of is some odd server problem. Perhaps a compression bug. (Unlikely, though.)

Could you post the whole code here? In fact, it may help if you posted the file itself here. Things like Unicode BOM chars commonly cause problems like this, which would not be immediately apparent in editors that read Unicode files correctly.

i gave you the whole code :P anyway gonna try the Unicode BOM thingy coz i think that's the problem, let me try

Edit, thank you so much that's what was the problem :)

View Postchinchang, on 07 March 2011 - 03:29 AM, said:

You code works just fine on chrome and firefox both.


I know that, i am wondering why isn't it showing the image :)

This post has been edited by IrisBlaze: 07 March 2011 - 03:35 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1