mbman / php-image-cache

Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file, move it to a new directory, and returns the new source for the image.

Home Page:http://nielse63.github.io/php-image-cache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image Cache

Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file, move it to a new directory, and returns the new source for the image.

Support this project by donating on Gittip.

Installation

You can either install the script manually using the require method:

require 'ImageCache.php';

Or (preferred) you can install the script with Composer.

Install Composer in the root directory of your project, and create a composer.json file.

In your composer.json file:

	{
		"require" : {
			"nielse63/phpimagecache": "dev-master"
		}
	}

This is currently the first release of Image Cache, so in this example you'll be able to update your script with any updates made to Image Cache. If, however, you don't want access to any potential updates, remove the tilda form the "version" value.

Navigate to your project root and run the install command of composer.phar.

$ php composer.phar install

From there, include the vendor/autoload.php file in your project, and initilize the class as normal.

Testing

To test the script, install the full project on your server and navigate to the test directory. This ccontains an index file with example functions and an image directory with several images. Run the test/index.php file to ensure that the script is compressing and compiling the sample images. If working correctly, a new directory, "compressed" will appear in your images folder.

Deploying

Include the script in your project either with Composer or via the manual require method and create a new instance of the class, using the appropriate parameters if needed:

$image = new ImageCache();

Possible parameters include:

$image = new ImageCache(
	$filebase = '', $dir = null, $create_dir = true, $opts = array()
);
/**
 * @param $filebase (string) - The base URL that will be included in the final output for the image source; used if image source is an absolute URL
 * @param $dir (string/null) - The base directory that houses the image being compressed
 * @param $create_dir (bool) - Whether or not to create a new directory for the compressed images
 * @param $opts (array) - An array of available options that the user can include to the overwrite default settings
 */

Then compress the image by calling it by it's filename:

$compressed = $image->compress('image.png');

This will return an array of information on the compressed image, including the source of the compressed image, the height, and the width. It can be included in your PHP file as such:

<img src="<?php echo $compressed['src']; ?>" height="<?php echo $compressed['height']; ?>" width="<?php echo $compressed['width']; ?>">

What's Next

Future development changes include:

  • Integration with Tim Thumb and other image cropping libraries
  • Increase browser capabilities (and further testing down to IE 8)
  • Fixing the issue with 304 headers being ignored
  • More options, better documentation, more forms of output, etc.

Contributing changes

Contributing to the project would be a massive help in maintaining and extending the script. It has a lot of potential, and any help would be awesome.

If you're interested in contributing, issue a pull request on Github or email me directly at erik@312development.com.

License

Create Commons Attribution Lisence:

http://freedomdefined.org/Licenses/CC-BY

.gitignore

Allows for files to be ignored in builds.

.travis.yml

This is used on travis-ci.org for continuous integration testing.

Support this project by donating on Gittip.

Bitdeli Badge

About

Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file, move it to a new directory, and returns the new source for the image.

http://nielse63.github.io/php-image-cache

License:Other