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.

Overview

NO LONGER MAINTAINED!!!

Image Cache v. 1.0.0

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.

Current Status

Build Status

Employing travis-ci.org for continuous integration testing and assurance of code validity.

Installation

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

Download Composer:

curl -sS https://getcomposer.org/installer | php

Create a composer.json file:

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

Navigate to your project root and run the install command.

$ php composer.phar install

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

More information on installing and using Composer can be found at getcomposer.org, and dependency information on the package can be found at packagist.org.

Testing

Manual Testing

To test the script manually by receiving visual output, setup a virtual host and load demo/index.php in your browser. Three examples are set in that file: the original image called from an outside source; a cached example referencing the outside source via an absolute URL; and an internal source referencing a file path.

Using Chrome Developer Tools you can see the difference in load times between the external source (non-cached image) and the internally stored and cached image.

Unit Testing

Some extremely basic unit tests are included with the script and can be run using PHP Unit. I'm working on continuing to build up these tests and would more than welcome any contributions to the tests.

To execute the tests in a bundled script (along with rebuilding the docs), clone the repository, navigate to the root of the repo in terminal, and execute:

$: sh build

Assuming you have the phpunit and phpdoc commands intalled, the tests will pass and docs will be rebuilt.

What's Next

See the source for a full to do list of changes that I wish to accomplish moving forward.

Contributing

Contributing to the project would be a massive help in maintaining and extending the script. The module is being used on a larger scale than I initially imagined, and continuing to maintain it is becoming a little time consuming for just me.

If you're interested in contributing, issue a pull request on Github or email me directly at [email protected].

For any issues found or extensions you'd like to see, feel free to submit an issue ticket so we can start a discussion about the viability of the problem and how it can be resolved.

License

Creative Commons Attribution Lisence:

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

Bitdeli Badge

