Skip to content

Instantly share code, notes, and snippets.

@GarryOne
Created December 18, 2016 10:23
Show Gist options
  • Save GarryOne/95114bf641c5ac1175120833bb342c33 to your computer and use it in GitHub Desktop.
Save GarryOne/95114bf641c5ac1175120833bb342c33 to your computer and use it in GitHub Desktop.
<?php
ini_set("display_errors", 1);
date_default_timezone_set('Europe/Bucharest');
$im = imagecreatefromjpeg('ctp.jpg');
$font = 'Roboto-Regular.ttf';
// Ex: 17:01 in 11/12/2016
$text = date('H:i \i\n d/m/Y', strtotime('+ 1 day -4 minute'));
$color = imagecolorallocate($im, 0, 0, 0);
$bg = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 110, 1240, 465, 1280, $bg);
imagettftext($im, 30, 0, 110, 1276, $color, $font, $text);
// Ex: '12-10 17:00'
$text = date('m-d H:i', strtotime('-5 minute'));
$color = imagecolorallocate($im, 120, 120, 120);
$bg = imagecolorallocate($im, 248, 248, 248);
imagefilledrectangle($im, 800, 880, 970, 920, $bg);
imagettftext($im, 23, 0, 810, 910, $color, $font, $text);
// Ex: '17:01'
$text = date('H:i');
$color = imagecolorallocate($im, 40, 40, 40);
$bg = imagecolorallocate($im, 248, 248, 248);
imagefilledrectangle($im, 15, 15, 90, 50, $bg);
imagettftext($im, 24, 0, 18, 41, $color, $font, $text);
// Render image
header('Content-Type: image/jpg');
imagejpeg($im);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment