PHP Classes
elePHPant
Icontem

Date PNG: Generate a PNG image with a given time

Recommend this page to a friend!
  Info   Screenshots Screenshots   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2009-03-02 (7 years ago) RSS 2.0 feedNot enough user ratingsTotal: 405 All time: 6,184 This week: 1,087Up
Version License PHP version Categories
datepng 0.9GNU General Publi...5.0PHP 5, Time and Date, Graphics
Description Author

This class can be used to generate a PNG image with a given time.

It opens a given template image in PNG format and renders a text with given time in one or more formats.

The font, size, position, angle and color of the text are configurable parameters.

The resulting image is generated in the PNG format as the current script output.

Picture of Buddhika Laknath
Name: Buddhika Laknath <contact>
Classes: 1 package by
Country: Sri Lanka Sri Lanka

Details
author Laknath (blaknath [at] gmail [dot] com)
version 0.9
to see a live demo of this class, check http:hotelotravel.com

License
========
DatePNG - Create the png from a given date
Copyright (C) 2009 by Buddhika Laknath <blaknath [at] gmail [dot] com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http:www.gnu.org/licenses/>.

Functionality:
==============
when given a valid timestamp it creates a png image with the given date format and png background template in the designated folder. To optimize the process and avoid having to create pngs every time the site loads it caches created pngs and use them if a given date png already exists.

Example:
========
<?php
get font ttf path
$font = $_SERVER["DOCUMENT_ROOT"].'/Arial.ttf';

png file template that's used as the background
$png_path = $_SERVER["DOCUMENT_ROOT"].'/date.png';

create a DatePNG object with the current timestamp and png file template
$datePNG = new DatePNG($time(), $png_path);

define the folder which the font files should be created (this folder must exist and writable)
$datePNG->folder = $_SERVER["DOCUMENT_ROOT"].'/dates';

define the text style and date pattern, each text pattern in each associated array

Possible values for the associated array with keys
$datePNG->formats = array(
	array('format'=>'d','font'=> $font, 'size'=>14,'angle'=>0,'x'=>5,'y'=>20,'color'=>'0x666666', 'linespacing' => 1.5),
	array('format'=>'M','font'=> $font, 'size'=>8,'angle'=>0,'x'=>5,'y'=>37,'color'=>'0x666666', 'upper_case' => true)
);

create the png and return the path of the created date png
$date_path = $datePNG->create_png();

echo '<img src="'.$date_path.'" alt="date" />' ;
?>
Screenshots  
  • datepng.png
  Files folder image Files  
File Role Description
Image file date.png Photo PNG template
Plain text file DatePNG.inc.php Class DatePNG.class
Plain text file README Doc. README

 Version Control Unique User Downloads Download Rankings  
 0%
Total:405
This week:0
All time:6,184
This week:1,087Up