Saving the image

You can save the image to an explicit file using save($file, $type = 'jpg', $quality = 80):

<?php// ...$image->save('output.jpg', 'jpg', 85);

You can also get the contents of the image using get($type = 'jpg', $quality = 80), which will return the binary contents of the image

Using cache

Each operation above is not actually applied on the opened image, but added in an operations
array. This operation array, the name, type and modification time of file are hashed using
sha1() and the hash is used to look up for a cache file.

Once the cache directory configured, you can call the following methods:

jpeg($quality = 80): lookup or create a jpeg cache file on-the-fly

gif(): lookup or create a gif cache file on-the-fly

png(): lookup or create a png cache file on-the-fly

guess($quality = 80): guesses the type (use the same as input) and lookup or create a
cache file on-the-fly

setPrettyName($prettyName, $prefix = true): sets a "pretty" name suffix for the file, if you want it to be more SEO-friendly.
for instance, if you call it "Fancy Image", the cache will look like something/something-fancy-image.jpg.
If $prefix is passed to false (default true), the pretty name won't have any hash prefix.
If you want to use non-latin1 pretty names, behat/transliterator package must be installed.

Using fallback image

If the image file doesn't exists, you can configurate a fallback image that will be used
by the class (note that this require the cache directory to be available).

A default "error" image which is used is in images/error.jpg, you can change it with:

<?php$img->setFallback('/path/to/my/fallback.jpg');

Garbage Collect

To prevent the cache from growing forever, you can use the provided GarbageCollect class as below:

<?phpuseGregwar\Image\GarbageCollect;// This could be a cron called each day @3:00AM for instance// Removes all the files from ../cache that are more than 30 days// old. A verbose output will explain which files are deletedGarbageCollect::dropOldFiles(__DIR__.'/../cache', 30, true);

Development

Gregwar\Image is using PHP metaprogramming paradigms that makes it easy to enhance.

Each function that handles the image is implemented in an Adapter, this is where
all the specific actions take place.

The Common adapter is design to contain common abstract actions, while the
specific adatpers (like GD) are designed to contain actions specific to the low
level layer.

You can add your own methods by adding it in the corresponding adapter.

<?php// In the adapterprivatefunctionmyFilter() {$this->negate();$this->sepia(); }

Which could be used on the Image

<?php$image->myFilter();

You can also write your own adapter which could extend one of this repository and use it by calling setAdapter():

<?php$image->setAdapter(newMyCustomAdapter);

License

Gregwar\Image is under MIT License, please read the LICENSE file for further details.
Do not hesitate to fork this repository and customize it !