[ Index ]
 

Code source de PHP PEAR 1.4.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Cache/ -> Graphics.php (sommaire)

(pas de description)

Poids: 353 lignes (13 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 1 fichier
 Cache.php

Définit 1 class

Cache_Graphics:: (8 méthodes):
  Cache_Graphics()
  getImage()
  getImageLink()
  cacheImage()
  cacheImageLink()
  setCacheURL()
  setCacheDir()
  generateID()


Classe: Cache_Graphics  - X-Ref

Graphics disk cache.

The usual way to create images is to pass some arguments that describe the image
to a script that dynamically creates an image. For every image of a page
a new PHP interpreter gets started. This is a good way to kill your webserver.

When dealing with dynamically generated images you should not call another script
to generate the images but generate the images by the script that produces the page
that contains the images. This is a major improvement but it's only half the way.

There's no need to rerender an image on every request. A simple disk cache can reduce
the computation time dramatically. This is what the class graphics_cache is for.

Usage:

// create an instance of the graphics cache
$cache = new graphics_cache;

$img = ImageCreate(...);

// compute an ID for your image based on typical parameters
$id = m5d( $size, $colors, $label);

// check if it's cached
if (!($link = $cache->getImageLink($id, 'gif'))) {

// hmmm, it's not cached, create it
...
// cacheImageLink() and cacheImage() make the ImageGIF() call!
// cacheImage() returns the value of ImageGIF() [etc.], cacheImageLink() returns a URL
$link = $cache->cacheImageLink($id, $img, 'gif');

}

// Ok, let's build the ImageLink
$size = getImageSize($link[0]);
printf('<img src="%s" %s>', $link[1], $size[3]);

// for cacheImage():
// header('Content-type: image/gif'); print $cache->cacheImage($id, $img, 'gif');


The class requires PHP 4.0.2+ [ImageType()]. Note that cacheImage() works with
the output buffer. Modify it if required!

Cache_Graphics()   X-Ref
Instantiates a cache file container.


getImage($id, $format = 'png')   X-Ref
Returns the content of a cached image file.

This function can be used to send the image directly to the browser.
Make sure that you send a correspondending header before sending the image itself.

Always try to get the image from the cache before you compute it. See
the class docs for an example.

param: string  Image-ID
param: string  Image type: gif, jpg, png, wbmp
return: string  Image file contents if a cached file exists otherwise an empty string

getImageLink($id, $format = 'png')   X-Ref
Returns an array with a link to the cached image and the image file path.

Always try to get the image from the cache before you compute it. See
the class docs for an example.

param: string  Image-ID
param: string  Image type: gif, jpg, png, wbmp
return: array   [ full path to the image file, image url ]

cacheImage($id, $img, $format = 'png')   X-Ref
Create an image from the given image handler, cache it and return the file content.

Always try to retrive the image from the cache before you compute it.

Warning: this function uses the output buffer. If you expect collisions
modify the code.

param: string  Image-ID. Used as a part of the cache filename.
param: string  Image handler to create the image from.
param: string  Image type: gif, jpg, png, wbmp. Also used as filename suffix.
return: string  Image content returned by ImageGIF/...

cacheImageLink($id, &$img, $format = 'png')   X-Ref
Create an image from the given image handler, cache it and return a url and the file path of the image.

Always try to retrive the image from the cache before you compute it.

param: string  Image-ID. Used as a part of the cache filename.
param: string  Image handler to create the image from.
param: string  Image type: gif, jpg, png, wbmp. Also used as filename suffix.
return: array  [ full path to the image file, image url ]

setCacheURL($cache_url)   X-Ref
Sets the URL prefix used when rendering HTML Tags.

Make sure that the URL matches the cache directory,
otherwise you'll get broken links.

param: string

setCacheDir($cache_dir)   X-Ref
Sets the directory where to cache generated Images

param: string

generateID($variable, $format = 'png')   X-Ref
Pas de description



Généré le : Sun Feb 25 14:08:00 2007 par Balluche grâce à PHPXref 0.7