php sig help

Associate
Joined
28 Feb 2007
Posts
969
Location
Leeds/Sunderland
I've been trying for ages but I can get the time on the line below.
Does any one know?
Heres the code:
PHP:
<?php
header ("Content-type: image/png");
$img = imagecreatefrompng ("sig.png");
$colour = ImageColorAllocate ($img, 0, 0, 0);
$read1 = date("D dS M y  h:i:s A");
$input = ($read1);
ImageString($img, 3, 15, 30, $input, $colour);
imagepng($img);
?>
Its probably something easy i know it.
 
The code works for me, what errors are you getting?

NOTE: If you want only the time you only need remove a small piece of code. Aside from that it works in any case.

What version of PHP are you running?

Plonk
PHP:
phpinfo();
into a page and see what version is shown.

It may be simply be the version of PHP you are using doesn't support the commaand you are using.

FURTHER NOTE: Make sure the PNG file the code refers to actually exists or it will produce an error.
 
Last edited:
Change the following lines...

Code:
[COLOR=#000000][COLOR=#0000bb]header [/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Content-type: image/png"[/COLOR][COLOR=#007700]);
[/COLOR][COLOR=#0000bb]$img [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]imagecreatefrompng [/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"sig.png"[/COLOR][COLOR=#007700]);[/COLOR][/COLOR]
to

Code:
[COLOR=#000000][COLOR=#0000bb]header [/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Content-type: image/jpeg"[/COLOR][COLOR=#007700]);
[/COLOR][COLOR=#0000bb]$img [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]imagecreatefromjpeg [/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"sig.jpeg"[/COLOR][COLOR=#007700]);[/COLOR][/COLOR]
or

Code:
[COLOR=#000000][COLOR=#0000bb]header [/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Content-type: image/gif"[/COLOR][COLOR=#007700]);
[/COLOR][COLOR=#0000bb]$img [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]imagecreatefromgif [/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"sig.gif"[/COLOR][COLOR=#007700]);[/COLOR][/COLOR]
http://uk2.php.net/manual/en/ref.image.php

The functions for JPEG and GIF are supported. However when testing they failed to work on the test page i created last time i was testing the code for you, switching back to PNG fixes the problem.

This should be supported in onwards of PHP3 (no problems there), but still won't work for me.

What's wrong with using PNG?

EDIT: Originally missed this line...

imagepng($img);

Have tried again using JPEG and it still fails simply outputting the page name instead of an image.
 
Last edited:
EDIT: It does work, it was me trying to save time by renaming the image extension..

Code:
<?php
header ("Content-Type: image/jpeg");
$img = imagecreatefromjpeg ("test.jpg");
$colour = ImageColorAllocate ($img, 255, 255, 255);
$read1 = date("D dS M y  h:i:s A");
imagestring($img, 3, 15, 30, $read1, $colour);
imagejpeg($img);
imagedestroy($img);
?>
Works....

I made a few changes, imagedestroy frees up memory after running the script, and i've removed a not needed line that simply changes the $read1 variable to $input, there's no need to do that.

Sorry still learning PHP myself, but it does work..... :)

Or if you want the date and time on 2 lines...

Code:
<?php
header ("Content-Type: image/jpeg");
$img = imagecreatefromjpeg ("test.jpg");
$colour = ImageColorAllocate ($img, 255, 255, 255);
$read1 = date('D dS M y');
$read2 = date('h:i:s A');
imagestring($img, 3, 15, 30, $read1, $colour);
imagestring($img, 3, 15, 50, $read2, $colour);
imagejpeg($img);
imagedestroy($img);
?>
 
Last edited:
Back
Top Bottom