forked from masterexploder/PHPThumb
/
PHPThumb.php
69 lines (50 loc) · 1.42 KB
/
PHPThumb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// SETTINGS
//
// To squeak a few more KB of memory performance out of this script replace the dynamic settings
// here with static paths.
//
// The path to PHPThumb
require_once 'ThumbLib.inc.php';
//
// The path to your web root
$document_path = '/'.trim($_SERVER['DOCUMENT_ROOT'], '/').($_SERVER['DOCUMENT_ROOT']!=''?'/':'');
//
// The path to your cache folder
$cache_path = '/Users/markhuot/Sites/PHPThumb/cache/';
//
// The URI to your cache folder
$cache_uri = 'http://'.trim($_SERVER['HTTP_HOST'], '/').'/cache/';
//
// How long caches should live. Remember, hard refreshes will also clear out your cache so you'll be
// safe setting this pretty high
$cache_life = '-1 month';
// End configurable settings
$params = array('src'=>false, 'w'=>false, 'h'=>false);
$options = array('resizeUp'=>true,'jpegQuality'=>100,'cache_life'=>$cache_life);
extract(array_merge($params, $options, $_GET));
$cache = md5($src.$w.$h);
$cache_path.= $cache;
if (
file_exists($cache_path) &&
($cache_life == false || filemtime($cache_path) > strtotime($cache_life)) &&
@$_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache'
)
{
header('Content-type: image/jpeg');
header('Location: '.$cache_uri.$cache);
exit();
}
else
{
if (!file_exists($src))
{
$src = $document_path.$src;
}
$thumb = PhpThumbFactory::create($src);
$thumb->setOptions($options);
$thumb->adaptiveResize($w, $h);
$thumb->save($cache_path);
}
$thumb->show();
flush();