Jump to content

Recommended Posts

I need urgent help - have been out of webworld for a few years and now has to build an extensive dynamic webpage for my company. I have php5.1.45, Apache 2.2 on a windows 7 pro. Php is working fine, but when I try to use the gd library to create an image, only jibberish comes out. On the php.ini everything is enabled, but it just doesn't work.

Geytjie

I have tried several different examples (to see if it was just me being stupid, which is quite possible). The last one:

<body>

<?php

try{

// define procedural function

function displayTextOnImage($text='This is a sample text

string'){

if(!$text){

throw new Exception('Invalid text string');

}

if(!$image=imagecreate(300,200)){

throw new Exception('Error creating blank image');

}

// create background color for image

$backColor=imagecolorallocate($image,0,0,255);

// create text color

if(!$textColor=imagecolorallocate($image,255,255,255)){

throw new Exception('Error creating text color');

}

// include text string into image stream

if(!imagestring($image,5,10,90,$text,$textColor)){

throw new Exception('Error creating image text');

}

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

// display image

imagepng($image);

// free up memory

imagedestroy($image);

}

// display image on the browser

displayTextOnImage('This text was created with GD.');

}

catch(Exception $e){

echo $e->getMessage();

exit();

}

 

 

?>

<body>

<?php

try{

....

 

You cannot output an image directly on a HTML page. You must use a HTML <img ...> tag for each image on a HTML page. The browser then fetches the image and displays it on the page. The URL that is in the src="URL_that_results_in_an_image_being_output" attribute must be to a .php file that outputs the Content-type header followed by the image data.

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.