WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Image Cache
Categories : Graphics, PHP Classes, PHP Update Picture
Brian Akins
Date : Feb 16th 2001
Grade : 2 of 5 (graded 6 times)
Viewed : 7342
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Brian Akins
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php

if(defined("image_cache.php")) {
return;
} else {
define("image_cache.php",1);
}

/*
=pod

=head1 NAME

Image Cache - Class to "cache" dynamically created images.

=head1 Dependencies

PHP with gd and png support compiled in.

=head1 SYNOPSIS

Example:
$image = new Image_Cache("this_image.png");
if($image->get()) {
$image->display();
}else{
//create a png named $png
$image->store($png);
$image->display();
}

=head1 DESCRIPTION

Basically, Image Cache writes dynamically created images to disk on the first access so that on
subsequent requests the image may be read from disk, rather than redrawn from computations. It also
has the ability to set a timeout on images so that they are recalculated after a certain duration.

=cut
*/

class Image_Cache {

/*
=pod

=head2 Varibles

=over 4

=item I<path>

The relative path to store cached images. This directory must be readable and writeable by the
webserver.

Default: ./dyn_images

=item I<image>

The full path to the cached image. Considered private.

Default: None. Should not be set other than by class!

=item I<Timeout>

Time, in seconds, that an image may reside on disc before being recalculated.

Default: 86400 (24 hours)

=back

=cut
*/
var $path = "./dyn_images/";
var $image;
var $Timeout = 86400;

/*
=pod

=head2 Methods

=over 4

=item I<Image_Cache>

Public constructor.

Arguments:

=over 4

title - Title of image to be cached. Should be unique.

Timeout - Time, in seconds, that an image may reside on disc before being recalculated. Default:
86400 (24 hours)

=back

Returns: nothing

Example:

=over 4

$image = new Image_Cache("thispage.png",360);

creates an Image Cache object with a timeout of 1 hour and a path of "./dyn_images/thispage.png".

$image = new Image_Cache("thispage.png");

creates an Image Cache object with a timeout of 24 hours and a path of "./dyn_images/thispage.png"

=back

=cut
*/

function Image_Cache($title = "",$Timeout = 86400) {
if($title) {
$title = urlencode($title);
$this->image = $this->path . $title;
}

$this->Timeout = $Timeout;

}


/*
=pod

=item I<get>


Determines if an image exists, and, if so, if it was created within the timeout.

Arguments: none

Returns: 1 if the image is valid, 0 if not.

=cut
*/

function get() {

if(is_readable($this->image)) {
$stat = stat($this->image);
if( (time() - $stat[9]) < $this->Timeout ) {
return 1;
}
}

return 0;
}

/*
=pod

=item I<store>

Stores a png to disk.

Arguments: The resource id of the image to be stored.

Returns: nonzero value if succesfull, 0 otherwise.

=cut
*/
function store($png) {
return imagepng($png,$this->image);
}

/*
=pod

=item I<display>

Handles the image output.

Arguments: none

Returns: nonzero value if succesfull, 0 otherwise.

=cut
*/
function display() {
$im = @imagecreatefrompng ($this->image);
return imagepng($im);
}
}

/*
=pod

=back

=head1 AUTHOR

M. Brian Akins, bakins@stsi.net

=cut
*/
?>



crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
Render TTF Text to PNG. Text message, font, size, rotation, padding, color, background, and transparency can all be defined via URL.
Categories : PHP, PHP Classes, Graphics
HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs
HTML_Graphs provides a simple PHP interface for creating pure HTML charts.
Categories : Graphics, PHP, PHP Classes, Charts and Graphs
3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations.
Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
PHP interface class to the eBusiness Charts generatation remote service.
Categories : PHP, PHP Classes, Graphics, Charts and Graphs
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
A class to draw real 3D graphics with surface area
Categories : Graphics, PHP, PHP Classes
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation