Current location: Hot Scripts Forums » Programming Languages » PHP » GD Library in PHP


GD Library in PHP

Reply
  #1 (permalink)  
Old 03-21-09, 08:23 AM
henllys henllys is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
GD Library in PHP

Hi

I am having trouble getting the php_gd2.dll to work on a windows, apache platform.

The extension is being loaded correctly as it appears in the php.info file as enabled.

I have called the php file with the GD PHP code from another PHP file using the img src tag set into HTML but I am just getting a broken link symbol.

If I try to view the GD PHP file in the browser I either get random text or nothing.

Just wondering what I am doing wrong.

Cheers

Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-21-09, 04:44 PM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Are you setting the header inside the php file? For it to work, you have to tell the browser that the file is an image.

PHP Code:

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

That's if you're making a png file, it's be image/jpeg for jpegs and image/gif for gifs etc.
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-22-09, 07:39 AM
henllys henllys is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Hi thanks for your reply , yes the header is set correctly, there are no errors being generated.

I have checked the php info page and all the right gd library extensions are enabled.

I am not sure what else to check.

Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-22-09, 08:20 AM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Could you post the code that is on the php file at all?
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-22-09, 03:00 PM
henllys henllys is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks again for sticking with this, I have pasted the code below which sits in a .php file and is nested inside the body tags of XHTML. With the php.ini file I didnt really have to do anything because the relevant extension was already enabled as it is the latest version of php.
I have tried viewing this code in the browser using dreamweaver as a stand alone and also I have called this file from another php web page with the same results.

<?php

header("Content-type: image/png");
$im = imagecreate (300, 300);
$white=imagecolorallocate($im,255,255,255);
$blue=imagecolorallocate($im, 0,0,255);

imagestring($im, 5,0,0, "I Love GDLib ", $blue);
imagerectangle($im, 50, 50, 100, 100, $blue);
?>

Cheers
Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 03-22-09, 03:38 PM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
You dont add html to the php for this

You just have that code in the php file only, nothing more. Then you have to echo the $im I believe
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 03-25-09, 07:04 PM
Thyrosis's Avatar
Thyrosis Thyrosis is offline
Newbie Coder
 
Join Date: Dec 2008
Location: South UK
Posts: 66
Thanks: 2
Thanked 0 Times in 0 Posts
I think you've forgotten to output the image. Try adding this to your code:

PHP Code:

ImagePNG($im);

ImageDestroy($im); 
I think that should solve it

---------

If that doesn't work, save your code plus mine in a seperate file, and call it from your HTML file as an image, so like this:

PHP Code:

// createImage.php

header("Content-type: image/png");
$im imagecreate (300300);
$white=imagecolorallocate($im,255,255,255);
$blue=imagecolorallocate($im0,0,255);

imagestring($im5,0,0"I Love GDLib "$blue);
imagerectangle($im5050100100$blue);

ImagePNG($im);
ImageDestroy($im); 
HTML Code:
<img src="createImage.php" />
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 03-26-09, 06:11 PM
henllys henllys is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
GD Library Broken Image Link

Hi Thanks for your reply, I have tried your code and there is some progress. However I now only get a broken image link which suggests that the code wants to display the image but either it can't find it or something is stopping it.

I was wondering if it is something to do with the browser security??


Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP or PHP which is better? nepala The Lounge 9 07-14-10 06:48 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
how to use onclick in php coolcoder HTML/XHTML/XML 2 05-31-06 01:40 PM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 04:06 AM
Creating Dynamic Images With PHP cdphreaker PHP 0 02-20-05 04:26 PM


All times are GMT -5. The time now is 09:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.