Skip to content

A media server that allow you to serve images from local storage or Amazon S3 and dinamically resize & crop based on URL prefixes, fully configurable.

Notifications You must be signed in to change notification settings

obokaman-com/images-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Images server

This set of scripts will allow you to build a light-weight images server and dynamic thubnail generation & caching, based on a repository where the original images will remain “untouched”.

Actually, the Image Server allow two options for original images storage: local storage and Amazon S3 storage.

Image Server integrates the official Amazon S3 library and PHP Thumb for image generation / resizing.

Quick Start

1. Configure your web server

  • Point a VirtualHost DocumentRoot to /public/ folder.
  • Use /public/index.php script as a dispatcher for all requests for files that doesn’t exists. There’s several ways to accomplish this, depending on what web server you use. (Fast implementation for Apache: ErrorDocument 404 /index.php)
  • Optimize your web server configuration to set a far future expire date for static files.

2. Give write permissions to /public folder

chmod 777 ./public

3. Rename sample_config.php to config.php and edit it to fit your needs

Some example usages:

Case 1:

Note that we directly translate request route to local path.

Lines to customize:
$config['filesystem'] = 'local';
$config['local_files'] = '/home/me/media/';

Case 2

Note that we are using an unexistent /category-name/ folder, and a seo-optimized-product-name add to real image name (a numeric product id) on URL requests.

Lines to customize:
$config['filesystem'] = 'local';
$config['local_files'] = '/home/me/media/';
$config['path_conversions'] = array(
'/^category-name\/.+-([0-9]+)\./' => '\\1.'
);

Expiring local cached images on demand

Since this image server will mantain local copies of every requested and resized image, you’ll need to expire and remove local cached images when you make changes to original images or remove them.

You can make a REST call prepending /delete/ to image request path. For instance, for deleting local cached image http://stc.domain.net/user/obokaman.jpg (and all the related thumbnails), you can call http://stc.domain.net/delete/user/obokaman.jpg

This call will return you a JSON answer with an array called “deleted-images” containing all images that has been removed from local cache.

Automated expiring of locally cached images

It will be a good practice to automatically remove those locally cached images that hasn’t been accessed for a long time. You can set up a cronjob to check your local images cache and remove those images that hasn’t been accessed for, let’s say, last month. You can retrieve this information using the filatime php function or find %path% -atime +%num% command, wich would return all files in path that were accessed more than num days ago.

For instance:

find /home/me/media/ -atime +5 | xargs rm

This will delete all files in /home/me/media/ not being accessed in last five days.

About

A media server that allow you to serve images from local storage or Amazon S3 and dinamically resize & crop based on URL prefixes, fully configurable.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages