GithubHelp home page GithubHelp logo

mbman / php-image-cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nielse63/php-image-cache

0.0 2.0 0.0 31.6 MB

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

License: Other

php-image-cache's Introduction

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 [email protected].

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

php-image-cache's People

Contributors

bitdeli-chef avatar tjefford avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.