Jump to content

[SOLVED] Need Help Getting ImageCreate () to work


zh3n

Recommended Posts

Hello. I am trying to use the ImageCreate() function to create some graphs on a website. It's not working. I was wondering if anyone could help me figure out why this wouldnt work?

 

I am using this test code:

 

<?php

$im = @ ImageCreate ( 150, 100)

    or die ( "Cannot create a new GD image.");

$background_color  = ImageColorAllocate  ($im, 255,  255, 255);

$text_color  = ImageColorAllocate  ($im, 233,  14, 91);

ImageString  ($im, 1,  5, 5,  "A Simple Text String", $text_color );

header ("Content-type: image/png");

ImagePng ($im);

?>

 

It works on my personal server, but it does not work on my client's server. (which i do not have admin access to, and the server admin does not want to help me out) Error messages are turned off, so I don't know exactly whats happening. It doesn't display an image on the page, just the URL of the php file the code was in. Also, as the page title, it says "info.php (Image)". It should say "info.php (PNG Image, 150x100  pixels)"

 

The server admin tells me PHP and GD are installed and according to phpinfo():

 

PHP Version 4.4.2

Apache Version    Apache/2.0.48 (Unix) mod_fastcgi/2.4.2 PHP/4.4.2 mod_ssl/2.0.48 OpenSSL/0.9.6b

GD Support    enabled

GD Version    bundled (2.0.28 compatible)

 

Could anybody help me out here and give me some advice on what is going wrong? Does apache have to be configured correctly to allow PNG extensions or something?

 

Thanks a bunch!!!!!

Link to comment
Share on other sites

Error messages are turned off

 

So turn them on....

 

<?php

  error_reporting(E_ALL) ; ini_set('display_errors','1');

  $im = ImageCreate(150, 100);
  $background_color  = ImageColorAllocate  ($im, 255,  255, 255);
  $text_color  = ImageColorAllocate  ($im, 233,  14, 91);
  ImageString  ($im, 1,  5, 5,  "A Simple Text String", $text_color );
  header ("Content-type: image/png");
  ImagePng ($im);

?>

Link to comment
Share on other sites

Ah thanks. I tried it again and got:

 

<b>Fatal error</b>:  imagepng(): gd-png:  fatal libpng error: Incompatible libpng version in application and library

in <b>/domains/HaysGroundwater/welldata/info.php</b> on line <b>11</b><br />

 

But the good news is that I switched it out with gif instead of png and the code seems to work ok now. Thanks d00d!

 

 

Link to comment
Share on other sites

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.