Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To 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 August 23rd, 2004, 08:36 PM
Registered User
 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Install GD on Windows

Hi
I'm Some kind of new in this website and i don't know i'm in right track or not
but i have question and i hope i can find answer in this fourms
my question is
i have apache 1.3 3.1 and php 4.3 and mysql
and all works realy good
now i try to use gd but i can't
here is what i did
i went to php.ini in my dir c:/windows/php.ini
and i omit the ; on ;extension php_gd2.dll:
    that means i change this ;extension php_gd2.dll to this extention php_gd.dll
and the extention_dir c:\php\extensions

so i did all those and i wrote a simple code like
<html>
<body>
<?php
header ("Content-type: image/png")
$image = imagecreate(200, 200);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $black);
imagepng($image);

imagedestroy($image);
?>
</body>
</html>
and also i test that code for jpeg and still i don't get any image all i get is some sentences that i cannot read them like
"@@@y^gls;tfjuw%$@y
in my hole page

i wondering if you guys can help me
thank
 
Old August 23rd, 2004, 09:04 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Cross-post: http://p2p.wrox.com/topic.asp?TOPIC_ID=18038

rezagholi: Please do not cross-post, your message will be read.

<s>I suggest posting in a forum that has to do with what you are dealing with, perhaps one of the PHP forums. This is in no way feedback.</s>

Snib

<><
 
Old August 23rd, 2004, 09:06 PM
Registered User
 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry

 
Old August 25th, 2004, 03:40 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well, the answer to your question is pretty simple, you cannot dump binary data directly into a web document. So you actually have to create two documents to dynamically generate an image with PHP and include that image in an HTML document.

The first document must be a normal HTML document.
Code:
<html>
    <head>
    </head>
    <body>
         <img src='image_emulator.php' alt='PHP image emulator.'/>
    </body>
</html>
Then in a *second* document, write up your PHP that generates the image.
Code:
<?php
    //image_emulator.php

    header ('content-type: image/png')

    $image = imagecreate(200, 200);

    $black = imagecolorallocate($image, 0, 0, 0);

    imagefill($image, 0, 0, $black);
    imagepng($image);

    imagedestroy($image);
?>
This script does what its name implies, it emulates an image, it's just like creating a real .png file. By sending out the content-type header, the browser knows to treat the subsequent binary data as a PNG image, even though it really comes from a PHP script.

When you create this script, no whitespace can appear before the opening <?php delimiter, and no other output can come from the script, otherwise that data will get botched and the browser won't know what to do with it and you'll find yourself with a broken image.

Ever open up an image with a plain text editor?? This is what you see:
"@@@y^gls;tfjuw%$@y

That's the raw data of the image itself.

In the future you can verify the installation of PHP extenstions by running a phpinfo() script.
Code:
<?php
    phpinfo();
?>
When you install GD, a new heading appears with information specific to that extension.

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to install MySQL on D:\ having Windows 2000 ? sherbir MySQL 2 April 1st, 2015 10:05 AM
how to install ffmpeg on windows server rahulcbr PHP How-To 1 November 16th, 2008 12:25 AM
How to install PHP on Windows 2003 Server x64 edeleon68 PHP How-To 2 May 18th, 2008 01:20 AM
Install VS2005 on Windows Vista Home PremiumWindow sansircar ASP.NET 2.0 Basics 3 January 10th, 2008 11:08 AM
install php on windows 2000 server (matrix) martinwbialachowski BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 May 6th, 2004 04:42 AM





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