Well, tell you the truth, what you see on my site is generated on-fly by GD
here is a code simular to what I'm using (note, GD v2 and PHP v5.x is required for this!):
create file
thumb.php with this content:
<?php
error_reporting(E_ALL);
$effects = array(
"blur" => array("101", 10),
"grey" => array("010"),
"contrast" => array("001", 0, -50),
);
$etag = "";
$modified = "";
$folder = "";
define("ROOT_PATH", "./");
include("config.php");
include(ROOT_PATH."includes/constants.php");
if(!function_exists('file_get_contents'))
{
function file_get_contents($file)
{
$file = file($file);
return !$file ? false : implode('', $file);
}
}
if (isset($_GET['file']) && !empty($_GET['file']))
{
$file = THUMB_DIR."/".urldecode($_GET['file']);
if (isset($_GET['folder'])) $folder = $_GET['folder'];
function effect($file, $data, $array = array())
{
$types = array(1 => "gif", 2 => "jpeg", 3 => "png");
$type = getimagesize($file);
$type = @$types[$type[2]];
if (empty($type) || !$image = @ImageCreateFromString($data)) return false;
$effect = (isset($array[0])) ? $array[0] : "000";
$l = (isset($array[1])) ? $array[1] : 10;
$param = (isset($array[2])) ? $array[2] : -50;
if (substr($effect, 0, 1) == "1")
{
for ($i = 0; $i < $l; $i++)
{
imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
}
}
if (substr($effect, 1, 1) == "1")
{
imagefilter($image, IMG_FILTER_GRAYSCALE);
}
if (substr($effect, 2, 1) == "1")
{
imagefilter($image, IMG_FILTER_CONTRAST, $param);
}
ob_start();
$cr = "Image".$type;
@$cr($image, '', 85);
$data = ob_get_contents();
ob_end_clean();
return $data;
}
if (file_exists($file) && in_array($folder, array_keys($effects)))
{
$etag = crc32($file.$folder);
$info = @getimagesize($file);
if (!isset($info['mime']) || !$info['mime'])
{
$ext = strtolower(substr(strchr($file,"."), 1));
include(ROO_PATH."includes/upload_definitions.php");
if (isset($mime_type_match[$ext]))
{
$mime = $mime_type_match[$ext][0];
}
}
else
{
$mime = $info['mime'];
}
$modified = ($modified) ? $modified : gmdate('D, d M Y H:i:s', filemtime($file)).' GMT';
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $modified || substr($_SERVER['HTTP_IF_MODIFIED_SINCE'],0,(strlen($_SERVER['HTTP_IF_MODIFIED_SINCE'])-strlen(strrchr($_SERVER['HTTP_IF_MODIFIED_SINCE'],";")))) == $modified) && (!isset($_SERVER['HTTP_IF_NONE_MATCH']) || empty($_SERVER['HTTP_IF_NONE_MATCH']) || $_SERVER['HTTP_IF_NONE_MATCH'] == '"'.$etag.'"'))
{
header("HTTP/1.1 304 Not Modified");
header("ETag: \"".$etag."\"");
exit;
}
$data = "";
$data = effect($file, file_get_contents($file), $effects[$folder]);
if ($data)
{
header("Last-Modified: " . $modified);
header("Content-type: ".$mime);
header("ETag: \"".$etag."\"");
echo $data;
exit;
}
}
}
header("HTTP/1.1 404 Not Found");
/*
header("Content-type: image/gif");
header("Content-length: 208");
$file = "R0lGODlhIAAgAKIAAO/v71lZWcDAwP8AAPHx7v///////wAAACH5BAEAAAYALAAAAAAgACAAAAOVKLrc/osIQ6u9OFOpu6/cJ2LhaBrlKaaqx7baSwF0bddBPGVA4f/AgiCXkRl6weBQp0Emf8viDuN8Comk6cU5GPi6vmi2CeyCw9iLsVo4o5m8shmatqx/57NYrbWwk3t2fRV/SnUggzNWdHBUi29STRAMhxuJBgGZmpubjTAdRp+Ioi6XpCimpKGqqaIEr7CxsrO0sgkAOw==";
echo base64_decode($file);
*/
exit;
?>
Upload it to your 4images root directory.
If you dont have apache webserver or mod_rewrite is not installed/enabled, then skip this step and continue with next, otherwise create
data/thumbnails/.htaccess file with the following content:
RewriteEngine on
RewriteRule ^([0-9]+/)([a-zA-Z0-9]+)/(.*)$ ../../thumb.php?file=$1$3&folder=$2
If you want to show blur thumbnails for the images visitor not allow to view, in includes/functions.php find:
$file_src = get_file_path($thumb_file_name, "thumb", $cat_id, 0, 1);
If you have apache webserver with mod_rewrite enabled then insert below:
if (!$show_link)
{
$file_src = str_replace("/".$thumb_file_name, "/blur/".$thumb_file_name, $file_src);
if (file_exists($file_src_new)) $file_src = $file_src_new;
}
Otherwise insert below this:
if (!$show_link)
{
$file_src = "thumb.php?file=".urlencode(str_replace(THUMB_DIR."/", "", $file_src))."&folder=blur";
}
Done.
In thumb.php I've added three "effects":
1) blur
2) greyscale
3) enhanced contrast
the 1) and 3) effects are used together when accessed "blur" images.
You also can get the 2) effect if you replace word "blur" in the url to "grey" and to get 3) effect use "contrast"
These effects being controled by third parameter of effect() functions.
The parameter represent an array, the first item in the array represent the type of effect and must contein three digits string (i.e.
101), the sequence of the digits is equal to the effect list above. Its almost like a binary code: "1" is equal to turn on filter, "0" - turn off
For example if you want only blur effect use "100", for only grey effect: "010" and for grey effect with contrast enhencment: "011"
Also, this code is checking "last modifyed" headers, same as normal webserver does, so if file was not modifyed, it will return only "304 not modifyed" header and will not recreate thumbnail, which will save some perfomance and bandwidth.