image.jpg

upload

The Trick

.htaccess

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?thumb=$1 [L,QSA]

thumb

This mean the server will dealing with the image once

Notice:

Image Transform

Getting Started

include_once ('../inc/transform.class.php'); if (!$_GET['thumb']) { exit('error'); } $thumb = $_GET['thumb']; $thumb_array = explode(',',$thumb); $mode = array_shift($thumb_array); $upload_path = '../upload/'; $imageTransform = new imageTransform; switch ($mode){ case 'gray': $file = $thumb_array[0]; $path = $upload_path.$file; $save = implode(",",array($mode,$file)); $imageTransform->view('gray', $path, null, $save); break; case 'rotate': //degrees allowed. $degrees = array('90','180'); $degree = $thumb_array[0]; $file = $thumb_array[1]; $path = $upload_path.$file; $save = implode(",",array($mode,$degree,$file)); if (in_array($degree,$degrees)) { $imageTransform->view('rotate', $path, $degree, $save); } break; case 'resize': case 'crop': //sizes allowed $sizes = array('50x50','100x100','600x400'); $size = $thumb_array[0]; $file = $thumb_array[1]; $path = $upload_path.$file; if (in_array($size,$sizes)) { $imageTransform->view($mode, $path, $size,implode(",",array($mode,$size,$file))); } break; case 'flip': case 'flop': $file = $thumb_array[0]; $path = $upload_path.$file; $save = implode(",",array($mode,$file)); $imageTransform->view($mode, $path, null, $save); break; default : exit('This is not valid mode'); }

$upload_path the folder which you uploading your images

the folder which you uploading your images $degrees in rotate case, this Lets you use specific degrees (90,-90,180,etc..)

in rotate case, this Lets you use specific degrees (90,-90,180,etc..) $sizes in case of resize or crop, let you use specific sizes (To prevent the random operations)

Resize or Crop

/thumb/crop,50x50,google.jpg

$upload_path

thumb

crop,50x50,google.jpg

Rotate

eg. /thumb/rotate,90,google.jpg

$upload_path

thumb

rotate,90,google.jpg

Make it Gray

/thumb/gray,google.jpg

$upload_path

thumb

gray,google.jpg

You uploadto your image folder,and want the same image in differant size or you want to crop, rotate it or make it gray. what should you do?take a look at thiscode, we use it to redirect incoming image requests through any Size to a PHP file to resize, crop or rotate itthumb/.htaccessthis code will check if the requested image already in thefolder or not, in case of existence the image (already resized, croped or rotated) will open directly, if not the php file will take the image and work on itI will useclass ( @phpclasses.org by Lito) to perform image manipulation operationsthumb/index.phpGo to "/thumb/resize or crop,size(width x height),image file" eg.this will go to('../upload/google.jpg'), then save it inasGo to "/thumb/rotate,degree(intger),image file"this will go to('../upload/google.jpg'), then save it inasGo to "/thumb/gray,image file" eg.this will go to('../upload/google.jpg'), then save it inas