Jump to content

[SOLVED] Help with php GD - Creating a GD image from a page with an image extension


Some Poster55

Recommended Posts

Hi,

 

I'll try to explain this as best I can, but basically I need to create a GD image based off of a variable entered in the page's URL. I've seen a number of sites do this in the past, so I know it's possible.

 

So for example, if I were to visit http://website.com/HelloWorld/image.png - it would show an image containing the text "HelloWorld".

 

Whatever that directory name would be changed to in the URL would then be displayed on the picture. So if I changed the URL to http://website.com/ByeWorld/image.png - it would show an image containing the text "ByeWorld".

 

If I changed the URL to http://website.com/HeyWorld/image.png - it would show an image containing the text "HeyWorld" - And so on...

 

I understand how to do this using a regular php file as so:

<?php
header("Content-type: image/png");
$im = imagecreate(510, 20);
$bg = imagecolorallocate($im, 0, 0, 0);

//Get the current directory of the page
$url = $_SERVER["REQUEST_URI"];
$text = explode("/",$url);

//Write the page's current directory on the image
$textcolor = imagecolorallocate($im, 0, 0, 255);
imagestring($im, 5, 0, 0, $text[1], $textcolor);

imagepng($im);
imagedestroy($im);
?>

 

However, I'm baffled as to how this works by just using a file with a .png extension. Following in the above example, my code will work as desired from http://website.com/HelloWorld/image.php and correctly write an image with the text "HelloWorld", but what I need is for it to be at http://website.com/HelloWorld/image.png .

 

The code above is exactly what I need, it's just I need the page to have a .png extension instead of a .php extension.

 

Any ideas?

 

Thanks much in advance! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.