Jump to content

Writing Text On PNG


N-Bomb(Nerd)

Recommended Posts

I have a php script I've made that creates a png image with stats on it that gets updated. However the forum I'm trying to use this in blocks the keyword ".php" within its image tags, therefore I couldn't use my script that I've made. I've seen people get around this though, but I'm not sure exactly how they did this.

 

So pretty much I need to figure out a way to turn:

http://www.SomeSite.Com/Image.php

 

into something like :

http://www.SomeSite.Com/Image.png

 

but yet still have my script used for the .png image. I know this may seem confusing, if you need me to try and explain better please let me know.

 

Thanks,

Link to comment
Share on other sites

You should be able to use

 

AddType application/x-httpd-php .png

 

in your .htaccess file on your server that hosts the image

 

I'm not quite sure what you mean  ???

 

Here's my code (image.php):

<?
$image = imagecreate(125, 125);
imagecolorallocatealpha($image, 0, 0, 0, 127);
$Color = imagecolorallocate($image, 32, 101, 138);
imagestring($image, 2, 1, 0,  'This is my signature.', $Color);
Header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

 

Now by going to /image.php on my website you can see the image it creates. However is there an .htaccess or php hack I can use so that I'm able to use something like "/image.png" for a signature on a forum instead of "/image.php" because the keyword ".php" is blocked.

 

This image is updated like every few minutes with new stats btw in case you didn't know.

Link to comment
Share on other sites

Yes, I am aware that you are making a dynamic sig.  You rename the image to image.png and put the entry I provided above in your .htaccess file.  It will then parse the .png as PHP.

 

I tried renaming the php file to image.png and using that .htaccess file and this is the output I got:

Multiple Choices

The document name you requested (/sig/image.png) could not be found on this server. However, we found documents with names similar to the one you requested.

 

Available documents:

 

    * /sig/image.php (common basename)

 

Then I would click the link "/sig/image.php" and it would take me to a different page that reads this:

 

The document name you requested (/sig/image.php) could not be found on this server. However, we found documents with names similar to the one you requested.

 

Available documents:

 

    * /sig/image.png (common basename)

 

Please consider informing the owner of the referring page about the broken link.

Link to comment
Share on other sites

Sounds like you are pointing to the wrong path.. file not found means just that.

 

Yeah I think I did mess up the path, but I just corrected the path problem. Now when I go to the url using the .png extention it wants me to download the file. I did in fact download the png image to look at it and it said no preview was available. So I tried to use my link with the .png extention on a forum to see if it worked there and no image came up.

 

Before I changed the file to .png I checked it once with the .php and it worked just fine.

 

Any suggestions?

Link to comment
Share on other sites

I use a .jpg file

 

http://bdcpaging.com/fsesig/mysig.jpg

 

And here is my code for that file

 

<?php
Header ('Content-type: image/jpeg');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Pragma: no-cache');


$current = "";
$pilot = '';

function start_tag($parser, $name, $attribs) {
   global $current;
   $current = $name;
}

function end_tag($parser, $name) {
global $current, $pilot;
}

function tag_contents($parser, $data) {
   global $current, $pilot;	 
   if ($current == "name") {$pilot[] = $data;}
   if ($current == "flights") {$pilot[] = $data;}
 if ($current == "miles") {$pilot[] = $data;}
   if ($current == "hours") {$pilot[] = $data;}

}

$parser = xml_parser_create();

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, "start_tag", "end_tag");
xml_set_character_data_handler($parser, "tag_contents");

$document = file_get_contents("http://localhost.bdcpaging.com/xml/pilots.xml","r") 
       or die("Error reading XML data.");

xml_parse($parser, $document);
xml_parser_free($parser);
/*
echo $pilot[0];
echo $pilot[2];
echo $pilot[4];
echo $pilot[6];	 
*/

// create the image using your own background
$image = imagecreatefromjpeg("FSESig.jpg");

// dimensions of the image used
$img_width = 440;
$img_height = 111;

// set the colours
$cool  = imagecolorallocate($image, 81, 86, 96);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$red   = imagecolorallocate($image, 255, 0, 0);
$grey  = imagecolorallocate($image, 204, 204, 204);
$green = imagecolorallocate($image, 206, 129, 18);
$blue  = imagecolorallocate($image, 0, 0, 255);

// set the font and print text
$font = '/home/users/web/b2031/pow.bdcpaging/htdocs/fsesig/arial.ttf';


// now i will create a line with font size 8, with no angle, 10 pixels to the right, and 17 pixels down
ImageTTFText ($image, 8, 0, 10, 40, $black, $font, "Pilot... $pilot[0]");
ImageTTFText ($image, 8, 0, 10, 60, $black, $font, "Flights Flown... $pilot[2]");
ImageTTFText ($image, 8, 0, 10, 80, $black, $font, "Miles Flown... $pilot[4]");
ImageTTFText ($image, 8, 0, 10, 100, $black, $font, "Hours Flown... $pilot[6]");

// output and destroy
imagepng($image);
imagedestroy($image);

?>

 

I use a XML feed for my data, but maybe you can spot what I'm doing different than what you are doing.

Link to comment
Share on other sites

I pretty much used the code that you just pasted, of course I took out the XML and changed the .htaccess instead of png I used jpg and it didn't work. When I go to it in my browser its asking me to download the image instead of displaying it. Could this be a problem with my php settings or my host then?

Link to comment
Share on other sites

Do you have GD enabled?

 

I believe so.. ( look below ). So since I'm thinking that is enabled what would be left that would cause this then?

gd

GD Support enabled

GD Version bundled (2.0.28 compatible)

FreeType Support enabled

FreeType Linkage with freetype

GIF Read Support enabled

GIF Create Support enabled

JPG Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

Link to comment
Share on other sites

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.