afxsoft/phpimagecache

Fork of https://github.com/nielse63/php-image-cache using psr-4 autoload and removing unused stuff.

1.0.0 2014-09-29 23:13 UTC

This package is not auto-updated.

Last update: 2024-04-28 03:51:49 UTC


README

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.

Installation

Install Composer by opening Terminal and navigating to the directory in which you'd like to install Image Cache.

Installation Execute this bash command from your project’s root directory:

composer require afxsoft/phpimagecache:dev-master

Basic Usage The class is pretty small, and very basic. First, include the file and initialize the class:

require_once 'ImageCache.php';
$imagecache = new Afxsoft\App\ImageCache();

Optional: Set the location of the directory to house your cached images:

$imagecache->cached_image_directory = dirname(__FILE__) . '/images/cached';

Next, reference the image that you want compressed and store the new image source in a variable. Echo this variable within the 'src' attribute of an image tag:

$cached_src = $imagecache->cache( 'images/unsplash1.jpeg' );
/// <!-- later in your HTML -->
<img src="<?php echo $cached_src; ?>" alt="Amazingly awesome photo">