Comments
  • Keep the previous format

    Keep the previous format

    Hello. Based on this statement:

    imagejpeg( $image, $newlocation, $this->opts['quality'] );

    an image is always converted as a JPG image. Why it can't be saved as its previous format?

    enhancement 
    opened by AurelioDeRosa 4
  • Incorrect work of makesource function on some servers

    Incorrect work of makesource function on some servers

    Hi,

    Yesterday I used ImageCache class to cache some images on my website. I noticed, that when $_SERVER['DOCUMENT_ROOT'] = '/', then solution presented currently in ImageCache.php is going to replace all occurences of slash, which results in incorrect source string.

    For example, if resulting string should be: /path/to/img , then after using makesource function, we've got: pathtoimg.

    I've done some workaround for it, which works for me:

    private function makesource( $dir ) {
            $cururl = strtolower( reset( explode( '/', $_SERVER['SERVER_PROTOCOL'] ) ) ) . '://' . $_SERVER['SERVER_NAME'];
            $base = $_SERVER['DOCUMENT_ROOT'];
    
            if($base == '/')
            {
                $localpath = substr($dir, 1);
            }else{
                $localpath = str_replace( $base, '', $dir );
            }
    
            return $cururl . $localpath;
    }
    

    Best regards, Mike

    bug 
    opened by sil3ntboy 3
  • Check if the new image is larger than the old image ?

    Check if the new image is larger than the old image ?

    Hi,

    I noticed that some times the size of the image actually increases. For ex an image 170 KB increase to 204 KB.

    This happens rarely but it would be good if there was an inbuilt way to check if any image compression took place.

    opened by bhargavy 2
  • Fix strtotime() empty

    Fix strtotime() empty

    The documentation of PHP does not allow strtotime() empty.

    Error: strtotime() expects at least 1 parameter, 0 given

    File: /src/ImageCache/ImageCache.php Line: 197.

    Fix: Add 'now' in strtotime(), or switch to time()

    opened by newerton 2
  • Docs do not match code at all

    Docs do not match code at all

    The docs located at:

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

    Do not match the functionality at all. For example:

    $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; primarily used if you want the image source to be an absolute URL; defaults to relative.
     * @param $dir (string/null) - The base directory that houses the image being compressed; defaults to the location of ImageCache.php.
     * @param $create_dir (bool) - Whether or not to create a new directory for the compressed images; defaults to "true"
     * @param $opts (array) - An array of available options that the user can include to the overwrite default settings.  Mostly just for forward-compatibility at the moment.
     */
    

    In the code the constructor actually accepts 3 parameters, 2 of which will be deprecated soon!

    Very confusing.

    Error behaviour is also completely undocumented.

    opened by manticorp 2
  • Script is not user friendly...

    Script is not user friendly...

    I think your script is not user friendly... just to configure your script we need more time... and there are soo many functions missing.... i really wanted to use your script.. but i keep getting errror message ...and these error error message can be answered only by you.. " Call to undefined function ImageCache\curl_init() in C:\wamp\www\icon\src\ImageCache\ImageCache.php " dont know why have you desghned this?? there is no documentation also.. serioously i wasted my time.. even stack experts could not find solutions for your script bugs...if you really want to make this as popular script.. please write a good documentation, each and every line on how to work on your script... forget about script updation, first let the basic things work...Sorry but that's what i found....

    bug 
    opened by sriducati 2
  • Fix fetch_image()

    Fix fetch_image()

    Because when the image has a longer height than width, the image is created with a blank space until the height ends.

    Original Image poltronas-original

    Image after cache(); poltronas-php-mage-cache

    opened by alegueleres 1
  • Message: Undefined variable: main_url

    Message: Undefined variable: main_url

    private function is404($source) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $main_url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_exec($ch); if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '404') return $this->show404(); return false; }

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined variable: main_url

    Filename: ImageCache/ImageCache.php

    Line Number: 232

    opened by sumanta-ghosh 1
  • Error PHP

    Error PHP

    Hello, I download the latest version, then transfer to my server but when I run the demo I have two PHP error ?

    Warning: Unexpected character in input: '' (ASCII = 92) state = 1 in / fximg/new/demo/index.php on line 16

    Parse error: syntax error, unexpected T_STRING in / fximg/new/demo/index.php on line 16

    What it comes from my version of PHP ? ... or something else!

    help me please ;)

    opened by nicemen 1
  • Made Image Cache a PHP 5.3+/PSR-2 compliant package

    Made Image Cache a PHP 5.3+/PSR-2 compliant package

    • Fixed indentation and other coding style details to match the PSR-2 standard (see https://github.com/php-fig/fig-standards/blob/master/accepted/fr/PSR-2-coding-style-guide.md)
    • Added a namespace (also required by PSR-2) and modified documentation, composer.json and test script accordingly
    • Changed the required version of PHP to 5.3.0 and fixed a couple minor issues (lack of a datetime zone definition in the test script, function return value passed directly as reference...) to avoid notices and warnings appearing on PHP 5.3 and above
    • Suggestion : autodetect the current path in the test script ? I had to change it when testing my changes, as I guess http://test is some local domain configured on your own working station
    opened by neemzy 1
  • Quality modification and version handling

    Quality modification and version handling

    I added a way to change the desired quality of the cached image because it could be useful caching images on a lower quality. And also a way to generate new cached versions from the same image. It is usefull to use the same filename for many cropped versions of a image (and to reset browser cache, if necessary).

    ps.: Sorry about the changes on the indentation. I edited it on netbeans and I have a problem with the Ctrl + Shift + F (I use it all the time...)

    opened by williamcarril-trendi 0
  • Blank page

    Blank page

    Hey,

    I am experiencing an issue. I can successfully shrink and cache the image but I am getting a blank page.

    How can I fix this?

    Update: Apparently this is caused by an error made by ImageCache.php: "Final image URL is broken". I used this guide to solve it

    opened by ghost 0
  • Image must writable error

    Image must writable error

    ../images must writable! is being displayed on the php page

    This is the line of code which I believe is giving the problem

    $cached_src_one = $imagecache->cache( '../images/background.jpg' );

    I am running the php page from where the images folder is found.

    opened by firepro20 2
  • JPG (.jpg) not working

    JPG (.jpg) not working

    I am trying your class with JPG file getting lot of errors

    first was "The file you supplied isn't a valid image."

    Then I commented the if condition just to check, then got "The image you supply must have a .gif, .jpg/.jpeg, or .png extension." Then I checked "$file_mime_as_ext" and it dump "octet-stream" for jpg file. I know it's some kind of mime problem. Any idea how to fix it?

    Thanks in advance

    opened by ibnbd 0
  • Final image URL is broken

    Final image URL is broken

    Web server: NGINX PHP Version: 5.5.9-1ubuntu4.14

    I am getting this error Final image URL is broken. The page looks like this page There should be 100 images displayed but it dies at the third.

    It is returning this url exampleImage There should be a / between the mediapage.zips.me and core, however it is a local image so I don't see why it should even need the host name.

    How I am doing this is,

    On the top of each page I am calling another page which contains the setup of the class

    <?php
        //Calls the php-image things
        include 'test.php';
    
    ?>
    

    Inside test.php

    <?php 
        require_once 'core/classes/ImageCache.php';
        $imagecache = new ImageCache();
    ?>
    

    Image page

    <?php 
        //Directory NON-CACHED images are stored in
        $dir    =   "i/";
    
        //Array of files in the Directory
        $files1 =   scandir($dir);
        //Used to limit results (100's of images)
        $count = 0;
        foreach ($files1 as $key) {
            //If the file name is longer than 3 chars and the count is less 
            //than the amount of images I want displayed.
            if (strlen($key) > 3 && $count <= 100){
                $count++;
                //dir2 is the directory/nameofFile.extension
                //Eg: i/testImage.png
                $dir2   =   $dir.''.$key;
                $info = new SplFileInfo($key);
                //Image Cache variable
                $cached_src = $imagecache->cache($dir2);
    ?>
        <tr>
            <td>
                <!-- Link for light box for full resolution image -->
                <a href="<?php echo $dir2;?>" data-popup="lightbox">
                    <!-- src of cached image is outputted and the alt is the name of the uncached image. -->
                    <img src="<?php echo $cached_src;?>" alt="<?php echo $key;?>" class="img-rounded img-preview">
                </a>
            </td>
            <!-- More table stuff... -->
        </tr>
    
    <?php
            } //End If
        } //End for
    ?>
    
    opened by XenRevo 2
  • Bug

    Bug

    Warning: imagejpeg(C:\xampp\htdocs\php-image-cache-master\demo/images/cached/ccc2078020a3fec0056ed59b53a7bf2d.jpeg): failed to open stream: No such file or directory in C:\xampp\htdocs\php-image-cache-master\src\ImageCache\ImageCache.php on line 230 Could not copy image resource.

    "It showing error like this how should i give input(Url) please suggest me"

    opened by asiddu 3
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image

Laravel ImageUp The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization. Install

QCode.in 708 Dec 22, 2022
This plugin adds a new image style for the Core Image block.

This plugin adds a new image style for the Core Image block. Introduction How to use? Go to Gutenberg Editor and add a image block. e.g. Add new image

Mahesh Waghmare 3 Feb 17, 2022
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

Image Optimizer This library is handy and very easy to use optimizer for image files. It uses optipng, pngquant, jpegoptim, svgo and few more librarie

Piotr Śliwa 879 Dec 30, 2022
The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API

Gregwar's Image class The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API. Installation With compos

Grégoire Passault 958 Dec 29, 2022
🤹‍♀️Very simple to use Gravatar implementation for Laravel

Very simple to use Gravatar implementation for Laravel. Install, Include the Facade and then generate, simple! Installation You can install the packag

Wavey 11 May 7, 2022
:racehorse: find the size of an image without downloading the whole file. Supports batch requests.

FasterImage FasterImage finds the dimensions or filetype of a remote image file given its uri by fetching as little as needed, based on the excellent

Will Washburn 58 Nov 30, 2022
A Laravel Gravatar package for retrieving gravatar image URLs or checking the existance of an image.

Gravatar for Laravel 5.x, 6, 7 and 8 Installation First, pull in the package through Composer via the command line: composer require creativeorange/gr

Creativeorange 477 Dec 1, 2022
An open source image hosting service powered by Laravel

Limg An open source image hosting service powered by Laravel Features Upload your image via file, url or ShareX ! Manage your image (custom title, pub

Thomas 56 Dec 16, 2022
GifFrameExtractor is a PHP class that separates all the frames (and their duration) of an animated GIF

================================ GifFrameExtractor ================================ GifFrameExtractor is a PHP class that separates all the frames (an

Clément Guillemain 173 Dec 12, 2022
GifCreator is a PHP class that creates animated GIF from multiple images

================================ GifCreator ================================ GifCreator is a PHP class to create animated GIF from multiple images For

Clément Guillemain 320 Dec 15, 2022
This is a class of php QR Code, This library helps you generate QR codes in a jiffy.

This is a class of php QR Code, This library helps you generate QR codes in a jiffy.

null 59 Oct 5, 2022
A simple page view counter that store data as text and shows data as a PNG image

Image Counter A simple page view counter that store data as text and shows the counter as a PNG image.

Victor Ribeiro 10 Apr 19, 2022
A truly single-file, no-database, drop-in PHP media gallery.

Media Hut When I went looking, in early 2022, the options for a truly single-file, no-database drop-in PHP media gallery were shockingly small. Well,

Toby D 14 Dec 28, 2022
Grabs the dominant color or a representative color palette from an image. Uses PHP and GD, Imagick or Gmagick.

Color Thief PHP A PHP class for grabbing the color palette from an image. Uses PHP and GD or Imagick libraries to make it happen. It's a PHP port of t

Kevin Subileau 610 Dec 28, 2022
PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options !

PHP Image Editor PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options ! ✨ Supporting ⭐ Star this repos

Franck Alary 17 Nov 13, 2022
image sharing site made in PHP just for fun and freetime

2bart image sharing site made in PHP just for fun and freetime To-do list: upload system [DONE] ✔️ views system [DONE] ✔️ image list system [DONE] ✔️

goom 1 Oct 22, 2021
PHP Image Manipulation

Intervention Image Intervention Image is a PHP image handling and manipulation library providing an easier and expressive way to create, edit, and com

null 13k Jan 3, 2023
PHP 5.3 Object Oriented image manipulation library

Imagine Tweet about it using the #php_imagine hashtag. Image manipulation library for PHP 5.3 inspired by Python's PIL and other image libraries. Requ

Bulat Shakirzyanov 4.3k Jan 6, 2023
🌄 Perceptual image hashing for PHP

ImageHash A perceptual hash is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions

Jens Segers 1.9k Dec 28, 2022