Skip to content

cluebattery/CodeIgniter-Image-Cache

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CodeIgniter Image Cache

CodeIgniter library to generate and cache images on the fly.

Setup

  1. Edit config/image_cache.php file with appropiate settings
  2. Copy config, controller and model file to your CodeIgniter installation
  3. Load config/image_cache.php file in your config/autoload.php
  4. Create a directory for images and give CodeIgnite write permissions

Settings

Parametres inside config/image_cache.php

  • ic_upload_directory → Directory, from root application, where Image Cache will look for the source images
  • ic_resize_limit → Maximum number of versions that Image Cache will create of each image

How it works

Image Cache listens the “/img” requests with ‘w’ and ‘h’ get URL parameteres, look if there’s a cache version available and if not, creates it on the fly and saves it. You can call the images with parameters from the template itself.

To avoid brute force attacks, you can set a limit of versions of each image that Image Cache will create.

Call the image without parameters shows a 404 error.

Example of use

Call an image from your templates with ‘w’ and ‘h’ get URL parameteres. Image Cache will create an image with the size, filling all the pixels from the source image.

Resize + Crop:
<img src=“/img/picture_1.jpg?w=500&h=300” />

Resize:
<img src=“/img/picture_2.jpg?w=700” />
<img src=“/img/picture_2.jpg?h=400” />

You can call for images in subdirectories as well:
<img src=“/img/news/new_1/picture_1.jpg?w=500&h=300” />

About

CodeIgniter library to generate and cache images on the fly

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published