Welcome Guest, Not a member yet? Register   Sign In
Real-time image manipulation and cache using class.upload.php
#1

[eluser]helmutbjorg[/eluser]
Hi Guys,

Thought i would share something as I guess this is how the whole open source thing works and I have already taken so much from this forum. I know this has been done before. I'm using the class.upload.php (if you don't know what it can do check out their samples page) because the CI image_lib doesn't handle PNG very well and I think it really is an unfinished and un-supported part of the library to be honest. And class.upload.php is amazing and thorough.

This is not recommended for BEGINNERS. You must understand how the concept works before you can really get good use out of this technique.

I wanted a way to let my clients upload an image (the biggest one they had) and then instead of manipulating that image on upload and creating various sizes to use throughout the system, I want to be able to use a script to generate an image (using a set format template) and save it to cache so that subsequent requests get the modified image. So essentially the resizing, cropping, conversion, etc only happens on the first request for the image.

For example...

A typical process (the old way)
1. A user uploads default.jpg which is 800x600
2. The system creates a thumbnail which is 100x75 and saves it as default_thumb.jpg
3. The system creates a small version which is 300x200 and saves it as default_small.jpg
4. Now the system can use those images like so...
Code:
<?php echo img('uploads/default_small.jpg'); ?>

My system
1. A user uploads default.jpg which is 800x600
2. Now the system can use it like so
Code:
<?php echo img_format('uploads/default.jpg', 'small'); ?>

The first time that tag is called the default.jpg image is modified according to the config image format set for 'small' and saved to cache. The second time the image is loaded from cache requiring no processing time.

The benefits:
1. You don't have to lock yourself in to any particular formats for images so that if requirements change you can deliver any size image or type.
2. Make a change to the format template and delete the cache and the whole site is updated.


Messages In This Thread
Real-time image manipulation and cache using class.upload.php - by El Forum - 01-28-2009, 06:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB