Jump to content

Displaying current date on an image


Recommended Posts

Hi everyone, complete beginner so I am sorry if this is posted in the wrong section.

 

I find PHP very interesting and a lot easier than other programming languages to pick up (I've had issues trying to learn programming languages in the past). I currently have an old laptop running ubuntu 10.04 with Apache, PHP and MySQL installed. It all seems to be working well and together which is nice.

 

I am currently learning the basics, reading and watching tutorials etc etc. I'm not sure if its a bit complex to start but I would like to learn how to write the current data and day of the week onto an image.

 

Really appreciate you reading and if you post thats even better!

Any ideas for tips for me would also be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/233624-displaying-current-date-on-an-image/
Share on other sites

Well if you are a beginner you have jumped in with somethign is a bit of a pain really.

 

what you need to do is create an image resource form the file using somethign like imagecreatefrompng() then write on that image using either imagestring() or imagettftext(). Finally you need to output the image to either the screen or a file using somethign like imagejpeg()

 

there are examples of all of those functions on their php.net pages.

  • 2 weeks later...

Everyting can be found on php.net. I am programming in PHP for more than three years and I still very frequently use php.net manual.

header("Content-Type: image/png");
///dimensions
$im = @imagecreate(110, 20)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
//use date() function to get date Y- year, m- month, d- day, H- hour, i- minute, s- second
//other date parameters can be found in http://www.php.net/manual/en/function.date.php
$date = date("Y-m-d H:i:s");
imagestring($im, 1, 5, 5,  "Date: $date", $text_color);
imagepng($im);
imagedestroy($im);

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.