Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2004, 11:14 PM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Working with ImageCreate in PHP?

I was downloaded the GD library but I can't config to PHP.ini for Apache run the lib gd.dll. I want to use the ImageCreate function, how can I do?
Thank for your help!
 
Old February 14th, 2004, 01:04 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Jwang,

First let's verify your installation of gd in PHP.
For Windows, check the following:

1.) Be sure that you have downloaded and installed the Windows zip package from http://www.php.net/downloads.php which includes many of the extra PHP extensions, including gd, if you used the Windows Installer extra extensions were not included, no worries though, just download the above package and move all the extra stuff in it to your PHP directory. But if you're running PHP as an Apache module you've likely already downloaded this package... check the following php.ini settings...

2.) Open php.ini (C:\Windows\php.ini) on a windows system.
Uncomment the line..
extension=php_gd2.dll

Modify the following line to point to the extensions directory.
extension_dir = "C:\PHP\extensions\"

For Linux:
See the gd documentation available at http://www.php.net/gd for configuration options.

Restart Apache and run the following script:
<?php
phpinfo();
?>

If you see the gd heading followed by a list of gd configurations, then the install was successful.

<?php
    header("content-type: image/png");
    $im = @ImageCreate(150, 150) or die("Could not create image");
    $bg_color = ImageColorAllocate($im, 240, 240, 240);
    $text_color = ImageColorAllocate($im, 0, 0, 0);
    ImageRectangle($im, 40, 40, 140, 140, $text_color);
    ImageString($im, 3, 5, 5, "Square", $text_color);
    ImagePng($im);
    ImageDestroy($im);
?>

This code looks ok to me. What errors or warnings do you see when you run it? (Ran independently of anything else, e.g. not from within the 'src' attribute of an img tag.)

Also it doesn't make sense to suppress errors in an experimental script, remove the '@' error supression operator from the call to ImageCreate().

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old February 14th, 2004, 01:14 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Also Jwang,

I just noticed you posted a test URL... http://www.phucuong.net/testPNG.php...

Run this modified copy...
Image output doesn't happen until the imagepng function is called, so in order to see errors issued previous to that call move the call to header to happen just before the imagepng function call. The reason for this is you are changing the content of your PHP script to become an image, so the browser will treat it like one.. which more or less means your errors are lost to oblivion.

Also leave off the error supression operator that I already mentioned and this should show you some errors. Also be sure that you are reporting errors while you are developing, set this php.ini directive to display all errors..

error_reporting = E_ALL

This is best done in a development environment where you are the only person that will see the errors, whereas on your live server this may pose a security risk and well simply be unprofessional.

<?php
    $im = ImageCreate(150, 150) or die("Could not create image");
    $bg_color = ImageColorAllocate($im, 240, 240, 240);
    $text_color = ImageColorAllocate($im, 0, 0, 0);
    ImageRectangle($im, 40, 40, 140, 140, $text_color);
    ImageString($im, 3, 5, 5, "Square", $text_color);

    header("content-type: image/png");
    ImagePng($im);
    ImageDestroy($im);
?>

hth,
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old February 24th, 2004, 05:02 AM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Give me an example, please and I can test it on your url site?
Thanks a lot!

 
Old February 24th, 2004, 01:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The example is given to you in source code. You should be able to run it on your own site if you have PHP with GD installed properly.

You can verify that GD is installed by looking for it in a <?php phpinfo(); ?> script.


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
working with php pritz Beginning PHP 2 September 11th, 2005 02:28 PM
php 5 not working with mysql fromheavenz PHP Databases 0 August 30th, 2005 12:31 PM
please php is not working perfectly well p2ptolu Beginning PHP 1 March 27th, 2005 09:56 AM
ASP not working after installing PHP taliesin Classic ASP Professional 1 July 4th, 2003 11:41 AM
ASP not working after installing PHP taliesin Classic ASP Basics 0 June 27th, 2003 12:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.