Jump to content

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);

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.