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" />' ;
?>
|