• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revision4658daef36db1d77553e63bea28db959c4aadd09 (tree)
Time2006-12-03 05:01:51
Authorhsur <hsur@1ca2...>
Commiterhsur

Log Message

use phpThumb() /w cache

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@510 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- a/trunk/NP_TrimImage/NP_TrimImage.php
+++ b/trunk/NP_TrimImage/NP_TrimImage.php
@@ -13,12 +13,18 @@
1313 // 0.8: supports gif
1414 // 0.9: doTemplateVar calls DB data for other PreItem Plugin
1515 // 0.9: change '&' to '&amp;'
16-// 1.1: NP_Paint supported.
16+// 1.1: NP_Paint support.
1717 // Security Fix.
18+// 2.0: use phpThumb() (http://phpthumb.sourceforge.net)
19+
20+define('NP_TRIMIMAGE_CACHE_MAXAGE', 86400 * 30); // 30days
21+
22+require_once(dirname(__FILE__).'/sharedlibs/sharedlibs.php');
23+require_once('phpthumb/phpthumb.functions.php');
24+require_once('phpthumb/phpthumb.class.php');
1825
1926 class NP_TrimImage extends NucleusPlugin
2027 {
21-
2228 function getName ()
2329 {
2430 return 'TrimImage';
@@ -26,7 +32,7 @@ class NP_TrimImage extends NucleusPlugin
2632
2733 function getAuthor ()
2834 {
29- return 'nakahara21';
35+ return 'nakahara21 + hsur';
3036 }
3137
3238 function getURL () {
@@ -34,7 +40,7 @@ class NP_TrimImage extends NucleusPlugin
3440 }
3541
3642 function getVersion () {
37- return '1.1';
43+ return '2.0';
3844 }
3945
4046 function supportsFeature($what)
@@ -51,7 +57,33 @@ class NP_TrimImage extends NucleusPlugin
5157 {
5258 return 'Trim image in items, and embed these images.';
5359 }
60+ function getEventList() {
61+ return array(
62+ 'PostAddItem',
63+ 'PostUpdateItem',
64+ 'PostDeleteItem',
65+ );
66+ }
67+
68+ function event_PostAddItem(&$data){
69+ $this->_clearCache();
70+ }
71+ function event_PostUpdateItem(&$data){ $this->_clearCache();
72+ }
73+ function event_PostDeleteItem(&$data){
74+ $this->_clearCache();
75+ }
76+ function _clearCache(){
77+ $phpThumb = new phpThumb();
78+ foreach($this->phpThumbParams as $paramKey => $paramValue ){
79+ $phpThumb->setParameter($paramKey, $paramValue);
80+ }
81+ $phpThumb->setParameter('config_cache_maxage', 1);
82+ $phpThumb->CleanUpCacheDirectory();
83+ //var_dump($phpThumb);
84+ }
5485
86+/*
5587 function instaii()
5688 {
5789 $ver_min = (getNucleusVersion() < $this->getMinNucleusVersion());
@@ -74,11 +106,30 @@ class NP_TrimImage extends NucleusPlugin
74106 $admin->pagefoot();
75107 return;
76108 }
77-
109+*/
78110 function init()
79111 {
112+ global $DIR_MEDIA;
80113 $this->fileex = array('.gif', '.jpg', '.png');
81114 $this->random = 1;
115+
116+ $this->phpThumbParams = array(
117+ 'config_document_root' => $DIR_MEDIA,
118+ 'config_cache_directory' => $DIR_MEDIA.'phpthumb/',
119+ 'config_cache_disable_warning' => true,
120+ 'config_cache_directory_depth' => 0,
121+ 'config_cache_maxage' => NP_TRIMIMAGE_CACHE_MAXAGE,
122+ 'config_cache_maxsize' => 10 * 1024 * 1024, // 10MB
123+ 'config_cache_maxfiles' => 1000,
124+ 'config_cache_source_filemtime_ignore_local' => false,
125+ 'config_cache_source_filemtime_ignore_remote' => true,
126+ 'config_cache_cache_default_only_suffix' => '',
127+ 'config_cache_prefix' => 'phpThumb_cache',
128+ 'config_cache_force_passthru' => true,
129+ 'config_max_source_pixels' => 3871488, //4Mpx
130+ 'config_output_format' => 'jpg',
131+ 'config_disable_debug' => true,
132+ );
82133 }
83134
84135 function doSkinVar($skinType, $amount = 10, $wsize = 80, $hsize = 80, $point = 0, $random = 0, $exmode = '')
@@ -122,6 +173,7 @@ class NP_TrimImage extends NucleusPlugin
122173 global $catid;
123174 if ($catid) $this->exquery .= ' and icat = ' . intval($catid);
124175 } elseif ($exmode == 'all') {
176+ // nothing
125177 } else {
126178 $spid_array = $spbid = $spcid = array();
127179 $spid_array = explode('/', $exmode);
@@ -133,17 +185,15 @@ class NP_TrimImage extends NucleusPlugin
133185 }
134186 $spbid = implode(',', $spbid);
135187 $spcid = implode(',', $spcid);
136- if ($spbid && $spcid) {
137- $this->exquery .= ' and ( iblog IN (' . $spbid . ') or icat IN (' . $spcid . ') )';
138- } elseif($spbid) {
188+ if($spbid) {
139189 $this->exquery .= ' and iblog IN (' . $spbid . ') ';
140- } elseif ($spcid) {
190+ }
191+ if($spcid) {
141192 $this->exquery .= ' and icat IN (' . $spcid . ') ';
142193 }
143194 }
144195 }
145196
146-
147197 $filelist = array();
148198 $this->imglists = array();
149199 $this->imgfilename = array();
@@ -221,20 +271,6 @@ class NP_TrimImage extends NucleusPlugin
221271 $this->imglists[] = array($imginfo, $iaid[0]);
222272 }
223273
224- function baseimageCreate($p,$imgtype)
225- {
226- switch ($imgtype) {
227- case 1:
228- return ImageCreateFromGif($p);
229- case 2:
230- return ImageCreateFromJpeg($p);
231- case 3:
232- return ImageCreateFromPng($p);
233- default:
234- return;
235- }
236- }
237-
238274 function doTemplateVar(&$item, $wsize=80, $hsize=80, $point=0, $maxAmount=0)
239275 {
240276 global $CONF;
@@ -299,80 +335,71 @@ class NP_TrimImage extends NucleusPlugin
299335
300336 function doAction($type)
301337 {
302- global $DIR_MEDIA;
303-
304- $tsize['w'] = intRequestVar('wsize') ? intRequestVar('wsize') : 80;
305- $tsize['h'] = intRequestVar('hsize') ? intRequestVar('hsize') : 80;
306- $point = requestVar('pnt');
307-
308- if (!requestVar('p')) 'No such file';
309- if (requestVar('p') == 'non') {
310- $im = @ImageCreate($tsize['w'], $tsize['h']) or die ("Cannnot Initialize new GD image stream");
311- $bgcolor = ImageColorAllocate($im, 0, 255, 255); //color index:0
312- // $strcolor = ImageColorAllocate($im,153,153,153); //color index:1
313- imagecolortransparent($im, $bgcolor);
314- // imageString($im, 1, 4, 0,'No images',$strcolor);
315- header ("Content-type: image/png");
316- ImagePng($im);
317- imagedestroy($im);
318- berak;
319- }
338+ $w = intRequestVar('wsize') ? intRequestVar('wsize') : 80;
339+ $h = intRequestVar('hsize') ? intRequestVar('hsize') : 80;
340+ $pnt = requestVar('pnt');
320341
321- $p = $DIR_MEDIA . requestVar('p'); //path
322- $p = realpath($p);
323- if( !$p ) return 'No such file';
324- if( strpos($p, $DIR_MEDIA) !== 0 ) return 'No such file';
325-
326342 switch ($type) {
327343 case 'draw':
328- list($imgwidth, $imgheight, $imgtype) = GetImageSize($p);
329-
330- if ($imgwidth / $imgheight < $tsize['w'] / $tsize['h']) { // height longer
331- $trimX = 0;
332- $trimW = $imgwidth;
333- $trimH = intval($tsize['h'] / $tsize['w'] * $imgwidth);
334- $trimY = intval(($imgheight - $trimH) / 2);
335- } else { // width longer
336- $trimY = 0;
337- $trimH = $imgheight;
338- $trimW = intval($tsize['w'] / $tsize['h'] * $imgheight);
339- $trimX = intval(($imgwidth - $trimW) / 2);
340- }
341-
342- if ($point == 'lefttop') {
343- $trimX = $trimY = 0;
344- }
345-
346- $im_r = $this->baseimageCreate($p,$imgtype);
347- $im = ImageCreateTrueColor($tsize['w'],$tsize['h']);
348- ImageCopyResampled( $im, $im_r, 0, 0, $trimX, $trimY, $tsize['w'], $tsize['h'], $trimW, $trimH);
349- switch ($imgtype) {
350- case 1:
351- header ("Content-type: image/gif");
352- Imagegif($im);
353- imagedestroy($im);
354- break;
355- case 2:
356- header ("Content-type: image/jpeg");
357- ImageJpeg($im);
358- imagedestroy($im);
359- break;
360- case 3:
361- header ("Content-type: image/png");
362- ImagePng($im);
363- imagedestroy($im);
364- break;
365- default:
366- return;
367- }
368- break;
369-
344+ $this->createImage(requestVar('p'), $w, $h, $pnt);
345+ break;
370346 default:
371347 return 'No such action';
372348 break;
373-//_=======
374349 }
375350 }
351+
352+ function createImage($p, $w, $h, $pnt){
353+ $phpThumb = new phpThumb();
354+ foreach($this->phpThumbParams as $paramKey => $paramValue ){
355+ $phpThumb->setParameter($paramKey, $paramValue);
356+ }
357+ $phpThumb->setParameter('w', $w);
358+ $phpThumb->setParameter('h', $h);
359+
360+ if ($p == 'non') {
361+ $phpThumb->setParameter('new', 'FFFFFF');
362+ } else {
363+ $phpThumb->setParameter('src', $p);
364+ $phpThumb->setParameter('zc', 1);
365+ if ($pnt == 'lefttop') {
366+ $phpThumb->setParameter('sx', 0);
367+ $phpThumb->setParameter('sy', 0);
368+ }
369+ }
370+
371+ // getCache
372+ $phpThumb->SetCacheFilename();
373+ if( file_exists($phpThumb->cache_filename) ){
374+ $nModified = filemtime($phpThumb->cache_filename);
375+ if( time() - $nModified < NP_TRIMIMAGE_CACHE_MAXAGE ){
376+ header('Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT');
377+ if (@serverVar('HTTP_IF_MODIFIED_SINCE') && ($nModified == strtotime(serverVar('HTTP_IF_MODIFIED_SINCE'))) && @serverVar('SERVER_PROTOCOL')) {
378+ header(serverVar('SERVER_PROTOCOL').' 304 Not Modified');
379+ return;
380+ }
381+ if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) {
382+ header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]));
383+ } elseif (eregi('\.ico$', $phpThumb->cache_filename)) {
384+ header('Content-Type: image/x-icon');
385+ }
386+ @readfile($phpThumb->cache_filename);
387+ return;
388+ }
389+ }
390+
391+ // generate
392+ $phpThumb->GenerateThumbnail();
393+
394+ // putCache
395+ if( !rand(0,20) ) $phpThumb->CleanUpCacheDirectory();
396+ $phpThumb->RenderToFile($phpThumb->cache_filename);
397+ chmod($phpThumb->cache_filename, 0666);
398+
399+ // to browser
400+ $phpThumb->OutputThumbnail();
401+ unset($phpThumb);
402+ }
376403
377404 function canEdit()
378405 {
@@ -404,6 +431,5 @@ class NP_TrimImage extends NucleusPlugin
404431 }
405432 return addLinkParams($link, $extra);
406433 }
407-
408434 }
409-?>
\ No newline at end of file
435+?>
--- /dev/null
+++ b/trunk/NP_TrimImage/sharedlibs/phpthumb/docs/phpthumb.changelog.txt
@@ -0,0 +1,1225 @@
1+//////////////////////////////////////////////////////////////
2+/// phpThumb() by James Heinrich <info@silisoftware.com> //
3+// available at http://phpthumb.sourceforge.net ///
4+//////////////////////////////////////////////////////////////
5+
6+、 = structure change or important new feature
7+* = less important new feature or change
8+
9+v1.7.5 - October 03, 2006
10+ 、 Deprecated parameters "err", "file", "goto"
11+ 、 Added broad cache directory feature (see phpThumb.config.php
12+ "cache_directory_depth") to spread cache files across many
13+ directories for improved performance and ability to store
14+ very large numbers (30000+) of cached files
15+ (thanks despoixリopenxtrem*com)
16+ 、 phpThumb now follows HTTP redirects (status=302) to new
17+ HTTP image URLs (configurable: config_http_follow_redirect)
18+ (thanks shannahリsfu*ca)
19+ 、 Added "rot" (ROTate) filter which is similar to "ra" parameter
20+ but now allows rotation of output of other filters (for
21+ example, rotate image after fltr[]=mask is applied)
22+ (thanks markリwoodjoint*ca)
23+ 、 Added WBMP output support (built-in GD or via ImageMagick)
24+ (code was already mostly present, just was not allowed format)
25+ 、 [#1567113] "wmi" filter now accepts both x and y margins
26+ and can be in pixels or percent of thumbnail dimensions
27+ (thanks squidlibertyリusers*sourceforge*net)
28+ * "hist" filter now accepts both X and Y margins
29+ * Added config variables: config_http_fopen_timeout = 10;
30+ config_http_follow_redirect = true
31+ * Changed MIME type for WBMP to image/vnd.wap.wbmp
32+ * Bugfix: Check for GD format support before attempting output
33+ * Bugfix: Opening HTTP source images with URL query parameters
34+ was broken (eg: http://host/show?id=123)
35+ (thanks ivo*beckersリinfopractica*nl)
36+
37+
38+v1.7.4 - August 17, 2006
39+ 、 Improved version of /demo/phpThumb.demo.showpic.php uses
40+ phpThumb.php so any filters can be applied, as well as
41+ resized image popups.
42+ New file: /demo/javascript_api.js
43+ Uses Javascript API by James Austin <jamesdozリhotmail*com>
44+ (http://aspandjavascript.co.uk/javascript/javascript_api/)
45+ 、 Added "sfn" (Source Frame Number) parameter to specify
46+ source frame in multi-frame/multi-page source formats, such
47+ as GIF, TIFF, PDF, etc (thanks despoixリopenxtrem*com)
48+ 、 Added "dpi" (Dots Per Inch) parameter to specify
49+ rasterising resolution for vector source formats (PDF, WMF)
50+ (requires ImageMagick) (thanks despoixリopenxtrem*com)
51+ * Added /demo/phpThumb.demo.object.simple.php
52+ * Added debug points inside GenerateThumbnail
53+ * Explicit error message for unsupported PDF source images
54+ * Bugfix: SafeURLread broken with GETstring parameters in
55+ fsockopen mode
56+ * Bugfix: [#1540523] CleanUpCacheDirectory() does not delete
57+ files as expected (thanks patricksleeリusers*sourceforge*net)
58+ * Bugfix: added useful error message when no source specified
59+ in object mode (thanks infoリdoepud*co*uk)
60+ * Bugfix: timeout value ignored in URLreadFsock()
61+ * Bugfix: timeout missing in SafeURLread CURL part
62+ * Bugfix: ImageMagick now checked with --version (not -version)
63+ * Bugfix: better ImageMagick (numeric) version number matching
64+ * Bugfix: noGD errors showing up when GD imagecreate functions
65+ fail and ImageMagick not available
66+ (thanks caseyyリgmail*com)
67+ * Bugfix: "-thumbnail" parameter not present in older versions
68+ of ImageMagick, now using -resize if -thumbnail unavailable
69+ (thanks atombomb96リbtopenworld*com)
70+ * Bugfix: "-resize" parameter requires explicit dimensions
71+ ("100x100" instead of "100x") in older ImageMagick versions
72+ (thanks atombomb96リbtopenworld*com)
73+ * Bugfix: phpThumb crashed with no output if ImageMagick failed
74+ to resize but output image larger than max_source_pixels
75+ (thanks atombomb96リbtopenworld*com)
76+ * Bugfix: phpThumb might die with no output on some large source
77+ images when ImageMagick unavailable.
78+ (thanks atombomb96リbtopenworld*com)
79+
80+
81+v1.7.3 - July 11, 2006
82+ * Now returns useful message for HTTP sources if 404-file-
83+ not-found (or similar) errors occur
84+ * Added new fsockopen() section in SafeURLread()
85+ * Removed PNG alpha warning for IE 7 (alpha PNGs now work)
86+ * Bugfix: ImageMagick failing version check and dumping text
87+ output (thanks infoリdevsystem*net)
88+ * Bugfix: curl_exec failing with text output
89+ (thanks infoリdevsystem*net)
90+ * Bugfix: workaround for PHP Bug #36102 (fopen(http) crash
91+ in PHP v4.4.2
92+ * Bugfix: "Unknown image type identified by..." problem when
93+ opening http:// source images
94+ (thanks webmasterリdanceage*com)
95+
96+
97+v1.7.2 - June 22, 2006
98+ 、 [#1256693] Added $this->exif_raw_data which is returned
99+ data from exif_read_data() on source image.
100+ Requires PHP v4.2.0+ (thanks tebiリusers*sourceforge*net)
101+ 、 Added $this->outputImageData and RenderOutput() to allow
102+ easy outputting of thumbnail data to a database or such.
103+ Call RenderOutput() instead of RenderToFile() and then
104+ access raw data in $this->outputImageData
105+ (thanks r*cremerリswitch*nl)
106+ 、 Added 'crop' filter, which is applied after resizing (as
107+ opposed to sx,sy,sw,sh which are before resizing)
108+ (thanks scottリscottjehl*com)
109+ * Enable creating new images with PATH_INFO style call
110+ (thanks edenリinstyleit*com*au)
111+ * Added warning message to encourage users not to use
112+ full HTTP paths for "src" parameter
113+ * Added fallback 'preg_quote' to phpthumb.functions.php in
114+ case your PHP installation does not have preg_* functions
115+ (thanks mortenリemeskay*dk)
116+ * Added fallback 'imagesavealpha' if GD < v2.0.1
117+ (thanks oliver*heegerリweb*de)
118+ * Added fallback 'imagealphablending' if GD < v2.0.1
119+ (thanks oliver*heegerリweb*de)
120+ * Added 'nocache' parameter that suppresses writing to cache
121+ file, but only if high_security_enabled is set
122+ (thanks federicoリdonelleschi*com)
123+ * Attempt to detect supported ImageMagick features
124+ (thanks simonリjapancentre*com)
125+ * Added temp dir detection to phpThumb.demo.check.php
126+ * Added ImageMagick dir to phpThumb.demo.check.php
127+ * Added ImageMagick features to phpThumb.demo.check.php
128+ * Default (config_allow_src_above_docroot = true) when PHP
129+ running in "cli" mode (thanks flobeeリgmail*com)
130+ * Bugfix: [#1470791] 'iar' not working properly with
131+ ImageMagick (thanks w1xリusers*sourceforge*net)
132+ * Bugfix: [#1498564] illegal characters in cache filenames
133+ (thanks carl-evertリusers*sourceforge*net)
134+ * Bugfix: 'sx','sy','sw','sh','zc' cache parameters broken
135+ (thanks federicoリdonelleschi*com)
136+ * Bugfix: 'config_max_source_pixels' incorrectly handled
137+ (thanks oliver*heegerリweb*de)
138+ * Bugfix: 'aoe' not working properly
139+ (thanks w1xリusers*sourceforge*net)
140+ * Bugfix: setParameter() was broken for arrays
141+ * Bugfix: setSourceFilename() wasn't setting 'src'
142+ * Bugfix: suppress stat()-related file permission
143+ notices (thanks lanceリmainecoastdesign*com)
144+ * Bugfix: image format now initialized during ErrorImage()
145+ * Bugfix: domain matching now case-insensitive
146+ * Bugfix: some versions of ImageMagick not detected
147+ (thanks arvidリfys*ku*dk)
148+ * Bugfix: sometimes no image returned in safe_mode
149+ (thanks bkainersリgmail*com)
150+ * Bugfix: 'far' not always handled correctly
151+ (thanks matthew*newtonリrealworldweb*com)
152+ * Bugfix: PATH_INFO method not working if no filters specified
153+ (thanks jjimenezリpracticaldata*com)
154+ * Bugfix: first (internal) call to ImageMagickVersion() failed
155+ under Windows
156+ * Bugfix: Images source-cropped AND resized with ImageMagick were
157+ wrong size (cropped size, not resized size)
158+ (thanks joao*saleiroリwebfuel*pt)
159+ * Bugfix: stat() warnings in CleanUpCacheDirectory()
160+ (thanks christianリhss-haage*de)
161+ * Bugfix: $PHPTHUMB_DEFAULTS not working when no other processing
162+ parameters specified (thanks tbittnersリcox*net)
163+
164+
165+v1.7.1 - March 16, 2006
166+ * /demo/phpThumb.demo.check.php now checks:
167+ - server software
168+ - local and master config values (with ini_get and
169+ get_cfg_var respectively) (thanks nEUTRonリgmx*tm)
170+ - existance of assorted PHP functions and explains their
171+ importance
172+ * Bugfix: config_error_die_on_error now defaults to FALSE to
173+ prevent object-mode errors dying in an error image
174+ (thanks moshリtobt*de; riteshgupta1974リgmail*com)
175+ * Bugfix: setParameter() now handles array parameters (such
176+ as 'fltr') by appending $value to $parameter
177+ * Bugfix: /demo/phpThumb.demo.check.php incorrect CURL value
178+ under PHP5 (thanks nEUTRonリgmx*tm)
179+ * Bugfix: [#1439110] Limit fread() calls to 8kB
180+ (see http://bugs.php.net/bug.php?id=35859)
181+ (thanks andig2リusers*sourceforge*net)
182+ * Bugfix: Prevent RenderToFilename() from trying to render
183+ to URLs (thanks Tim*Masseyリitrm*co*uk)
184+ * Bugfix: [#1438657] missing path in phpThumbURL()
185+ (thanks terracesリusers*sourceforge*net)
186+ * Bugfix: zoomcrop was broken for non-square output
187+ (thanks alisonリsemidivine*com, federicoリdonelleschi*com)
188+ * Bugfix: suppress error messages when stat access to temp
189+ dir is disabled (thanks rfineリvnuinc*com)
190+ * Bugfix: ImageMagick processing was broken for source
191+ images of types not supported by GetImageSize
192+ (thanks rfineリvnuinc*com)
193+
194+v1.7.0 - February 15, 2006
195+ 、 ImageMagick output is used directly far more frequently
196+ for much improved speed and minor quality improvement.
197+ 、 ImageMagick now processes most of the image filters if
198+ possible (will fall back to GD methods if unavailable)
199+ 、 GD support is now optional if ImageMagick is installed.
200+ Known limitations include:
201+ - no support for HTTP source images
202+ - ICO output is buggy (in some ImageMagick versions)
203+ - most &fltr[] filters don't work at all
204+ - 'ar', 'ra', 'far' don't work
205+ 、 Added output support for ICO (icon) format (&f=ico).
206+ Currently only supports single-image icons, but multi-
207+ resolution support may be added in future versions
208+ New file: phpthumb.ico.php
209+ 、 Added output support for BMP (bitmap) format (&f=bmp).
210+ Currently only supports 24-bit RGB format (for simplicity)
211+ 、 Added new configuration & compatability checker
212+ New file: demo/phpThumb.demo.check.php
213+ * ImageMagick-generated thumbnails now have extra hidden
214+ contents (EXIF data, etc) stripped (by using -thumbnail
215+ instead of -resize) resulting in smaller filesizes
216+ * Added background fill color, opacity and extent options to
217+ 'wmt' filter (thanks craigリpc-fanatics*com)
218+ * Added metacharacter (^*) support for 'wmt', currently:
219+ source filesize in bytes (^Fb), kB (^Fk), MB (^Fm),
220+ source image width (^X), source image height (^Y),
221+ thumbnail width (^x), thumbnail height (^y) and caret (^^)
222+ (Feature Request #1357815)
223+ (thanks ticklemeozmoリusers*sourceforge*net)
224+ * Moved ImageDestroy call from OutputThumbnail to end of
225+ phpThumb.php to allow multiple calls to OutputThumbnail
226+ * Added config_http_user_agent for site with browsersniffers
227+ (thanks redrobリgmail*com)
228+ * Added $PHPTHUMB_CONFIG['disable_pathinfo_parsing'] (default
229+ false) which disables parsing $_SERVER[PATH_INFO] for
230+ parameters. If you want to parse PATH_INFO, set to false
231+ * Added $PHPTHUMB_CONFIG['disable_imagecopyresampled'] (default
232+ false) which replaces ImageCopyResampled with
233+ ImageCopyResampleBicubic for buggy PHP-GD versions
234+ (thanks g*pelagattiリnetface*it)
235+ * Added $PHPTHUMB_CONFIG['cache_prefix'] to allow sharing of
236+ cache files across virtual servers (Feature Request #1395332)
237+ (thanks doggyfrリusers*sourceforge*net)
238+ * Added $PHPTHUMB_CONFIG['disable_onlycreateable_passthru'] with
239+ default=true (increased speed) to allow direct passthru of
240+ images that don't have GD support. (Feature Request #1396446)
241+ (thanks zedboyリusers*sourceforge*net)
242+ * Removed $PHPTHUMB_CONFIG['cache_differentiate_offsite'] because
243+ it is now automatically tied in with nooffsitelink_enabled
244+ (thanks doggysworldリlibertysurf*fr)
245+ * Removed phpThumb.demo.cacheconvert2.php
246+ * Debug messages are now passed back from filters
247+ * $PHPTHUMB_CONFIG['cache_source_filemtime_ignore_remote'] now
248+ defaults to true for much-improved cached performance
249+ (thanks redrobリgmail*com)
250+ * $PHPTHUMB_CONFIG['cache_differentiate_offsite'] now defaults
251+ to false
252+ * Added $PHPTHUMB_DEFAULTS['ar']='x' to phpThumb.config.php.default
253+ * Added ImageDestroy($this->gdimg_source) to GenerateThumbnail()
254+ to save memory before applying image filters
255+ * gd_info() no longer member of phpthumb_functions
256+ * cache files now default to using SERVER_NAME without 'www.'
257+ * phpUnsharpMask::applyUnsharpMask() should be faster under PHP5 by
258+ using ImageFilter(IMG_FILTER_GAUSSIAN_BLUR) when radius==1
259+ * Added alternate CURL method for HTTP source images if
260+ allow_url_fopen is disabled (thanks webweberリmotiondraw*com)
261+ * Replaced $this->osslash with DIRECTORY_SEPARATOR constant
262+ * Bugfix: [#1398327] 'new' got broken (1x1 images)
263+ * Bugfix: [#1412552] HTTP source images with special characters were
264+ not getting urlencoded
265+ * Bugfix: ImageSaveAlpha errors on GD v2.0.0
266+ * Bugfix: phpThumbDebug now entirely disabled if high_security=true
267+ * Bugfix: source images with transparency lost transparency when
268+ rotated (thanks roalklリyahoo*com)
269+ * Bugfix: square source images were not resized when only (w|h)(p|l)
270+ parameters passed
271+ * Bugfix: source images are passed through unmodified in more cases
272+ * Bugfix: ImageMagick not used on systems where it exists outside
273+ defined open_basedir
274+ * Bugfix: ImageMagickVersion() now returns correct versionstring
275+ * Bugfix: ImageMagick warnings no longer cause ImageMagick to fail
276+ * Bugfix: ErrorImage no longer fatal to phpThumbDebug
277+ * Bugfix: "Array to string conversion" in foreach($a as $v) loops
278+ (thanks zeeshanリtargetedmedia*co*uk)
279+ * Bugfix: safe mode warnings in ImageCreateFromStringReplacement
280+ (thanks adminリalex-home*net)
281+ * Bugfix: nooffsitelink broken if !nooffsitelink_require_refer
282+ (thanks depronリgmx*net)
283+ * Bugfix: phpThumb failed when magic_quotes_runtime=true
284+ (thanks stansawyerリyahoo*com)
285+ * Bugfix: several issues with HTTP image sources
286+ (thanks redrobリgmail*com)
287+ * Bugfix: phpThumb_tempnam() would return incomplete temp filenames
288+ under Windows, which may result in orphaned zero-byte temp files
289+ in C:\ if multiple drives exist
290+
291+v1.6.2 - November 24, 2005
292+ 、 Animated GIF output is now possible if ImageMagick is
293+ available and no filters (other than resize) are applied
294+ (thanks brandenbassリgmail*com for idea)
295+ * Added $PHPTHUMB_CONFIG['cache_force_passthru'] to work
296+ around cached-image-only-works-second-time issue
297+ (thanks yakoリ11y11*com)
298+ * Bugfix: black borders on some image edges
299+ (thanks atelierリdelirius*ch && chuckリcatalyststudio*com)
300+ * Bugfix: uncaught PHP warning in RenderToFile DebugMessage
301+ * Bugfix: allow phpThumbDebug in noGD PHP installations
302+ * Bugfix: 'hash' warning in high_security mode
303+ (thanks bernhardリwtf*at)
304+ * Bugfix: non-TTF rotated text watermarks now work (unrotated)
305+ with no warnings if ImageRotate is unavailable
306+ (thanks aparviaiリusers*sourceforge*net)
307+
308+v1.6.1 - August 26, 2005
309+ 、 Filters now use GD functions where available (using
310+ ImageFilter, only available in PHP v5.0.0+ with bundled
311+ version of GD). Enabled for: colorize, negative,
312+ grayscale, brightness, contrast, gaussian blur, selective
313+ blur, mean removal (thanks donlaurリmac*com)
314+ 、 Added config_prefer_imagemagick (defaults=true)
315+ 、 Added phpthumb_filters::Grayscale() 'gray'
316+ 、 Added phpthumb_filters::ReduceColorDepth() 'rcd'
317+ 、 Added phpthumb_filters::Brightness() 'brit'
318+ 、 Added phpthumb_filters::Contrast() 'cont'
319+ 、 Added phpthumb_filters::Saturation() 'sat'
320+ 、 Added phpthumb_filters::EdgeDetect() 'edge' [PHP5 only]
321+ 、 Added phpthumb_filters::BlurGaussian() 'gblr' [PHP5 only]
322+ 、 Added phpthumb_filters::BlurSelective() 'gblr' [PHP5 only]
323+ 、 Added phpthumb_filters::MeanRemoval() 'mean' [PHP5 only]
324+ 、 Added phpthumb_filters::Smooth() 'smth' [PHP5 only]
325+ * New timing debug info in phpThumbDebug
326+ * Added config_cache_differentiate_offsite
327+ * config_die_on_error now defaults to false
328+ * ResolveSource works better
329+ * cache filenames with 'fltr' parameters have changed
330+ * Filters now skip processing if amount=0 or similar
331+ * [#1263051] 'far' now accepts L,R,T,B,C as values giving
332+ alignment of left/right/top/bottom/center respectively.
333+ Old value of '1' defaults to centered
334+ (thanks webgrappaリusers*sourceforge*net)
335+ * Bugfix: RenderToFile() now fails properly when output format
336+ is unknown
337+ * Bugfix: PNG transparency wasn't working with 'far'
338+ * Bugfix: source images with EXIF thumbnails that differ in
339+ aspect ratio no longer use EXIF thumbnails as source unless
340+ no other options exist
341+ * Bugfix: setting 'src' with setParameter now invokes
342+ setSourceFilename to properly set $this->sourceFilename
343+ (thanks Gazou)
344+ * Bugfix: 'zc' had poor quality when used with ImageMagick
345+ * Bugfix: 'aoe' parameter broken when not using ImageMagick
346+ (thanks frankieali4リhotmail*com)
347+ * Bugfix: fixed issue with symbolic links
348+ (thanks hornet136リgmail*com)
349+ * Bugfix: config_max_source_pixels now defaults to same
350+ calculation as used in phpThumb.config.php
351+ (thanks vukshaリhotmail*com)
352+ * Bugfix: Offsite cached thumbnails no longer use unique
353+ referer (now either nothing or "_offsite")
354+ (thanks swaayeリyahoo*com)
355+ * Bugfix: "Unknown image type identified by ??ph? errors
356+ in some installations (thanks frankieali4リhotmail*com)
357+
358+v1.6.0 - July 18, 2005
359+ 、 Included new file phpThumb.demo.random.php to select a
360+ random image from a specified folder, optionally only
361+ landscape and/or portrait and/or square images, and to
362+ display it to phpThumb.php
363+ (thanks mikeリgdaymate*nl)
364+ 、 Added /docs/phpthumb.faq.txt
365+ 、 Added /demo/readme.demos.txt
366+ 、 Added 'wp', 'hp', 'wl', 'hl', 'ws', 'hs' parameters for
367+ width and height of portrait, landscape and square
368+ images. This allows you to display any image aspect
369+ ratio at the size you want without knowing ahead of time
370+ whether the image is wide or tall.
371+ (thanks mikeリgdaymate*nl)
372+ 、 phpThumb.php can now also be called by passing parameters
373+ in $_SERVER['PATH_INFO']. Please see phpthumb.readme.txt
374+ (thanks javierリguegue*net)
375+ 、 MySQL data pulling configuration moved from phpThumb.php
376+ to phpThumb.config.php
377+ * "file" and "goto" parameters are now disabled by
378+ default (configurable in phpThumb.config.php but not
379+ recommended)
380+ * Cached files are now used from first instance, avoiding
381+ call to OutputThumbnail and preventing browser-side
382+ cache failure
383+ * Added config_allow_src_above_docroot (default=false) to
384+ prevent browsing filesystem outside document_root
385+ (thanks davidリint0x80*com)
386+ * Added config_allow_src_above_phpthumb (default=true) to
387+ prevent access to files except in subdirectories of
388+ phpThumb installation (thanks davidリint0x80*com)
389+ * Added setParameter() and getParameter() functions
390+ (thanks werner*kraussリhallstatt*net)
391+ * SafeBackTick() renamed to SafeExec() and all execution
392+ functions are tried (exec, shell_exec, system, passthru)
393+ are tried in case one or more are disabled
394+ (thanks bkainersリgmail*com)
395+ * config_output_allow_enlarging has been removed from
396+ phpthumb.class.php, and 'output_allow_enlarging' has
397+ been removed from phpThumb.config.php
398+ * New default detection method for
399+ $PHPTHUMB_CONFIG['document_root']
400+ * Bugfix: inconsitant handling of boolean parameters
401+ passed "0" (isset vs !empty()) (thanks manniリzapto*de)
402+ * Bugfix: text watermarks now support multiple lines
403+ (thanks hanno*vandenbergリhccnet*nl)
404+ * Bugfix: suppress error message in
405+ ImageCreateFromStringReplacement()
406+ (thanks srimandadapuリyahoo*com)
407+ * Bugfix: 'aoe' was ignored in object mode
408+ (thanks tonyリnylink*com)
409+ * Bugfix: ResolveFilenameToAbsolute() failed on non-
410+ existant filenames (file to be written, for example)
411+ * Bugfix: 'aoe' parameter was ignored in cache filename
412+ (thanks tonyリnylink*com)
413+ * Bugfix: non-TTF watermark text had inverted opacity
414+ scale. All 'wmt' is now 100=opaque, 0=transparent
415+ (thanks mailリmmjaeger*com)
416+ * Bugfix: cache file failed if document_root had
417+ trailing slash. (thanks lovingloboリgmail*com)
418+ * Bugfix: [#1219422] Cache filename structure modified to
419+ avoid excessively long filenames (cache filenames are
420+ now limited to 142 characters + length of
421+ $_SERVER['SERVER_NAME'])
422+ (thanks trungieリusers*sourceforge*net)
423+ * Bugfix: [#1211729] phpThumb.php fails to locate
424+ phpThumb.config.php if the two files are in the same
425+ directory but phpThumb.php is run through a sym link.
426+ (thanks allanbushリusers*sourceforge*net)
427+
428+v1.5.4 - May 27, 2005
429+ * Security issue with passthrough addressed
430+ (thanks davidリint0x80*com)
431+ * 'wmt' now reads TTF fonts from the config font
432+ directory, or from anywhere if a path is specified in
433+ the font filename
434+ (thanks mailリmmjaeger*com)
435+ * Changed default error_die_on_source_failure to true in
436+ phpThumb.config.php
437+ * Bugfix: Firefox (possibly other browsers) did not like
438+ the new (faster) cache retrieval method with Location
439+ header redirection if the cached filename does not have
440+ a recognized filename extension (.jpeg, .png, .gif).
441+ Cached images have therefore been renamed from *_jpeg to
442+ *.jpeg and the _qXX parameter has been removed for PNG
443+ and GIF output. Please use the included cache renamer:
444+ /demo/phpThumb.demo.cacheconvert2.php
445+ (thanks mailリmmjaeger*com)
446+ * Bugfix: Changed "Content-type" to "Content-Type" in all
447+ header calls
448+ * Bugfix: 'wmt' text opacity was broken
449+ (thanks mstuhuリweb*de)
450+ * Bugfix: variable name typo in phpThumb.demo.object.php
451+ (thanks mbリmarko-bischof*de)
452+ * Bugfix: no GD support for source image format now
453+ reported as such for remote images
454+ (thanks andgu842リstudent*liu*se)
455+ * Bugfix: very narrow images no longer produce Invalid
456+ Image Dimensions error (thanks mailリmmjaeger*com)
457+
458+v1.5.3 - May 4, 2005
459+ 、 Added new filters:
460+ - 'wb' (White Balance) [ex: &fltr[]=wb|<c>]
461+ where <c> is the target hex color to white balance
462+ on, this color is what "should be" white, or light
463+ gray. The filter attempts to maintain brightness so
464+ any gray color can theoretically be used. If <c> is
465+ omitted the filter guesses based on brightest pixels
466+ in each of RGB
467+ 、 Cached files are used by a Location header instead of
468+ being passed through phpThumb.php using readfile
469+ (thanks newtnリthrillnerds*com)
470+ * Added 'cache_source_filemtime_ignore_local' and
471+ 'cache_source_filemtime_ignore_remote' configurations
472+ to ignore source modification and/or removal
473+ (thanks raynerapeリgmail*com)
474+ * Added 'md5s' parameter, which is the MD5 hash of the
475+ source image -- if this parameter is passed with the
476+ hash of the source image then the source image is not
477+ checked for existance or modification and the cached
478+ file is used (if available). If 'md5s' is passed an
479+ empty string then phpThumb.php dies and outputs the
480+ correct MD5 hash value. This parameter is the single-
481+ file equivalent of 'cache_source_filemtime_ignore_*'
482+ configuration paramters (thanks raynerapeリgmail*com)
483+ * Added /demo/phpThumb.demo.object.php
484+ * Unused parameter 'bgt' removed
485+ * Added empty /cache/source/ directory to distribution
486+ * Added /demo/ and /docs/ and /fonts/ directories
487+ * Set default config_use_exif_thumbnail_for_speed = false
488+ * Bugfix: Wrapped output buffering around all
489+ include_once calls to prevent headers getting sent
490+ accidentally
491+ * Bugfix: md5_file and imagecolorallocatealpha calls
492+ were undefined under PHP v4.1.x (thanks tomリemile*com)
493+ * Bugfix: default 'f' parameter ('jpeg') overrode
494+ config_output_format in object mode
495+ (thanks mailリmmjaeger*com)
496+ * Bugfix: suppressed error message for IIS shell_exec
497+ errors (thanks tomリemile*com)
498+ * Bugfix: Added PHP version check for stream_set_timeout
499+ for HTTP sources (thanks raynerapeリgmail*com)
500+ * Bugfix: overlay margins of 0.5-1.0 cause invalid image
501+ dimensions error (thanks mailリmmjaeger*com)
502+ * Bugfix: underlay margins were not working
503+ (thanks mailリmmjaeger*com)
504+ * Bugfix: [#1187735] EXIF thumbnails were incorrectly
505+ output to the browser directly if requested thumbnail
506+ exactly matched EXIF dimensions
507+ (thanks rebootリusers*sourceforge*net)
508+
509+v1.5.2 - April 20, 2005
510+ 、 phpThumb.config.php is renamed to
511+ phpThumb.config.php.default to prevent accidental
512+ overwriting. Please migrate your old settings to the new
513+ file, delete your old config and rename the default to
514+ phpThumb.config.php
515+ 、 Added new filters:
516+ - 'blur' (Blur) [ex: &fltr[]=blur|<radius>]
517+ where (0 < <radius> < 25) (default = 1)
518+ (thanks thoensiリnetcom*no for code)
519+ - 'hist' (Histogram)
520+ [ex: &fltr[]=hist|<b>|<c>|<w>|<h>|<a>|<o>|<m>]
521+ Where <b> is the color band(s) to display, from back
522+ to front (one or more of "rgba*" for Red Green Blue
523+ Alpha and Grayscale respectively);
524+ <c> is a semicolon-seperated list of hex colors to
525+ use for each graph band (defaults to FF0000, 00FF00,
526+ 0000FF, 999999, FFFFFF respectively);
527+ <w> and <h> are the width and height of the overlaid
528+ histogram in pixels, or if <= 1 then percentage of
529+ source image width/height;
530+ <a> is the alignment (same as for "wmi" and "wmt");
531+ <o> is opacity from 0 to 100;
532+ <m> is the edge (and inter-tile) margin in percent
533+ - 'over' (OVERlay/underlay image) overlays an image on
534+ the thumbnail, or overlays the thumbnail on another
535+ image (to create a picture frame for example)
536+ [ex: &fltr[]=over|<i>|<u>|<m>|<o>]
537+ where <i> is the image filename; <u> is "0" (default)
538+ for overlay the image on top of the thumbnail or "1"
539+ for overlay the thumbnail on top of the image; <m> is
540+ the margin - can be absolute pixels, or if < 1 is a
541+ percentage of the thumbnail size [must be < 0.5]
542+ (default is 0 for overlay and 10% for underlay);
543+ <o> is opacity (0 = transparent, 100 = opaque)
544+ (thanks raynerapeリgmail*com, shabazz3リmsu*edu)
545+ - 'gray' (GRAYscale) [ex: &fltr[]=gray]
546+ is an alias to 100% desaturation
547+ * New configuration 'cache_source_directory' allows the
548+ unprocessed source image to be cached when source is
549+ HTTP or from a database (thanks raynerapeリgmail*com)
550+ * Added 'cache' subdirectory to phpThumb distribution
551+ since this is the default location for the cache
552+ folder.
553+ * Default value for config_error_die_on_source_failure
554+ changed to true (thanks shabazz3リmsu*edu)
555+ * Added checks to make sure $this->gdimg_output is a
556+ resource before allowing calls to RenderToFile or
557+ OutputThumbnail
558+ * Better error messages when phpThumb.config.php missing
559+ * Bugfix: watermark overlay margins were wrong
560+ * Bugfix: 'lvl' filter no longer processes if not needed
561+ * Bugfix: off-server thumbnail error message was wrong
562+ * Bugfix: several PHP safe mode fixes
563+ (thanks virginiaリalertbutnotalarmed*com)
564+ * Bugfix: cache filenames broken for filter parameters
565+ with paths (thanks srcericリusers.sourceforge.net)
566+
567+v1.5.1 - April 06, 2005
568+ * Added some security upgrades:
569+ - 'config_*' parameters cannot be passed by GETstring
570+ - 'config_nooffsitelink_require_refer' is a new option
571+ (disabled by default) that only allows calls to
572+ phpThumb() from a refering domain listed in
573+ 'config_nooffsitelink_valid_domains'
574+ - disallowed paramters now generate an error image if
575+ present in the GETstring
576+ - 'high_security_enabled' if set to true enabled new
577+ mode of verification, and requires a small function
578+ to generate a hash for calls to phpThumb:
579+ echo '<img src="'.phpThumbURL('src=pic.jpg&w=50').'">';
580+ This function is supplied at the bottom of
581+ phpThumb.config.php (thanks paulリstonie*co*uk)
582+ 、 Added new parameter "new" (phpThumb.php only) which can
583+ create a new image without using "src" parameter. Set
584+ "&new=<b>|<o>" where <b> is the background hex color,
585+ <o> is (optional) opacity (0=transparent, 100=opaque).
586+ (thanks mailリmmjaeger*com)
587+ 、 Added new filters:
588+ - 'sep' (Sepia) [ex: &fltr[]=sep|<value>|<color>]
589+ where <value> is a number between 0 and 100 for the
590+ amount of colorization (default=50), and <color> is
591+ the hex color to colorize to (default=A28065).
592+ (thanks mailリmmjaeger*com)
593+ - 'lvl' (Levels) [ex: &fltr[]=lvl|<channel>|<min>|<max>
594+ where <channel> can be one of 'r', 'g', 'b', 'a' (for
595+ Red, Green, Blue, Alpha respectively), or '*' for all
596+ channels based on average grayscale value (default).
597+ <min> and <max> are the clip points for the levels
598+ (range = 0-255) and are set to clip 0.1% of each end
599+ by default. Use -1 for min and/or max to invoke auto-
600+ detect mode. Using default parameters (&fltr[]=lvl)
601+ is similar to Auto Contrast in Adobe Photoshop.
602+ * Bugfix: Image MIME header was incorrect for cached
603+ images.
604+ * Bugfix: Cache was broken for images pulled from a
605+ database in phpThumb.php
606+ (thanks dragutin*cvetkovicリdragontech-ltd*com)
607+ * Bugfix: Hotlink/Offsite prevention was broken when
608+ image was already cached.
609+ * Bugfix: ImageMagick path was incorrect in some cases
610+ (thanks joshgリtwcny*rr*com)
611+ * Bugfix: ProportionalResize() in phpthumb.functions.php
612+ had a broken check for default values
613+ (thanks Bert*Claeysリarinso*com)
614+ * Bugfix: transparency now preserved for GIF & PNG input
615+ (thanks tristanリcyrax*ch)
616+ * Bugfix: transparency now supported for GIF output
617+ (thanks j_ivanovリabv*bg)
618+ * Bugfix: alpha transparency could be lost in ApplyMask()
619+ (thanks analyzerxリgmail*com)
620+ * Bugfix: errors on 16/32-bit BMPs
621+ (thanks mattリhellstrominc*com)
622+ * Bugfix: Added datestamp to cached filenames for remote
623+ (HTTP) files, and better warning for caching
624+ (thanks a*gambinoリabramo*it)
625+ * Faster BMP parsing (thanks sgeppertリmail*utexas*edu)
626+ * Added 'error_die_on_source_failure' configuration to
627+ allow invalid source images to show an error rather
628+ than output unmodified source image.
629+ (thanks mindpixelリgmail*com)
630+ * Added $phpThumb->fatalerror which will contain the
631+ text of the fatal error if 'error_die_on_error' is
632+ false. (thanks mindpixelリgmail*com)
633+
634+v1.5.0 - February 4, 2005
635+ * Added new filter parameter 'fltr' that is an array and
636+ can apply multiple effects in sequence. Current filters
637+ that can be called are:
638+ - 'gam' (Gamma Correction) [ex: &fltr[]=gam|<value>]
639+ where <value> can be a number >0 to 10+ (default 1.0)
640+ - 'ds' (DeSaturate) [ex: &fltr[]=ds|<value>]
641+ where <value> is a number between zero (no change)
642+ and 100 (complete desaturation -- grayscale), or it
643+ can be a negative number for saturation boost.
644+ (thanks mailリmmjaeger*com)
645+ - 'clr' (Colorize) [ex: &fltr[]=clr|<value>|<color>]
646+ where <value> is a number between 0 and 100 for the
647+ amount of colorization, and <color> is the hex color
648+ to colorize to. (thanks mailリmmjaeger*com)
649+ - 'neg' (Negative) [ex: &fltr[]=neg]
650+ inverts the color
651+ - 'th' (ThresHold) [ex: &fltr[]=th|<val>] (range 0-255)
652+ every grayscale pixel brighter than <val> is set to
653+ white, every darker pixel is set to black
654+ (thanks mailリmmjaeger*com)
655+ - 'usm' (UnSharpMask) [ex: &fltr[]=usm|<a>|<r>|<t>]
656+ where <a> is the amount (default = 80), <r> is the
657+ radius (default = 0.5), <t> is the threshold
658+ (default = 3).
659+ - 'wmi' (WaterMarkImage)
660+ [ex: &fltr[]=wmi|<f>|<a>|<o>|<m>] where <f> is the
661+ filename of the image to overlay, <a> is the
662+ alignment (one of BR, BL, TR, TL, C, R, L, T, B, *
663+ where B=bottom, T=top, L=left, R=right, C=centre,
664+ *=tile), <o> is opacity from 0 to 100, <m> is the
665+ edge (and inter-tile) margin in percent
666+ - 'wmt' (WaterMarkText)
667+ [ex: &fltr[]=wmt|<t>|<s>|<a>|<c>|<f>|<o>|<m>|<n>]
668+ where:
669+ <t> is the text to use as a watermark,
670+ <s> is the font size (1-5 for built-in font, or point
671+ size for TrueType fonts),
672+ <a> is the alignment (one of BR, BL, TR, TL, C, R, L,
673+ T, B, * where B=bottom, T=top, L=left, R=right,
674+ C=centre, *=tile),
675+ <c> is the hex color of the text
676+ <f> is the filename of the TTF file (optional, if
677+ omitted a built-in font will be used)
678+ <o> is opacity from 0 to 100,
679+ <m> is the edge (and inter-tile) margin in percent
680+ <n> is the angle
681+ (thanks mailリmmjaeger*com)
682+ - 'flip' [ex: &fltr[]=flip|x or &fltr[]=flip|y]
683+ flip image on X or Y axis
684+ (thanks mailリmmjaeger*com)
685+ - 'elip' [ex: &fltr[]=elip]
686+ similar to rounded corners but more extreme
687+ (thanks mailリmmjaeger*com)
688+ - 'mask' [ex: &fltr[]=mask|filename.png]
689+ greyscale values of mask are applied as the alpha
690+ channel to the main image. White is opaque, black
691+ is transparent.
692+ - 'bvl' (BeVeL) [ex: &fltr[]=bvl|<w>|<c1>|<c2>]
693+ where <w> is the bevel width, <c1> is the hex color
694+ for the top and left shading, <c2> is the hex color
695+ for the bottom and right shading
696+ (thanks mailリmmjaeger*com)
697+ - 'fram' (FRAMe) draws a frame, similar to border but
698+ more configurable (thanks mailリmmjaeger*com)
699+ [ex: &fltr[]=fram|<w1>|<w2>|<c1>|<c2>|<c3>]
700+ where <w1> is the width of the main border, <w2> is
701+ the width of each side of the bevel part, <c1> is the
702+ hex color of the main border, <c2> is the highlight
703+ bevel color, <c3> is the shadow bevel color
704+ - 'drop' (DROP shadow)
705+ [ex: &fltr[]=drop|<d>|<w>|<clr>|<a>]
706+ where <d> is distance from image to shadow, <w> is
707+ width of shadow fade (not yet implemented), <clr> is
708+ the hex color of the shadow, and <a> is the angle of
709+ the shadow (default=225)
710+ - 'ric' (Rounded Image Corners)
711+ [ex: &fltr[]=ric|<x>|<y>]
712+ where <x> is the horizontal corner radius,
713+ <y> is the vertical corner radius
714+ * Split out filter functions into phpthumb.filters.php
715+ * 'usa','usr','ust' parameters have been removed and
716+ replaced with the 'fltr' call (see above)
717+ * 'wmf','wma','wmp','wmm' parameters have been removed
718+ and replaced with the 'fltr' call (see above)
719+ * 'brx','bry','bw' parameters have been removed
720+ and replaced with the 'fltr' call (see above)
721+ * 'bw=0' to force aspect ratio has been replaced by
722+ 'far=1' (force aspect ratio)
723+ * Filters that produce transparent sections (such as
724+ Rounded Corners, Ellipse, Mask, Rotate) are now output
725+ as 32-bit/alpha PNG, or flattened with "bg" background
726+ color for JPEG/GIF output (thanks mailリmmjaeger*com)
727+ * Added 'zc' (Zoom Crop) parameter
728+ (thanks arcookeリgmail*com, mailリmmjaeger*com,
729+ pl16056リmacnews*de, kezzasmリusers*sourceforge*net, etc)
730+ * AutoRotate now can use EXIF orientation tag ('ar=x')
731+ * Added 'ttf_directory' configuration parameter for
732+ TrueType watermarks (thanks mailリmmjaeger*com)
733+ * Added "Last-Modified" header to cache portion of
734+ phpThumb.php which should allow better user-side
735+ caching of thumbnails. (thanks derekリnetsimple*net)
736+ * Added 'cache_disable_warning' configuration which will
737+ cause an error image to be displayed if the cache
738+ directory isn't configured, unless explicitly disabled
739+ * Added 'nooffsitelink_enabled' configuration which
740+ prevents linking to thumbnails on your server from
741+ another domain. Defaults to watermaking linked images
742+ with text warning message.
743+ (thanks anteリabstraktmedia*com)
744+ * Added 'error_image_width' & 'error_image_height'
745+ config variables (thanks mailリmmjaeger*com)
746+ * Rounded image corners now requires GD v2.0.1 and PHP
747+ v4.3.2. Corners are transparent (for PNG output) and
748+ antialiased.
749+ * Rotate by arbitary angle ('ra') now has a transparent
750+ background for PNG output
751+ * Cached filenames now have an additional component for
752+ applied filters
753+ * Cached filenames now have an additional component for
754+ HTTP referer, but only if the refering domain does not
755+ match the domain of the server (designed to prevent
756+ imaged linked from offsite with error message being
757+ cached the same as the local cached version)
758+ * Added setSourceImageResource() to allow use of an
759+ existing GD image resource for thumbnailing
760+ (thanks danリgonmad*co*uk)
761+ * Now including phpThumb.demo.demo1.php (main demo page)
762+ and phpThumb.demo.demo2.php (configurable demo page)
763+ in the phpThumb() distribution
764+ (thanks mailリmmjaeger*com)
765+ * Added many more debugging/tracing message points
766+ * Added set_time_limit(30) to phpThumb.php
767+ * Bugfix: ImageMagick not used if `which convert` points
768+ to a link and not a file (thanks bkainersリgmail*com)
769+ * Bugfix: 'bgt' parameter was sometimes misspelled 'bct'
770+ * Bugfix: 'wmm' couldn't be set to zero
771+ * Bugfix: 'wmm' parameter was only applied to top/left of
772+ image
773+ * Bugfix: auto-detection of document_root failed on
774+ Windows (thanks xbartvリhotmail*com)
775+ * Bugfix: phpThumbDebug could be bypassed if EXIF
776+ thumbnail present (thanks olgradinリcheckfree*com)
777+ * Bugfix: cache file wasn't being written if EXIF data
778+ was used directly (thanks olgradinリcheckfree*com)
779+ * Bugfix: phpThumb.demo.showpic.php was broken by popup
780+ blockers for images larger than the screen.
781+ (thanks mailリmmjaeger*com)
782+
783+v1.4.11 - October 11, 2004
784+ * Changed sx/sy/sw/sh parameters to allow decimal values
785+ (>0 but <1) to represent percent of source image
786+ (thanks mordorリdefault*co*yu)
787+ * Added config_error_silent_die_on_error for no-output
788+ die on fatal errors (thanks johannesリformformat*se)
789+ * Added auto-detection of probable 'document_root' if
790+ that key is not available in $_SERVER
791+ * Bugfix: Check `which convert` failing with error
792+ message (thanks chadリchadshome*com)
793+ * Bugfix: Image cropping to invalid areas outside source
794+ image caused text output (thanks mordorリdefault*co*yu)
795+
796+v1.4.10 - August 22, 2004
797+ * Bugfix: cached files not written in most cases
798+ (thanks kizerリcourtkizer*com, snuffリinbox*ru)
799+ * Bugfix: ApacheLookupURIarray() crashes in CGI mode
800+ (thanks hanskrentelリyahoo*de)
801+ * Bugfix: phpthumb_bmpfile2gd() was broken
802+ (thanks iリmindlace*net)
803+
804+v1.4.9 - August 9, 2004
805+ * Bugfix: changed destination filename in RenderToFile()
806+ (thanks alextkリwalla*com)
807+ * Bugfix: problems with HTTP image source when called as
808+ an object (thanks alextkリwalla*com)
809+
810+v1.4.8 - August 4, 2004
811+ * $this->error has changed to $this->errors and is now
812+ an array of strings (instead of a single string)
813+ * A lot more error conditions (invalid cache directory,
814+ etc) are now reported in $this->errors
815+ (thanks aidan*slingsbyリlineone*net)
816+ * Removed all define(CONSTANT) in the phpThumb()
817+ constructor - you can now access:
818+ - PHPTHUMB_VERSION == $this->phpthumb_version;
819+ - PHPTHUMB_OSSLASH == $this->osslash;
820+ - PHPTHUMB_ISWINDOWS == $this->iswindows;
821+ * Bugfix: Error message from apache_lookup_uri() failing
822+ under Apache2 now reported cleanly
823+ (thanks derbaffリyahoo*com)
824+ * Bugfix: missing phpthumb_functions:: class name for
825+ ImageTypeToMIMEtype() call in ExtractEXIFgetImageSize()
826+ (thanks aidan*slingsbyリlineone*net)
827+ * Bugfix: ImageTypeToMIMEtype() was broken for PHP older
828+ than v4.3.0 (thanks georg*schreiberリbatch-pc*es)
829+ * Bugfix: RenderToFile() now returns false if it fails
830+ (thanks phpthumbリsendthemtomir*com)
831+ * Bugfix: Corrupt JPEG/PNG/GIF files that failed
832+ ImageCreateFrom*() were not being passed to ImageMagick
833+ for fallback, nor passed through unmodified if IM was
834+ unavailable or failed (thanks r*chongリmogenic*net)
835+ * Bugfix: Improved backtick safe-mode limit detection
836+ (thanks 1リadamcarrington*com)
837+ * Bugfix: EXIF thumbnails were being used as source when
838+ they should not be (thanks aidan*slingsbyリlineone*net)
839+ * Bugfix: Cached files were not being created or used
840+ properly (thanks aidan*slingsbyリlineone*net)
841+ * Bugfix: max_source_pixels not set correct on some PHP
842+ versions (thanks derbaffリyahoo*com)
843+ * Bugfix: 'down' parameter ignored for unprocessed and
844+ cached files (thanks aidan*slingsbyリlineone*net)
845+
846+v1.4.7 - July 27, 2004
847+ * Included a modified version of "module.graphic.bmp.php"
848+ from getID3() [http://getid3.sourceforge.net] as
849+ "phpthumb.bmp.php" for BMP reading support without
850+ ImageMagick. It works, but it's *very* slow, especially
851+ for large images (as in 640x480 or larger).
852+ * Added check to prevent error messages when shell_exec
853+ is disabled (thanks webmasterリneester*com)
854+
855+v1.4.6 - July 22, 2004
856+ * Added new section to phpthumb.config.php where you can
857+ easily specify defaults for any parameter you can set
858+ in the URL. Normally URL parameters override these
859+ default values, unless you set
860+ $PHPTHUMB_DEFAULTS_GETSTRINGOVERRIDE to false
861+ * Renamed phpthumb.config.php to phpThumb.config.php
862+ since it's part of phpThumb.php, not part of
863+ phpthumb.class.php (change of case only, will not
864+ affect Windows servers, but will affect *nix)
865+ * Changed cached filename of rawImageData-source images
866+ from urlencode('') to md5(rawImageData). This should
867+ make caching thumbnails from non-file sources more
868+ reliable.
869+ * Added ImageMagick debugging information
870+ * Removed unneccesary default values from cached
871+ filenames. This may invalidate some previously cached
872+ files. phpthumb.demo.cacheconvert.php has been updated
873+ to handle v1.4.1-1.4.5 => v1.4.6+ cache filenames.
874+ * Bugfix: Cached filename did not have file-modified
875+ datestamp when used as implmented in phpThumb.php
876+ * Bugfix: RenderToFile() now accepts relative filenames
877+ (thanks aidan*slingsbyリlineone*net)
878+ * Bugfix: AllowOutputEnlargment setting was ignored when
879+ falling back to ImageMagick
880+ * Bugfix: IgnoreAspectRatio setting was ignored when
881+ falling back to ImageMagick
882+ * Bugfix: config_temp_directory was ignored in gd_info()
883+ in PHP < v4.3.0 when phpinfo() returns no GD
884+ information (due to safe mode restrictions)
885+ (thanks mimyrtekリmyrtek*com)
886+
887+v1.4.5 - June 28, 2004
888+ * Added new parameter 'down' where you can specify a
889+ filename and OutputThumbnail() will cause the file
890+ to be downloaded rather than displayed in the browser.
891+ Demo images on silisoftware.com/scripts/phpThumb/demo/
892+ can all be downloaded to show off this feature.
893+ (thanks stuartscrumpリyahoo*co*uk)
894+ * Added ability to remove old files from cache directory
895+ based on last-access time and/or number of cached files
896+ and/or total size of cached files
897+ (thanks jrmhaigリyahoo*co*uk)
898+ * Added public CleanUpCacheDirectory() for cache cleaning
899+ (see above) if you need to call it manually
900+ * Included new file phpThumb.demo.cacheconvert.php to
901+ convert old-style cache names to the current (and
902+ hopefully last!) standard naming convention.
903+ (thanks joshgリtwcny*rr*com)
904+ * Added configuration value 'document_root' for rare case
905+ when $_SERVER['DOCUMENT_ROOT'] return incorrect value
906+ (thanks joshgリtwcny*rr*com)
907+ * Now tries to create thumbnail with ImageMagick if
908+ ImageCreateFromJPEG etc fails, before falling back to
909+ outputting unmodified source data.
910+ * Bugfix: HTTP image sources were broken
911+ (thanks fritz*weisshartリt-online*de)
912+ * Bugfix: ImageMagick callout wasn't being used if EXIF
913+ thumbnail was available
914+ (thanks joshgリtwcny*rr*com)
915+ * Bugfix: HTTP src with space in filename was broken
916+ (thanks drリrhodes360*com)
917+ * Bugfix: version_compare_replacement() was broken for
918+ PHP v4.1.0+
919+
920+v1.4.4 - June 8, 2004
921+ * Bugfix: network-share (Windows) source filenames were
922+ not possible. Now works, but you must use the network
923+ name and not a mapped drive name, for example:
924+ \\othercomputer\file.jpg - good
925+ \\192.168.2.1\file.jpg - good
926+ z:\file.jpg - won't work
927+ This is a PHP limitation (see www.php.net/file-exists)
928+ Note: you may want to use "/" slashes instead of "\" if
929+ you have magic_quotes_gpc enabled to avoid stripslashes
930+ problems.
931+ (thanks drリrhodes360*com)
932+ * Bugfix: missing "phpthumb_functions::" in
933+ ImageCreateFromStringReplacement()
934+ (thanks zapletalリsoftwaremedia*cz)
935+
936+v1.4.3 - May 25, 2004
937+ * Added new configuration variable 'config_temp_directory'
938+ to allow you to specify a writable directory name for
939+ temp files if you do not have access to the system temp
940+ directory on your server (Safe Mode restrictions etc)
941+ (thanks nickリregenmag*com)
942+ * Added new configuration variable
943+ 'config_error_die_on_error' which can be set to false if
944+ you want to retrieve the error message without having it
945+ dumped as an image - the error message is now available
946+ in $phpThumb->error
947+ * Images are passed through directly with no processing
948+ and no caching if no parameters are passed to alter the
949+ image (resize, crop, sharpening, etc)
950+ (thanks nchmuraリusers*sourceforge*net)
951+ * Added new configuration variable 'config_disable_debug'
952+ which disabled phpThumbDebug from working if you have
953+ security concerns about the displayed information
954+ * Bugfix: Added detection at the top of phpThumb.php for
955+ no-GD errors to avoid parse errors later in the code
956+ (thanks nickリregenmag*com)
957+ * Bugfix: RoundedImageCorners() had some off-by-1 errors
958+ (thanks ola*thunbergリhome*se)
959+
960+v1.4.2 - May 10, 2004
961+ * Added IE-compatability mode for transparent corners
962+ (set 'bct=256')
963+ * Bugfix: version_compare_replacement() was broken in PHP
964+ older than 4.1.0
965+ (thanks nickリregenmag*com)
966+
967+v1.4.1.1 - May 9, 2004
968+ * Bugfix: Removed ImageTrueColorToPalette hack.
969+ See http://bugs.php.net/bug.php?id=28341
970+ * Bugfix: 'maxb' option for PNG/GIF output incorrect
971+ bit depth under some circumstances
972+
973+v1.4.1 - May 9, 2004
974+ * Added 'maxb' (MAXimum Bytes) option to auto-set the
975+ output image quality (JPEG) or bit depth (PNG/GIF) so
976+ that the output thumbnail is less than 'maxb' bytes
977+ (thanks e_belleリhotmail*com)
978+ * Added 'bgt' parameter to make rounded corners from
979+ 'brx'/'bry' option transparent when used with PNG
980+ output. Note: PHP/GD appears buggy at this time, so this
981+ option must force output to 256-color mode for this
982+ to work. The feature will be updated when a non-broken
983+ version of PHP/GD is released.
984+ (thanks javierリircorion*net)
985+ * Bugfix: Caching was broken
986+ (thanks mikeリgdaymate*nl, jurewiczリgo3*pl)
987+
988+v1.4.0 - April 30, 2004
989+ * Rewritten as a PHP class. Split into several files:
990+ - phpthumb.class.php = most processing code
991+ - phpthumb.functions.php = support functions
992+ - phpthumb.readme.txt = usage instructions
993+ - phpthumb.changelog.txt = this file
994+ - phpthumb.config.php = configuration file
995+ - phpthumb.gif.php = Non-GD GIF reading support
996+ - phpthumb.unsharp.php = Unsharp Masking support
997+ - phpThumb.php = demo script that works
998+ exactly as previous versions; this is a drop-in
999+ replacement for existing phpThumb() installations
1000+ - phpThumb.demo.showpic.php = demo script that auto-
1001+ resizes a popup window to the size of the image
1002+ shown. Useful if you want popup images but do not
1003+ know the large image size beforehand
1004+ * Added optional call-out to ImageMagick (if avaible) if
1005+ source image is larger than PHP memory restrictions
1006+ allow. ImageMagick installation should be auto-detected
1007+ under *nix, but you should configure 'imagemagick_path'
1008+ for use under Windows.
1009+ * 'max_source_pixels' is now auto-calculated from PHP
1010+ configuration settings. Due to various server-level
1011+ restrictions that may override PHP settings this
1012+ calculated value may not always be correct, and you may
1013+ have to specify the value manually.
1014+ * Added rounded-corner border option. You must specify
1015+ both 'brx' (horizontal radius) and 'bry' (vertical
1016+ radius) as well as 'bw' (border width). If 'bw' is
1017+ greater than zero, the image will be shrunk to fit
1018+ inside the border with a margin of background color.
1019+ If 'bw' is zero, the corners of the image will be
1020+ cut off and filled with background color.
1021+ (thanks javierリircorion*net)
1022+ * Minor speed improvement for unsharp masking
1023+
1024+v1.3.7 - March 28, 2004
1025+ * Bugfix: GD version detection was broken on PHP <4.3.0
1026+ on servers where phpinfo() was disabled
1027+ (thanks javierリircorion*net)
1028+ * Bugfix: Non-GD GIF support was broken on restricted
1029+ PHP configurations
1030+ (thanks javierリircorion*net)
1031+ * Bugfix: phpThumb.gif.php output error messages if PHP
1032+ was running in Safe Mode
1033+ * Added 'iar' parameter (Ignore Aspect Ratio) to allow
1034+ non-proportional resizing (stretch image to fit).
1035+ You must specify 'h' and 'w' to use this option.
1036+ (thanks javierリircorion*net)
1037+
1038+v1.3.6 - March 14, 2004
1039+ * Bugfix: was broken when register_globals turned on
1040+ (thanks joshgリtwcny*rr*com)
1041+ * Bugfix: Images with transparent backgrounds now have
1042+ the background color filled with the color specified
1043+ by the 'bg' parameter
1044+ * Bugfix: ImageCreateFromString() is broken in the
1045+ non-bundled GD. Added workaround, but please use
1046+ the bundled version of GD if possible
1047+ (thanks dnリxbe*ch)
1048+ * Bugfix: EXIF thumbnail caching was broken
1049+ * Bugfix: EXIF thumbnail handling was broken for PHP
1050+ v4.2.x
1051+ (thanks smithk1リshaw*ca)
1052+ * Bugfix: Image borders with GD2 were misaligned
1053+ * Bugfix: virtual paths/filenames like /~user/foo.jpg
1054+ should now work properly, if PHP is installed as an
1055+ Apache module (see www.php.net/apache-lookup-uri)
1056+ * Bugfix: contents of any non-image file could be
1057+ displayed (including PHP & HTML files)
1058+ (thanks arsyanリarsyan*com)
1059+ * Added rotation parameters 'ra' and 'ar'
1060+ (thanks drリrhodes360*com)
1061+ * Added $CONFIG['output_allow_enlarging'], defaulted
1062+ to false, to prevent smaller-than-max-size images
1063+ from being enlarged beyond their original size. If
1064+ you want to be able to enlarge images, set this to
1065+ false. Can be overridden with the 'aoe' parameter
1066+ (thanks dnリxbe*ch)
1067+ * Changed all configuration variables to be under one
1068+ array named $CONFIG
1069+ * Moved color and font options for ErrorImage() to
1070+ $CONFIG variables
1071+ * Changed cached filename structure (again) to a more
1072+ flexible format that can handle future expansion
1073+ (old cached files are invalid and will be recreated)
1074+ * Added more debugging code to phpThumbDebug
1075+
1076+v1.3.5 - February 29, 2004
1077+ * Added capability to use EXIF thumbnail that may be
1078+ embedded in source image (often is in digital camera
1079+ JPEGs) and source image dimensions are larger than
1080+ $config_max_source_pixels. This will overcome the
1081+ limitation where PHP runs out of memory processing
1082+ large images (usually >1600x1200). EXIF thumbnail
1083+ extraction requires PHP v4.2.0 or higher and EXIF
1084+ support compiled into PHP (or php_exif extension)
1085+ * Eliminated intermediate read-file-to-memory stage if
1086+ image is created from local file. Should allow
1087+ larger images to be processed without running out of
1088+ memory.
1089+ * Added optional 'goto' parameter to be used with the
1090+ 'file' parameter, where 'goto' is a URL that is
1091+ redirected to after image is rendered to file
1092+ (thanks wimbleリwebdonors*com)
1093+ * Added optional 'xto' parameter that will bypass all
1094+ processing and just return the embedded EXIF
1095+ thumbnail, if available.
1096+ * Added error-handling if ImageTypes() is unavailable
1097+
1098+v1.3.4 - February 15, 2004
1099+ * Custom error image option (&err=img.jpg) which can
1100+ also be set as $config_error_message_image_default
1101+ (thanks carlリ4thstar*net)
1102+ * &f=text will now output plain-text error messages
1103+ * ErrorImage() now used for anti-hotlink messages (if
1104+ $config_nohotlink_erase_image is true)
1105+
1106+v1.3.3 - February 5, 2004
1107+ * Bugfix: Added stripslashes() to filenames if
1108+ magic_quotes_gpc is enabled
1109+ (thanks arsyanリarsyan*com)
1110+ * Output can now be rendered to a file only (not to
1111+ browser) specified by the 'file' parameter
1112+ (thanks arsyanリarsyan*com)
1113+ * JPEG quality now has a maximum of 95%, as specified
1114+ in the GD documentation
1115+
1116+v1.3.2.1 - February 3, 2004
1117+ * Bugfix: gd_version() was broken for GD v2.0+
1118+ * Bugfix: removed debugging code
1119+
1120+v1.3.2 - February 3, 2004
1121+ * Bugfix: when borders are enabled, portait images
1122+ with no width constraint, or landscape images with
1123+ no height constraint were smaller than neccesary by
1124+ double the border width
1125+ (thanks jjjリxs4all*nl)
1126+ * Added unsharp mask option thanks to Torstein H?si:
1127+ http://www.vikjavev.com/hovudsida/umtestside.php
1128+ Note: requires GD v2.x to function
1129+ (thanks jjjリxs4all*nl)
1130+ * Updated cache filenames to reflect new parameters,
1131+ this means old cached files will need to be deleted
1132+ (or not, they just will never get called again) and
1133+ new cached versions will be created.
1134+ * Added caching to gd_info() calls for minor speedup
1135+
1136+v1.3.1 - February 2, 2004
1137+ * Added optional border (width and color configurable)
1138+ (thanks arsyanリarsyan*com)
1139+ * Added option to create fixed-dimension thumbnails
1140+ regardless of source aspect ration. Set the 'bw'
1141+ (BorderWidth) parameter (even to 0) and this will be
1142+ enabled. Outside the actual image will be filled
1143+ with 'bg' color (default FFFFFF)
1144+ (thanks arsyanリarsyan*com)
1145+
1146+v1.3.0 - January 27, 2004
1147+ * Added watermarking option to overlay thumbnails with
1148+ a semi-transparent watermark image (copied from a
1149+ seperate source watermark image)
1150+ (thanks arsyanリarsyan*com)
1151+ * Added option for absolute filenames (on both Windows
1152+ and *nix) outside the DOCUMENT_ROOT directory
1153+ * Added debug output dump for diagnosing problems)
1154+
1155+v1.2.8 - January 19, 2004
1156+ * added ability to specify relative pathnames as well
1157+ as absolute pathnames (pathname is relative to the
1158+ location of phpThumb.php if the passed source does
1159+ not begin with "/"
1160+
1161+v1.2.7 - January 7, 2004
1162+ * Added patch to allow use of PHP older than 4.1.0
1163+ (or GD without PNG support) for non-GD GIF support
1164+ (thanks hostwebserverリhotmail*com)
1165+
1166+v1.2.6 - January 4, 2004
1167+ * Added patch to allow use of PHP older than 4.1.0
1168+ (without the superglobals arrays)
1169+
1170+v1.2.5 - December 26, 2003
1171+ * Added configuration options for default output image
1172+ format and max width/height
1173+
1174+v1.2.4 - December 20, 2003
1175+ * Bugfix: temp directory for non-native GD support not
1176+ always returning valid directory
1177+ * Caching feature reintroduced (see configuration)
1178+
1179+v1.2.3 - December 19, 2003
1180+ * Added anti-hotlink code so the thumbnail script on
1181+ one domain cannot be used by another domain. The
1182+ list of allowed domains defaults to the current
1183+ domain but is configurable below as
1184+ $config_nohotlink_valid_domains. The message, text
1185+ size, colors and whether to blank the image or not
1186+ are also configurable
1187+ * Bugfix: URL image sources were not able to use the
1188+ non-GD GIF-reading functions
1189+
1190+v1.2.2 - December 17, 2003
1191+ * Added option to use http:// URL as image source
1192+
1193+v1.2.1 - December 11, 2003
1194+ * Added option to get source data from a database
1195+ rather than a physical file
1196+ * Bugfix: resize not proportional when wide image
1197+ limited more by max height than max width
1198+ Thanks mathias_strasserリgmx*net
1199+ * Removed caching code
1200+
1201+v1.2.0 - December 10, 2003
1202+ * Added GIF support for versions of GD that do not
1203+ have built-in GIF support (v1.6.x) via the "GIF
1204+ Util" class by Fabien Ezber (www.yamasoft.com)
1205+ GD's built-in GIF-reading functions are faster, and
1206+ are present in PHP v4.3.0 or newer, but all versions
1207+ of GD can display resized GIF thumbnails now.
1208+
1209+v1.1.2 - October 26, 2003
1210+ * check for source image existance to prevent text
1211+ error messages
1212+ * if GD not available, a GIF saying "no GD" is shown
1213+ instead of showing the original image
1214+ * Cache feature introduced
1215+
1216+v1.1.1 - September 28, 2003
1217+ * better resize code by sfisher10リcox*net
1218+
1219+v1.1.0 - September 1, 2003
1220+ * initial public release
1221+ * thumbnails can now be larger than source image
1222+ * graphical error messages
1223+
1224+v1.0.0 - January 7, 2002
1225+ * initial private release
--- /dev/null
+++ b/trunk/NP_TrimImage/sharedlibs/phpthumb/docs/phpthumb.faq.txt
@@ -0,0 +1,305 @@
1+//////////////////////////////////////////////////////////////
2+/// phpThumb() by James Heinrich <info@silisoftware.com> //
3+// available at http://phpthumb.sourceforge.net ///
4+//////////////////////////////////////////////////////////////
5+/// //
6+// Frequently Asked Questions (FAQ) about phpThumb() //
7+// ///
8+//////////////////////////////////////////////////////////////
9+
10+
11+Q: My question isn't answered here and I can't find any
12+ forums, how do I get support?
13+A: Please email me directly at info@silisoftware.com with
14+ any questions, suggestions, donations, etc.
15+
16+
17+Q: I think I found a bug, what's the first thing I should do?
18+A: Please make sure you're using the latest version. There's
19+ a good chance I may have already fixed the bug, so please
20+ make sure you can reproduce it with the latest version
21+ before reporting the bug.
22+
23+
24+Q: phpThumb doesn't work as expected, and it may be a server
25+ configuration issue -- how do I check?
26+A: Please run /demo/demo.check.php to find out how your server
27+ matches up with the recommended configuration and for
28+ suggestions on what to change for improved performance.
29+
30+
31+Q: What is the GPL? Can I use this for commercial sites?
32+A: See the GPL FAQ: http://www.gnu.org/licenses/gpl-faq.html
33+ In general, if you just want to call phpThumb.php in the
34+ standard <img src="phpThumb.php?src=pic.jpg&w=100"> manner
35+ then there is no problem, you're free to do this no matter
36+ if you site is commercial or not, or what license your code
37+ is released under.
38+ If you're calling phpThumb() as an object then you will
39+ probably run into license issues, so consult the above FAQ
40+ and the GPL itself.
41+ No matter if you use phpThumb() commercially or not, no
42+ payment is required. However, donations are always welcome
43+ and can be made at http://phpthumb.sourceforge.net
44+
45+
46+Q: Some images generate thumbnails, but some fail (the original
47+ non-resized image is output instead).
48+A: Your PHP installation does not have a high enough memory_limit
49+ and ImageMagick is not installed on the server. The PHP memory
50+ required is 5 times the number of pixels in the image.
51+ For example:
52+ 640x480x5 = 1.5MB
53+ 1600x1200x5 = 9.2MB
54+ You can adjust the PHP memory limit in php.ini (if you have
55+ permission on your server to do so), or (better yet) install
56+ ImageMagick on the server and that will bypass the memory limit
57+ issue. If you can't do either of the above, you can resize the
58+ images manually (with your favourite image editor) to a size
59+ that your memory_limit setting can handle, and/or you can
60+ re-save the images with an image editor that can embed an EXIF
61+ thumbnail (Photoshop for example) which phpThumb can use as an
62+ image source (lower image quality, but perhaps better than
63+ nothing).
64+
65+
66+Q: I'm getting is this error message:
67+ Failed: RenderToFile(<filename>) failed because
68+ !is_resource($this->gdimg_output)
69+A: You missed the call to GenerateThumbnail() before
70+ RenderToFile() or OutputThumbnail.
71+ See /demo/phpThumb.demo.object.php for an example.
72+
73+
74+Q: I'm trying to save a phpThumb-generated image in Internet
75+ Explorer and it saves in BMP format, why?
76+A: This is not phpThumb's fault, it is an IE issue:
77+ http://support.microsoft.com/default.aspx?scid=kb;en-us;810978
78+ http://support.microsoft.com/default.aspx?scid=kb;en-us;260650
79+
80+
81+Q: PNG images with transparent areas show up with gray background
82+ in the areas that are supposed to be transparent.
83+A: Internet Explorer has had a broken PNG alpha-channel display
84+ implementation for a decade, so it may never get fixed. Other
85+ major browsers generally handle alpha-transparent PNGs fine.
86+ See http://www.silisoftware.com/png_transparency/
87+ For an alpha-channel PNG display in IE hack, see this page:
88+ http://www.koivi.com/ie-png-transparency/
89+
90+
91+Q: I'm getting "<filename> does not exist" when I know the
92+ file does exist
93+A: Check that these two values are present and properly
94+ configured in phpThumb.config.php (introduced in v1.6.0):
95+ $PHPTHUMB_CONFIG['allow_src_above_docroot'] (default=false)
96+ $PHPTHUMB_CONFIG['allow_src_above_phpthumb'] (default=true)
97+ If your images are outside DOCUMENT_ROOT then you will have
98+ to configure 'allow_src_above_docroot' to true.
99+ Make sure whatever user the webserver is running as has read
100+ permission to the file/directory you're reading from
101+
102+
103+Q: Should I use phpThumb.php, or use phpThumb() as an object?
104+A: phpThumb.php is easier to use (less coding) for basic uses.
105+ phpThumb.php handles all caching; your own object will need
106+ to have its own caching code. If you just want to display a
107+ thumbnailed version of an existing image, use phpThumb.php
108+ If you want to render one (or more) thumbnails to static
109+ files (during upload, for example), that's an appropriate
110+ use for the object mode. Also, phpThumb.config.php is only
111+ used by phpThumb.php, so if you instantiate your own object
112+ you need to manually set all configuration options because
113+ phpThumb.config.php has NO effect. So, to repeat:
114+ **always use phpThumb.php unless you NEED to have an object**
115+
116+
117+Q: The first time I go to a page which contains thumbnails I
118+ don't actually see the thumbnail, I just get a browser image
119+ placeholder (or no image). As soon as I hit refresh, all the
120+ thumbnail images pop into place really fast.
121+A: You can try and see if it works better with
122+ $PHPTHUMB_CONFIG['cache_force_passthru'] = false;
123+ but typically the default setting works better.
124+ This is something of an unresolved issue on some servers,
125+ where for whatever reason I haven't (yet?) been able to
126+ figure out a setting that always works the first time. If the
127+ above config setting doesn't help, you might be stuck with
128+ having to manually or automagically pre-cache thumbnails as
129+ they're created. Please email info@silisoftware.com if you
130+ have a better solution...
131+
132+
133+Q: Are there any front-end GUI interfaces to phpThumb()?
134+A: See /demo/readme.demo.txt
135+
136+
137+Q: Are there / have there been any security issues in phpThumb?
138+A: http://secunia.com/product/5199/
139+
140+
141+Q: Why can't Flash work with images output from phpThumb()?
142+A: Flash doesn't like progressive JPEG. Set:
143+ $PHPTHUMB_CONFIG['output_interlace'] = false;
144+
145+
146+Q: Image quality is not very good - why?
147+A: If you're using GD v1.x, no way around it. Upgrade to GD v2.x
148+
149+
150+Q: Image quality is very bad, very pixelated -- why?
151+A: You may be trying to resize images larger than the available
152+ PHP memory, so phpThumb is simply extracting and using the
153+ EXIF thumbnail as the image source, which is usually about
154+ 160x120 (so if you resize it to 640x480 it will look very bad).
155+ To calculate the required size for memory_limit in php.ini,
156+ calculate the number of pixels in the image and multiply by 5:
157+ For example, 1600x1200 = 1600 * 1200 * 5 = 9600000 = 10M
158+ Easy solution: install ImageMagick
159+
160+
161+Q: Can I save the generated thumbnail to a file?
162+A: Yes, there are several ways to do so; the best way is to call
163+ phpThumb as an object and call RenderToFile() to save the
164+ thumbnail to whatever filename you want.
165+ See /demo/phpThumb.demo.object.php for an example.
166+ The other way is to use the 'file' parameter (see
167+ /docs/phpthumb.readme.txt) but this parameter is deprecated
168+ and does not work in phpThumb v1.7.5 and newer.
169+
170+
171+Q: "Off-server thumbnailing is not allowed" -- how do I enable it?
172+A: By default, phpThumb() only makes thumbnails for the same
173+ domain that it is running on. To allow it to make thumbnails
174+ for a limited number of other domains, add them
175+ (in phpThumb.config.php) like this:
176+ $PHPTHUMB_CONFIG['nohotlink_valid_domains'] = array(
177+ @$_SERVER['HTTP_HOST'], 'example.com', 'www.example.com',
178+ 'subdomain.example.net', 'example.org');
179+ To disable off-server thumbnail blocking, just set:
180+ $PHPTHUMB_CONFIG['nohotlink_enabled'] = false;
181+
182+
183+Q: Is it possible to set the parameters (like w/h/fltr[]) in
184+ the config, so that they can't be changed over the URL?
185+A: Take a look at $PHPTHUMB_DEFAULTS at the bottom of
186+ phpThumb.config.php You'll want to set
187+ $PHPTHUMB_DEFAULTS_GETSTRINGOVERRIDE = false
188+ possibly also
189+ $PHPTHUMB_DEFAULTS_DISABLEGETPARAMS = true
190+ You may also want to investigate
191+ $PHPTHUMB_CONFIG['high_security_enabled'] = true
192+ (see the example at the bottom of phpThumb.config.php
193+ for how to call images in HighSecurity mode)
194+
195+
196+Q: Is there a way to use phpThumb() object to create thumbnails
197+ without the parameters in the URL showing the location of
198+ the image etc?
199+A: There is a demo in /demo/phpThumb.demo.object.php. You could
200+ modify this into your own file, but there still remains the
201+ problem of passing parameters to the file, whether it's
202+ phpThumb.php or your own instantiation of a phpThumb() object.
203+ I would suggest is putting as many of the common parameters
204+ into phpThumb.config.php as possible under $PHPTHUMB_DEFAULTS,
205+ so you then don't have to pass them for each image. If you
206+ don't want people modifying the parameters, turn on
207+ $PHPTHUMB_CONFIG['high_security_enabled'] and set a password
208+ (you'll need to generate the <img> tags with phpThumbURL()
209+ provided at the bottom of phpThumb.config.php). If you don't
210+ want people accessing your source images at all, you can
211+ place them outside DOCUMENT_ROOT on your server (as long as
212+ phpThumb/PHP has read access to the directory). The other
213+ option is to put your source images in a MySQL database
214+ and set $PHPTHUMB_CONFIG['mysql_query'] and related
215+ parameters in phpThumb.config.php to pull your source images
216+ from the database. That way it's impossible to retrieve the
217+ images except through phpThumb.php, and if high_security is
218+ enabled, then nobody can modify the parameters to view
219+ anything except what you want to show. So, yes, it's possible
220+ to use your own object, but it's probably better to use
221+ phpThumb.php if possible -- one notable issue is that
222+ phpThumb.php handles all the caching, so you're on your own
223+ to deal with that if you create your own object.
224+
225+
226+Q: How do I write the output thumbnail back to a database instead
227+ of outputting to the browser or a file?
228+A: See /demo/phpThumb.demo.object.php Basically you need to call
229+ $this->GenerateThumbnail() then $this->RenderOutput() and then
230+ the output raw image data is found in $this->outputImageData
231+
232+
233+Q: phpThumb runs slowly, as if the images aren't cached, when I use HTTP source
234+ images (not on my server). How can I make it go faster?
235+A: $PHPTHUMB_CONFIG['cache_source_filemtime_ignore_remote'] = true;
236+ // if true, remote source images will not be checked for modification date and
237+ // cached image will be used if available, even if source image is changed or removed
238+
239+
240+Q: What does the "cache_default_only_suffix" configuration option do?
241+A: Cache files are normally created with big ugly names like
242+ "phpThumb_cache_www.example.com_src1a482c2c760463795ff18faf073b389f_par3e099041c2f4a73041a7f5d7e7fc481a_dat1119952152.jpeg"
243+ but if cache_default_only_suffix is enabled, cache filenames are simplified to
244+ "pic_thumb.jpg" (for example). The problem is that only one version of that
245+ thumbnail is possible, and you can never call it again with a different size,
246+ or different filters, etc. Generally you don't want that enabled, but it's
247+ there because some people asked for it.
248+
249+
250+Q: Why is the visual size of rotated images smaller than the unrotated images?
251+A: phpThumb fits the rotated image into the 'w' and 'h' dimensions.
252+ Try not specifying a 'w' parameter: phpThumb.php?src=file.png&ra=15
253+ That should leave the image the apparent same size as the unrotated image
254+ (in actual fact the canvas size is enlarged to fit the rotated image in it).
255+
256+
257+Q: How can I purge cached files when I delete the source image?
258+A: You can either let phpThumb's built-in cache purging features (see phpThumb.config.php)
259+ take effect, or you can manually walk through your source images to delete and find
260+ the matching cache files and delete them:
261+ if ($dh = opendir($sourcedir)) {
262+ while ($file = readddir($dh)) {
263+ if ($file == $WhatIwantToDelete) {
264+ $md5 = md5_file($sourcedir.'/'.$file);
265+ unlink($phpthumb_cache_dir.'/phpThumb_cache_www.example.com_src'.$md5.'*.*');
266+ }
267+ }
268+ closedir($dh);
269+ }
270+
271+
272+Q: Can I make thumbnails from a PDF?
273+A: Yes, as long as you have both ImageMagick and GhostScript
274+ installed. The AFPL version of GhostScript seems to work
275+ better than the GNU version (at least for me it does).
276+ http://www.imagemagick.org
277+ http://www.cs.wisc.edu/~ghost/
278+ You may want to use the "sfn" (Source Frame Number)
279+ parameter of phpThumb to specify which page to thumbnail.
280+
281+
282+Q: Can I make a thumbnail of a webpage?
283+A: Possibly, but it's not easy. Theoretically, if you have
284+ html2ps, GhostScript and ImageMagick all installed it should
285+ be possible, but I have not tested that. Other projects that
286+ attempt to generate thumbnails from webpages include:
287+ http://www.boutell.com/webthumb/
288+
289+
290+Q: phpThumb is the best software in the world, how can I donate?
291+A: There's a handy "Support this project" button at the top of
292+ http://phpthumb.sourceforge.net which will take you through
293+ the process (and give SourceForge a ~5% cut), or if you prefer
294+ you can send PayPal donations directly to info@silisoftware.com
295+
296+
297+Q: What is the proper name for this script/program/library?
298+A: The official name is "phpThumb()" but it may be written
299+ as simply "phpThumb" in short form (or where parentheses
300+ are not permitted), or "phpthumb" in case-insensitive
301+ environments. The following is a non-exhaustive sample of
302+ unacceptable forms: PHPthumb; phpThumbs; phpthump;
303+ phpthumbnailer; phpThumbnail; PHP Thumb; Phpthumb; etc.
304+
305+
--- /dev/null
+++ b/trunk/NP_TrimImage/sharedlibs/phpthumb/docs/phpthumb.license.txt
@@ -0,0 +1,340 @@
1+ GNU GENERAL PUBLIC LICENSE
2+ Version 2, June 1991
3+
4+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6+ Everyone is permitted to copy and distribute verbatim copies
7+ of this license document, but changing it is not allowed.
8+
9+ Preamble
10+
11+ The licenses for most software are designed to take away your
12+freedom to share and change it. By contrast, the GNU General Public
13+License is intended to guarantee your freedom to share and change free
14+software--to make sure the software is free for all its users. This
15+General Public License applies to most of the Free Software
16+Foundation's software and to any other program whose authors commit to
17+using it. (Some other Free Software Foundation software is covered by
18+the GNU Library General Public License instead.) You can apply it to
19+your programs, too.
20+
21+ When we speak of free software, we are referring to freedom, not
22+price. Our General Public Licenses are designed to make sure that you
23+have the freedom to distribute copies of free software (and charge for
24+this service if you wish), that you receive source code or can get it
25+if you want it, that you can change the software or use pieces of it
26+in new free programs; and that you know you can do these things.
27+
28+ To protect your rights, we need to make restrictions that forbid
29+anyone to deny you these rights or to ask you to surrender the rights.
30+These restrictions translate to certain responsibilities for you if you
31+distribute copies of the software, or if you modify it.
32+
33+ For example, if you distribute copies of such a program, whether
34+gratis or for a fee, you must give the recipients all the rights that
35+you have. You must make sure that they, too, receive or can get the
36+source code. And you must show them these terms so they know their
37+rights.
38+
39+ We protect your rights with two steps: (1) copyright the software, and
40+(2) offer you this license which gives you legal permission to copy,
41+distribute and/or modify the software.
42+
43+ Also, for each author's protection and ours, we want to make certain
44+that everyone understands that there is no warranty for this free
45+software. If the software is modified by someone else and passed on, we
46+want its recipients to know that what they have is not the original, so
47+that any problems introduced by others will not reflect on the original
48+authors' reputations.
49+
50+ Finally, any free program is threatened constantly by software
51+patents. We wish to avoid the danger that redistributors of a free
52+program will individually obtain patent licenses, in effect making the
53+program proprietary. To prevent this, we have made it clear that any
54+patent must be licensed for everyone's free use or not licensed at all.
55+
56+ The precise terms and conditions for copying, distribution and
57+modification follow.
58+
59+ GNU GENERAL PUBLIC LICENSE
60+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61+
62+ 0. This License applies to any program or other work which contains
63+a notice placed by the copyright holder saying it may be distributed
64+under the terms of this General Public License. The "Program", below,
65+refers to any such program or work, and a "work based on the Program"
66+means either the Program or any derivative work under copyright law:
67+that is to say, a work containing the Program or a portion of it,
68+either verbatim or with modifications and/or translated into another
69+language. (Hereinafter, translation is included without limitation in
70+the term "modification".) Each licensee is addressed as "you".
71+
72+Activities other than copying, distribution and modification are not
73+covered by this License; they are outside its scope. The act of
74+running the Program is not restricted, and the output from the Program
75+is covered only if its contents constitute a work based on the
76+Program (independent of having been made by running the Program).
77+Whether that is true depends on what the Program does.
78+
79+ 1. You may copy and distribute verbatim copies of the Program's
80+source code as you receive it, in any medium, provided that you
81+conspicuously and appropriately publish on each copy an appropriate
82+copyright notice and disclaimer of warranty; keep intact all the
83+notices that refer to this License and to the absence of any warranty;
84+and give any other recipients of the Program a copy of this License
85+along with the Program.
86+
87+You may charge a fee for the physical act of transferring a copy, and
88+you may at your option offer warranty protection in exchange for a fee.
89+
90+ 2. You may modify your copy or copies of the Program or any portion
91+of it, thus forming a work based on the Program, and copy and
92+distribute such modifications or work under the terms of Section 1
93+above, provided that you also meet all of these conditions:
94+
95+ a) You must cause the modified files to carry prominent notices
96+ stating that you changed the files and the date of any change.
97+
98+ b) You must cause any work that you distribute or publish, that in
99+ whole or in part contains or is derived from the Program or any
100+ part thereof, to be licensed as a whole at no charge to all third
101+ parties under the terms of this License.
102+
103+ c) If the modified program normally reads commands interactively
104+ when run, you must cause it, when started running for such
105+ interactive use in the most ordinary way, to print or display an
106+ announcement including an appropriate copyright notice and a
107+ notice that there is no warranty (or else, saying that you provide
108+ a warranty) and that users may redistribute the program under
109+ these conditions, and telling the user how to view a copy of this
110+ License. (Exception: if the Program itself is interactive but
111+ does not normally print such an announcement, your work based on
112+ the Program is not required to print an announcement.)
113+
114+These requirements apply to the modified work as a whole. If
115+identifiable sections of that work are not derived from the Program,
116+and can be reasonably considered independent and separate works in
117+themselves, then this License, and its terms, do not apply to those
118+sections when you distribute them as separate works. But when you
119+distribute the same sections as part of a whole which is a work based
120+on the Program, the distribution of the whole must be on the terms of
121+this License, whose permissions for other licensees extend to the
122+entire whole, and thus to each and every part regardless of who wrote it.
123+
124+Thus, it is not the intent of this section to claim rights or contest
125+your rights to work written entirely by you; rather, the intent is to
126+exercise the right to control the distribution of derivative or
127+collective works based on the Program.
128+
129+In addition, mere aggregation of another work not based on the Program
130+with the Program (or with a work based on the Program) on a volume of
131+a storage or distribution medium does not bring the other work under
132+the scope of this License.
133+
134+ 3. You may copy and distribute the Program (or a work based on it,
135+under Section 2) in object code or executable form under the terms of
136+Sections 1 and 2 above provided that you also do one of the following:
137+
138+ a) Accompany it with the complete corresponding machine-readable
139+ source code, which must be distributed under the terms of Sections
140+ 1 and 2 above on a medium customarily used for software interchange; or,
141+
142+ b) Accompany it with a written offer, valid for at least three
143+ years, to give any third party, for a charge no more than your
144+ cost of physically performing source distribution, a complete
145+ machine-readable copy of the corresponding source code, to be
146+ distributed under the terms of Sections 1 and 2 above on a medium
147+ customarily used for software interchange; or,
148+
149+ c) Accompany it with the information you received as to the offer
150+ to distribute corresponding source code. (This alternative is
151+ allowed only for noncommercial distribution and only if you
152+ received the program in object code or executable form with such
153+ an offer, in accord with Subsection b above.)
154+
155+The source code for a work means the preferred form of the work for
156+making modifications to it. For an executable work, complete source
157+code means all the source code for all modules it contains, plus any
158+associated interface definition files, plus the scripts used to
159+control compilation and installation of the executable. However, as a
160+special exception, the source code distributed need not include
161+anything that is normally distributed (in either source or binary
162+form) with the major components (compiler, kernel, and so on) of the
163+operating system on which the executable runs, unless that component
164+itself accompanies the executable.
165+
166+If distribution of executable or object code is made by offering
167+access to copy from a designated place, then offering equivalent
168+access to copy the source code from the same place counts as
169+distribution of the source code, even though third parties are not
170+compelled to copy the source along with the object code.
171+
172+ 4. You may not copy, modify, sublicense, or distribute the Program
173+except as expressly provided under this License. Any attempt
174+otherwise to copy, modify, sublicense or distribute the Program is
175+void, and will automatically terminate your rights under this License.
176+However, parties who have received copies, or rights, from you under
177+this License will not have their licenses terminated so long as such
178+parties remain in full compliance.
179+
180+ 5. You are not required to accept this License, since you have not
181+signed it. However, nothing else grants you permission to modify or
182+distribute the Program or its derivative works. These actions are
183+prohibited by law if you do not accept this License. Therefore, by
184+modifying or distributing the Program (or any work based on the
185+Program), you indicate your acceptance of this License to do so, and
186+all its terms and conditions for copying, distributing or modifying
187+the Program or works based on it.
188+
189+ 6. Each time you redistribute the Program (or any work based on the
190+Program), the recipient automatically receives a license from the
191+original licensor to copy, distribute or modify the Program subject to
192+these terms and conditions. You may not impose any further
193+restrictions on the recipients' exercise of the rights granted herein.
194+You are not responsible for enforcing compliance by third parties to
195+this License.
196+
197+ 7. If, as a consequence of a court judgment or allegation of patent
198+infringement or for any other reason (not limited to patent issues),
199+conditions are imposed on you (whether by court order, agreement or
200+otherwise) that contradict the conditions of this License, they do not
201+excuse you from the conditions of this License. If you cannot
202+distribute so as to satisfy simultaneously your obligations under this
203+License and any other pertinent obligations, then as a consequence you
204+may not distribute the Program at all. For example, if a patent
205+license would not permit royalty-free redistribution of the Program by
206+all those who receive copies directly or indirectly through you, then
207+the only way you could satisfy both it and this License would be to
208+refrain entirely from distribution of the Program.
209+
210+If any portion of this section is held invalid or unenforceable under
211+any particular circumstance, the balance of the section is intended to
212+apply and the section as a whole is intended to apply in other
213+circumstances.
214+
215+It is not the purpose of this section to induce you to infringe any
216+patents or other property right claims or to contest validity of any
217+such claims; this section has the sole purpose of protecting the
218+integrity of the free software distribution system, which is
219+implemented by public license practices. Many people have made
220+generous contributions to the wide range of software distributed
221+through that system in reliance on consistent application of that
222+system; it is up to the author/donor to decide if he or she is willing
223+to distribute software through any other system and a licensee cannot
224+impose that choice.
225+
226+This section is intended to make thoroughly clear what is believed to
227+be a consequence of the rest of this License.
228+
229+ 8. If the distribution and/or use of the Program is restricted in
230+certain countries either by patents or by copyrighted interfaces, the
231+original copyright holder who places the Program under this License
232+may add an explicit geographical distribution limitation excluding
233+those countries, so that distribution is permitted only in or among
234+countries not thus excluded. In such case, this License incorporates
235+the limitation as if written in the body of this License.
236+
237+ 9. The Free Software Foundation may publish revised and/or new versions
238+of the General Public License from time to time. Such new versions will
239+be similar in spirit to the present version, but may differ in detail to
240+address new problems or concerns.
241+
242+Each version is given a distinguishing version number. If the Program
243+specifies a version number of this License which applies to it and "any
244+later version", you have the option of following the terms and conditions
245+either of that version or of any later version published by the Free
246+Software Foundation. If the Program does not specify a version number of
247+this License, you may choose any version ever published by the Free Software
248+Foundation.
249+
250+ 10. If you wish to incorporate parts of the Program into other free
251+programs whose distribution conditions are different, write to the author
252+to ask for permission. For software which is copyrighted by the Free
253+Software Foundation, write to the Free Software Foundation; we sometimes
254+make exceptions for this. Our decision will be guided by the two goals
255+of preserving the free status of all derivatives of our free software and
256+of promoting the sharing and reuse of software generally.
257+
258+ NO WARRANTY
259+
260+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268+REPAIR OR CORRECTION.
269+
270+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278+POSSIBILITY OF SUCH DAMAGES.
279+
280+ END OF TERMS AND CONDITIONS
281+
282+ How to Apply These Terms to Your New Programs
283+
284+ If you develop a new program, and you want it to be of the greatest
285+possible use to the public, the best way to achieve this is to make it
286+free software which everyone can redistribute and change under these terms.
287+
288+ To do so, attach the following notices to the program. It is safest
289+to attach them to the start of each source file to most effectively
290+convey the exclusion of warranty; and each file should have at least
291+the "copyright" line and a pointer to where the full notice is found.
292+
293+ <one line to give the program's name and a brief idea of what it does.>
294+ Copyright (C) <year> <name of author>
295+
296+ This program is free software; you can redistribute it and/or modify
297+ it under the terms of the GNU General Public License as published by
298+ the Free Software Foundation; either version 2 of the License, or
299+ (at your option) any later version.
300+
301+ This program is distributed in the hope that it will be useful,
302+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304+ GNU General Public License for more details.
305+
306+ You should have received a copy of the GNU General Public License
307+ along with this program; if not, write to the Free Software
308+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309+
310+
311+Also add information on how to contact you by electronic and paper mail.
312+
313+If the program is interactive, make it output a short notice like this
314+when it starts in an interactive mode:
315+
316+ Gnomovision version 69, Copyright (C) year name of author
317+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318+ This is free software, and you are welcome to redistribute it
319+ under certain conditions; type `show c' for details.
320+
321+The hypothetical commands `show w' and `show c' should show the appropriate
322+parts of the General Public License. Of course, the commands you use may
323+be called something other than `show w' and `show c'; they could even be
324+mouse-clicks or menu items--whatever suits your program.
325+
326+You should also get your employer (if you work as a programmer) or your
327+school, if any, to sign a "copyright disclaimer" for the program, if
328+necessary. Here is a sample; alter the names:
329+
330+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
332+
333+ <signature of Ty Coon>, 1 April 1989
334+ Ty Coon, President of Vice
335+
336+This General Public License does not permit incorporating your program into
337+proprietary programs. If your program is a subroutine library, you may
338+consider it more useful to permit linking proprietary applications with the
339+library. If this is what you want to do, use the GNU Library General
340+Public License instead of this License.
--- /dev/null
+++ b/trunk/NP_TrimImage/sharedlibs/phpthumb/docs/phpthumb.readme.txt
@@ -0,0 +1,565 @@
1+//////////////////////////////////////////////////////////////
2+/// phpThumb() by James Heinrich <info@silisoftware.com> //
3+// available at http://phpthumb.sourceforge.net ///
4+//////////////////////////////////////////////////////////////
5+/// //
6+// This code is released under the GNU GPL: //
7+// http://www.gnu.org/copyleft/gpl.html //
8+// //
9+// +-----------------------------------------------+ //
10+// | phpThumb() is free to use according to the | //
11+// | terms of the GPL. Donations also gratefully | //
12+// | GPL FAQ: http://gnu.org/licenses/gpl-faq.html | //
13+// | | //
14+// | Donations are gratefully accepted from happy | //
15+// | users :) See http://phpthumb.sourceforge.net | //
16+// | | //
17+// | If you like phpThumb(), please consider | //
18+// | writing a review at HotScripts.com: | //
19+// | http://www.hotscripts.com/Detailed/25654.html | //
20+// | | //
21+// | If you do use this code somewhere, send me | //
22+// | an email and tell me how/where you used it. | //
23+// +-----------------------------------------------+ //
24+// ///
25+//////////////////////////////////////////////////////////////
26+
27+============
28+Description:
29+============
30+
31+phpThumb() uses the GD library to create thumbnails from
32+images (GIF, PNG or JPEG) on the fly. The output size is
33+configurable (can be larger or smaller than the source),
34+and the source may be the entire image or only a portion
35+of the original image. True color and resampling is used
36+if GD v2.0+ is available, otherwise low-color and simple
37+resizing is used. Source image can be a physical file on
38+the server or can be retrieved from a database. GIFs are
39+supported on all versions of GD even if GD does not have
40+native GIF support thanks to the GIFutil class by Fabien
41+Ezber. AntiHotlinking feature prevents other people from
42+using your server to resize their thumbnails, or link to
43+your images from another server. The cache feature
44+reduces server load.
45+
46+
47+========
48+Support:
49+========
50+
51+First, read this file.
52+Then read phpthumb.faq.txt
53+Then run /demo/phpThumb.demo.check.php
54+If you still think it's a bug, email info@silisoftware.com
55+
56+
57+======
58+Usage:
59+======
60+
61+Call phpThumb() just like you would a normal image.
62+Examples:
63+ <IMG SRC="phpThumb.php?src=/image.jpg&w=100">
64+ <IMG SRC="phpThumb.php?src=http://example.com/foo.jpg">
65+See the "demo" link on http://phpthumb.sourceforge.net
66+for more usage examples). Parameters that can be passed
67+are listed below under "URL Parameters".
68+
69+NOTE: It's recommended you use the local image filename
70+wherever possible (rather than http://) because performance
71+is much better, less (or no) use of temp files, and the
72+last-modified check for cached files doesn't work for
73+remote files.
74+
75+To access files over a LAN with Windows share names you
76+must use the network name (or IP) and not a mapped drive
77+name, for example:
78+ //othercomputer/file.jpg - good
79+ //192.168.2.1/file.jpg - good
80+ z:/file.jpg - won't work
81+This is a PHP limitation (see www.php.net/file-exists)
82+Note: you may want to use "/" slashes instead of "\" if
83+you have magic_quotes_gpc enabled to avoid stripslashes
84+problems, although either slash should work if
85+magic_quotes_gpc is disabled
86+
87+
88+================================
89+Alternate PATH_INFO-style Usage:
90+================================
91+
92+phpThumb.php can also be called by passing parameters not
93+after the usual "?" but like this:
94+ phpThumb.php/<params>=<values>;<w>x<h>;<image>
95+For example:
96+ phpThumb.php/100;pic.jpg
97+ phpThumb.php/100;images/pic.jpg
98+ phpThumb.php/100;/images/pic.jpg
99+ phpThumb.php/100x200;pic.jpg
100+ phpThumb.php/x200;pic.jpg
101+ phpThumb.php/f=jpeg;q=50;100x200;pic.jpg
102+ phpThumb.php/fltr[]=usm;100;pic.jpg
103+
104+<image> must be the last item. Dimensions must be the second-
105+last item. As many key/value pairs for parameters can be
106+passed before those last two items, with each pair joined by
107+equals ("=") and seperated by semicolon (";")
108+
109+
110+==============================================
111+Calling as an object (not using phpThumb.php):
112+==============================================
113+
114+NOTE: most people don't need to and should not do this.
115+If you just want to display resized images, please just
116+use phpThumb.php, not the object mode. To render output
117+to one (or more) files instead of the browser, you should
118+skip phpThumb.php and instantiate your own object. Please
119+take a look at /demo/phpThumb.demo.object.php for details.
120+
121+Note: phpThumb.php is where the caching code is located, if
122+ you instantiate your own phpThumb() object that code is
123+ bypassed and it's up to you to handle the reading and
124+ writing of cached files.
125+
126+
127+==============
128+Configuration:
129+==============
130+
131+There are some configuration options you may (but are
132+not required to) change. Most configuration options can
133+be set when you call phpThumb() - see list below), but
134+default configuration options (such as cache directory)
135+are in phpThumb.config.php - this is the only file you
136+should ever modify.
137+
138+The configuration file is distributed as
139+phpThumb.config.php.default to prevent accidental
140+overwriting of old configuration settings. Please
141+migrate your old settings to the new file (if upgrading),
142+or delete your old config and rename the default to
143+phpThumb.config.php
144+
145+
146+The amount of memory required for phpThumb depends on
147+several factors: the dimensions of the source image,
148+the dimensions of the output image, whether unsharp
149+masking is applied, whether watermarks are applied, etc.
150+The auto-detection of memory limits works as a general
151+"safe" value. You may be able to exceed the auto value
152+by a small or large amount, depending on whether you
153+apply watermarks and/or sharpening, and the output size
154+of your thumbnails. I do not currently have a reliable
155+formula for calculating such things, but I will attempt
156+to craft one for future versions of phpThumb(). Until
157+then, set "max_source_pixels" in phpThumb.config.php to a
158+value that works well for you (or leave it alone if the
159+defaults give you no problems).
160+
161+The configuration options you should maybe modify are:
162+* cache_directory - thumbnailing is slow and processor-
163+ intensive. Enabling caching will dramatically speed
164+ up future thumbnail serving
165+* max_source_pixels - This should be auto-detected, but
166+ if auto-detection fails and you get an invalid image
167+ from large source images, set this to about 20% of
168+ your available PHP memory limit.
169+* imagemagick_path - If the source image is larger than
170+ max_source_pixels allows, but ImageMagick is available
171+ phpThumb() will use it to generate the thumbnail.
172+
173+
174+///////////////////////////////////////////////////////////
175+Note: High-Security mode is recommended enabled if possible.
176+ Set $PHPTHUMB_CONFIG['high_security_enabled'] in
177+ phpThumb.config.php to enable it. Each call to phpThumb
178+ needs to be made through the function supplied at the
179+ bottom of phpThumb.config.php which create the hash:
180+ require_once('phpThumb.config.php');
181+ echo '<img src="'.phpThumbURL('src=pic.jpg&w=50').'">';
182+///////////////////////////////////////////////////////////
183+
184+
185+===============
186+URL Parameters:
187+===============
188+
189+ src = filename of source image
190+ new = create new image, not thumbnail of existing image.
191+ Requires "w" and "h" parameters set.
192+ [ex: &new=FF0000|75] - red background, 75% opacity
193+ Set to hex color string of background. Opacity is
194+ optional (defaults to 100% opaque).
195+ w = max width of output thumbnail in pixels
196+ h = max height of output thumbnail in pixels
197+ wp = max width for portrait images
198+ hp = max height for portrait images
199+ wl = max width for landscape images
200+ hl = max height for landscape images
201+ ws = max width for square images
202+ hs = max height for square images
203+ f = output image format ("jpeg", "png", or "gif")
204+ q = JPEG compression (1=worst, 95=best, 75=default)
205+ sx = left side of source rectangle (default = 0)
206+ (values 0 < sx < 1 represent percentage)
207+ sy = top side of source rectangle (default = 0)
208+ (values 0 < sy < 1 represent percentage)
209+ sw = width of source rectangle (default = fullwidth)
210+ (values 0 < sw < 1 represent percentage)
211+ sh = height of source rectangle (default = fullheight)
212+ (values 0 < sh < 1 represent percentage)
213+ zc = zoom-crop. Will auto-crop off the larger dimension
214+ so that the image will fill the smaller dimension
215+ (requires both "w" and "h"). Set "zc=1" to enable.
216+ (overrides both "iar" and "far")
217+ bg = background hex color (default = FFFFFF)
218+ bc = border hex color (default = 000000)
219+fltr = filter system. Call as an array as follows:
220+ - "brit" (Brightness) [ex: &fltr[]=brit|<value>]
221+ where <value> is the amount +/- to adjust brightness
222+ (range -255 to 255)
223+ Availble in PHP5 with bundled GD only.
224+ - "cont" (Constrast) [ex: &fltr[]=cont|<value>]
225+ where <value> is the amount +/- to adjust contrast
226+ (range -255 to 255)
227+ Availble in PHP5 with bundled GD only.
228+ - "gam" (Gamma Correction) [ex: &fltr[]=gam|<value>]
229+ where <value> can be a number >0 to 10+ (default 1.0)
230+ Must be >0 (zero gives no effect). There is no max,
231+ although beyond 10 is pretty useless. Negative
232+ numbers actually do something, maybe not quite the
233+ desired effect, but interesting nonetheless.
234+ - "sat" (SATuration) [ex: &fltr[]=sat|<value>]
235+ where <value> is a number between zero (no change)
236+ and -100 (complete desaturation = grayscale), or it
237+ can be any positive number for increased saturation.
238+ - "ds" (DeSaturate) [ex: &fltr[]=ds|<value>]
239+ is an alias for "sat" except values are inverted
240+ (positive values remove color, negative values boost
241+ saturation)
242+ - "gray" (Grayscale) [ex: &fltr[]=gray]
243+ remove all color from image, make it grayscale
244+ - "th" (Threshold) [ex: &fltr[]=th|<value>]
245+ makes image greyscale, then sets all pixels brighter
246+ than <value> (range 0-255) to white, and all pixels
247+ darker than <value> to black
248+ - "rcd" (Reduce Color Depth) [ex: &fltr[]=rcd|<c>|<d>]
249+ where <c> is the number of colors (2-256) you want
250+ in the output image, and <d> is "1" for dithering
251+ (deault) or "0" for no dithering
252+ - "clr" (Colorize) [ex: &fltr[]=clr|<value>|<color>]
253+ where <value> is a number between 0 and 100 for the
254+ amount of colorization, and <color> is the hex color
255+ to colorize to.
256+ - "sep" (Sepia) [ex: &fltr[]=sep|<value>|<color>]
257+ where <value> is a number between 0 and 100 for the
258+ amount of colorization (default=50), and <color> is
259+ the hex color to colorize to (default=A28065).
260+ Note: this behaves differently when applied by
261+ ImageMagick, in which case 80 is default, and lower
262+ values give brighter/yellower images and higher
263+ values give darker/bluer images
264+ - "usm" (UnSharpMask) [ex: &fltr[]=usm|<a>|<r>|<t>]
265+ where <a> is the amount (default = 80), <r> is the
266+ radius (default = 0.5), <t> is the threshold
267+ (default = 3).
268+ - "blur" (Blur) [ex: &fltr[]=blur|<radius>]
269+ where (0 < <radius> < 25) (default = 1)
270+ - "gblr" (Gaussian Blur) [ex: &fltr[]=gblr]
271+ Availble in PHP5 with bundled GD only.
272+ - "sblr" (Selective Blur) [ex: &fltr[]=gblr]
273+ Availble in PHP5 with bundled GD only.
274+ - "smth" (Smooth) [ex: &fltr[]=smth|<value>]
275+ where <value> is the weighting value for the matrix
276+ (range -10 to 10, default 6)
277+ Availble in PHP5 with bundled GD only.
278+ - "lvl" (Levels) [ex: &fltr[]=lvl|<channel>|<min>|<max>
279+ where <channel> can be one of 'r', 'g', 'b', 'a' (for
280+ Red, Green, Blue, Alpha respectively), or '*' for all
281+ channels based on average grayscale value (default).
282+ <min> and <max> are the clip points for the levels
283+ and are set to clip 0.1% of each end by default.
284+ (range = 0-255) and are set to clip 0.1% of each end
285+ by default. Use -1 for min and/or max to invoke auto-
286+ detect mode. Using default parameters (&fltr[]=lvl)
287+ is similar to Auto Contrast in Adobe Photoshop.
288+ - "wb" (White Balance) [ex: &fltr[]=wb|<c>]
289+ where <c> is the target hex color to white balance
290+ on, this color is what "should be" white, or light
291+ gray. The filter attempts to maintain brightness so
292+ any gray color can theoretically be used. If <c> is
293+ omitted the filter guesses based on brightest pixels
294+ in each of RGB
295+ - "hist" (Histogram)
296+ [ex: &fltr[]=hist|<b>|<c>|<w>|<h>|<a>|<o>|<x>|<y>]
297+ Where <b> is the color band(s) to display, from back
298+ to front (one or more of "rgba*" for Red Green Blue
299+ Alpha and Grayscale respectively);
300+ <c> is a semicolon-seperated list of hex colors to
301+ use for each graph band (defaults to FF0000, 00FF00,
302+ 0000FF, 999999, FFFFFF respectively);
303+ <w> and <h> are the width and height of the overlaid
304+ histogram in pixels, or if <= 1 then percentage of
305+ source image width/height;
306+ <a> is the alignment (same as for "wmi" and "wmt");
307+ <o> is opacity from 0 (transparent) to 100 (opaque)
308+ (requires PHP v4.3.2, otherwise 100% opaque);
309+ <x> and <y> are the edge margin in pixels (or percent
310+ if 0 < (x|y) < 1)
311+ - "over" (OVERlay/underlay image) overlays an image on
312+ the thumbnail, or overlays the thumbnail on another
313+ image (to create a picture frame for example)
314+ [ex: &fltr[]=over|<i>|<u>|<m>|<o>]
315+ where <i> is the image filename; <u> is "0" (default)
316+ for overlay the image on top of the thumbnail or "1"
317+ for overlay the thumbnail on top of the image; <m> is
318+ the margin - can be absolute pixels, or if < 1 is a
319+ percentage of the thumbnail size [must be < 0.5]
320+ (default is 0 for overlay and 10% for underlay);
321+ <o> is opacity (0 = transparent, 100 = opaque)
322+ (requires PHP v4.3.2, otherwise 100% opaque);
323+ (thanks raynerapeリgmail*com, shabazz3リmsu*edu)
324+ - "wmi" (WaterMarkImage)
325+ [ex: &fltr[]=wmi|<f>|<a>|<o>|<x>|<y>] where
326+ <f> is the filename of the image to overlay;
327+ <a> is the alignment (one of BR, BL, TR, TL, C,
328+ R, L, T, B, *) where B=bottom, T=top, L=left,
329+ R=right, C=centre, *=tile);
330+ <o> is opacity from 0 (transparent) to 100 (opaque)
331+ (requires PHP v4.3.2, otherwise 100% opaque);
332+ <x> and <y> are the edge (and inter-tile) margin in
333+ pixels (or percent if 0 < (x|y) < 1)
334+ - "wmt" (WaterMarkText)
335+ [ex: &fltr[]=wmt|<t>|<s>|<a>|<c>|<f>|<o>|<m>|<n>|<b>|<O>|<x>]
336+ where:
337+ <t> is the text to use as a watermark;
338+ URLencoded Unicode HTMLentities must be used for
339+ characters beyond chr(127). For example, the
340+ "eighth note" character (U+266A) is represented
341+ as "&#9834;" and then urlencoded to "%26%239834%3B"
342+ Any instance of metacharacters will be replaced
343+ with their calculated value. Currently supported:
344+ ^Fb = source image filesize in bytes
345+ ^Fk = source image filesize in kilobytes
346+ ^Fm = source image filesize in megabytes
347+ ^X = source image width in pixels
348+ ^Y = source image height in pixels
349+ ^x = thumbnail width in pixels
350+ ^y = thumbnail height in pixels
351+ ^^ = the character ^
352+ <s> is the font size (1-5 for built-in font, or point
353+ size for TrueType fonts);
354+ <a> is the alignment (one of BR, BL, TR, TL, C, R, L,
355+ T, B, * where B=bottom, T=top, L=left, R=right,
356+ C=centre, *=tile);
357+ <c> is the hex color of the text;
358+ <f> is the filename of the TTF file (optional, if
359+ omitted a built-in font will be used);
360+ <o> is opacity from 0 (transparent) to 100 (opaque)
361+ (requires PHP v4.3.2, otherwise 100% opaque);
362+ <m> is the edge (and inter-tile) margin in percent;
363+ <n> is the angle
364+ <b> is the hex color of the background;
365+ <O> is background opacity from 0 (transparent) to
366+ 100 (opaque)
367+ (requires PHP v4.3.2, otherwise 100% opaque);
368+ <x> is the direction(s) in which the background is
369+ extended (either 'x' or 'y' (or both, but both
370+ will obscure entire image))
371+ Note: works with TTF fonts only, not built-in
372+ - "flip" [ex: &fltr[]=flip|x or &fltr[]=flip|y]
373+ flip image on X or Y axis
374+ - "ric" [ex: &fltr[]=ric|<x>|<y>]
375+ rounds off the corners of the image (to transparent
376+ for PNG output), where <x> is the horizontal radius
377+ of the curve and <y> is the vertical radius
378+ - "elip" [ex: &fltr[]=elip]
379+ similar to rounded corners but more extreme
380+ - "mask" [ex: &fltr[]=mask|filename.png]
381+ greyscale values of mask are applied as the alpha
382+ channel to the main image. White is opaque, black
383+ is transparent.
384+ - "bvl" (BeVeL) [ex: &fltr[]=bvl|<w>|<c1>|<c2>]
385+ where <w> is the bevel width, <c1> is the hex color
386+ for the top and left shading, <c2> is the hex color
387+ for the bottom and right shading
388+ - "bord" (BORDer) [ex: &fltr[]=bord|<w>|<rx>|<ry>|<c>
389+ where <w> is the width in pixels, <rx> and <ry> are
390+ horizontal and vertical radii for rounded corners,
391+ and <c> is the hex color of the border
392+ - "fram" (FRAMe) draws a frame, similar to "bord" but
393+ more configurable
394+ [ex: &fltr[]=fram|<w1>|<w2>|<c1>|<c2>|<c3>]
395+ where <w1> is the width of the main border, <w2> is
396+ the width of each side of the bevel part, <c1> is the
397+ hex color of the main border, <c2> is the highlight
398+ bevel color, <c3> is the shadow bevel color
399+ - "drop" (DROP shadow)
400+ [ex: &fltr[]=drop|<d>|<w>|<clr>|<a>]
401+ where <d> is distance from image to shadow, <w> is
402+ width of shadow fade (not yet implemented), <clr> is
403+ the hex color of the shadow, and <a> is the angle of
404+ the shadow (default=225)
405+ - "crop" (CROP image)
406+ [ex: &fltr[]=crop|<l>|<r>|<t>|<b>]
407+ where <l> is the number of pixels to crop from the left
408+ side of the resized image; <r>, <t>, <b> are for right,
409+ top and bottom respectively. Where (0 < x < 1) the
410+ value will be used as a percentage of width/height.
411+ Left and top crops take precedence over right and
412+ bottom values. Cropping will be limited such that at
413+ least 1 pixel of width and height always remains.
414+ - "rot" (ROTate)
415+ [ex: &fltr[]=rot|<a>|<b>]
416+ where <a> is the rotation angle in degrees; <b> is the
417+ background hex color. Similar to regular "ra" parameter
418+ but is applied in filter order after regular processing
419+ so you can rotate output of other filters.
420+md5s = MD5 hash of the source image -- if this parameter is
421+ passed with the hash of the source image then the
422+ source image is not checked for existance or
423+ modification and the cached file is used (if
424+ available). If 'md5s' is passed an empty string then
425+ phpThumb.php dies and outputs the correct MD5 hash
426+ value. This parameter is the single-file equivalent
427+ of 'cache_source_filemtime_ignore_*' configuration
428+ paramters
429+ xto = EXIF Thumbnail Only - set to only extract EXIF
430+ thumbnail and not do any additional processing
431+ ra = Rotate by Angle: angle of rotation in degrees
432+ positive = counterclockwise, negative = clockwise
433+ ar = Auto Rotate: set to "x" to use EXIF orientation
434+ stored by camera. Can also be set to "l" or "L"
435+ for landscape, or "p" or "P" for portrait. "l"
436+ and "P" rotate the image clockwise, "L" and "p"
437+ rotate the image counter-clockwise.
438+ sfn = Source Frame Number - use this frame/page number for
439+ multi-frame/multi-page source images (GIF, TIFF, etc)
440+ aoe = Output Allow Enlarging - override the setting for
441+ $CONFIG['output_allow_enlarging'] (1=on, 0=off)
442+ ("far" and "iar" both override this and allow output
443+ larger than input)
444+ iar = Ignore Aspect Ratio - disable proportional resizing
445+ and stretch image to fit "h" & "w" (which must both
446+ be set). (1=on, 0=off) (overrides "far")
447+ far = Force Aspect Ratio - image will be created at size
448+ specified by "w" and "h" (which must both be set).
449+ Alignment: L=left,R=right,T=top,B=bottom,C=center
450+ BL,BR,TL,TR use the appropriate direction if the
451+ image is landscape or portrait.
452+maxb = MAXimum Byte size - output quality is auto-set to
453+ fit thumbnail into "maxb" bytes (compression
454+ quality is adjusted for JPEG, bit depth is adjusted
455+ for PNG and GIF)
456+down = filename to save image to. If this is set the
457+ browser will prompt to save to this filename rather
458+ than display the image
459+
460+// Deprecated:
461+file = if set then thumbnail will be rendered to this
462+ filename, not output and not cached.
463+ (Deprecated. Disabled by default since v1.6.0,
464+ unavailable in v1.7.5 and later. You should
465+ instantiate your own object instead)
466+goto = URL to redirect to after rendering image to file
467+ * Must begin with "http://"
468+ * Requires file parameter set
469+ (Deprecated. Disabled by default since v1.6.0,
470+ unavailable in v1.7.5 and later. You should
471+ instantiate your own object instead)
472+ err = custom error image filename instead of showing
473+ error messages (for use on production sites)
474+ (Deprecated. Disabled by default since v1.6.0,
475+ unavailable in v1.7.5 and later. You should
476+ instantiate your own object instead)
477+
478+
479+==============
480+General Notes:
481+==============
482+
483+* Always use the local image filename wherever possible
484+ rather than a full http:// URL because performance is
485+ much better, less (or no) use of temp files, and the
486+ last-modified check for cached files doesn't work for
487+ remote files. For example:
488+ good: phpThumb.php?src=/images/nicepic.jpg
489+ bad: phpThumb.php?src=/home/httpd/example/images/nicepic.jpg
490+ worse: phpThumb.php?src=http://example.com/images/nicepic.jpg
491+
492+* Thumbnails will be scaled proportionately to fit in a
493+ box of at most (width * height) pixels
494+ (unless "iar" is set)
495+
496+* Thumbnail caching for URL or database sources requires
497+ an absolute directory name for $config_cache_directory
498+ Physical file cached thumbnails will be recreated if
499+ the source file changes, but remote/database files
500+ cannot (modification time isn't readily available)
501+
502+* If you need a GUI interface to phpThumb(), or for a user
503+ to specify crop settings, or something like that please
504+ see the list of known programs in /demo/readme.demos.txt
505+
506+* Cropping images can be specified with either exact pixel
507+ values for sx/sy/sw/sh parameters, or if those are set
508+ to a value >0 and <1 then these are interpreted as a
509+ percentage of the source image width/height. For example,
510+ to crop 25% off all sides, you would specify parameters:
511+ phpThumb.php?src=pic.jpg&sx=.25&sy=.25&sw=.5&sh=.5
512+
513+* phpThumb() may have tempfile access issues on servers
514+ where Safe Mode is enabled, specificly when accessing
515+ a file over HTTP, or when a non-bundled version of GD
516+ is in use. Specifying "config_temp_directory" may help
517+
518+* Properly resolving /~user/ style filenames requires
519+ apache_lookup_uri(), which is missing or broken in
520+ Apache2, or if PHP is not installed as an Apache module.
521+ phpThumb() does try and work around this if it is
522+ unavailble, but you may have to specify a full filename
523+ for "src" if you encounter problems.
524+
525+* phpThumb() should work with PHP v4.0.6+, but seems to
526+ have a few quirks before v4.1.0
527+ EXIF thumbnail extraction requires PHP v4.2.0+
528+ Image rotation requires PHP v4.3.0+. There have been
529+ reports of problems with PHP older than v4.3.3
530+ Some image filters require PHP v5.0.0+
531+ Run /demo/phpThumb.demo.check.php to examine your server
532+
533+* phpThumb() works better and faster when ImageMagick is
534+ available. Most functions will work with only GD2, but
535+ speed is much faster with ImageMagick, and much larger
536+ images can be processed with ImageMagick than GD.
537+
538+* phpThumb() works with GD v1.x, but works better with
539+ GD v2.0+ because of the true-color image support
540+ and ImageCopyResampled(). Also, there appears to be a
541+ bug in ImageCopyResized() which is used with GD v1.x
542+ where the bottom and/or right line of pixels is set
543+ to the background color (due to a rounding error?)
544+ NOTE: Please use the bundled version of GD if at all
545+ possible (with PHP v4.3.0+) because the non-bundled
546+ version has bugs which may cause PHP to crash:
547+ * http://bugs.php.net/bug.php?id=21518
548+ * http://bugs.php.net/bug.php?id=24174
549+ phpThumb() has a workaround for the above bug but
550+ there may be other bugs, and the workaround is slow.
551+ Alpha transparent output requires GD >= 2.0.1 and
552+ PHP >= 4.3.2
553+ Most (if not all) filters require GD v2.x to function
554+ at all. But many filters can be handled by ImageMagick
555+ instead of GD.
556+
557+* Filters handled by ImageMagick or GD:
558+ - brit;cont;ds;sat;gray;clr;sep;gam;neg;th;rcd;flip;edge;
559+ emb;lvl;blur;gblr;usm;
560+* Filters handled only by ImageMagick:
561+ - none yet
562+* Filters handled only by GD + PHP5:
563+ - sblr;mean;smth;
564+* Filters handled only by GD2:
565+ - bvl;wmi;wmt;over;wb;hist;fram;drop;mask;elip;ric;bord;
--- /dev/null
+++ b/trunk/NP_TrimImage/sharedlibs/phpthumb/enableLeftTop.patch
@@ -0,0 +1,52 @@
1+enableLeftTop.patch
2+
3+Zoom-Cropの際に、sx,syを評価するようにするパッチ
4+
5+/*
6+ * Copyright (C) 2006 CLES. All rights reserved.
7+ *
8+ * This program is free software; you can redistribute it and/or
9+ * modify it under the terms of the GNU General Public License
10+ * as published by the Free Software Foundation; either version 2
11+ * of the License, or (at your option) any later version.
12+ *
13+ * This program is distributed in the hope that it will be useful,
14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+ * GNU General Public License for more details.
17+ *
18+ * You should have received a copy of the GNU General Public License
19+ * along with this program; if not, write to the Free Software
20+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21+ *
22+ * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
23+ * permission to link the code of this program with those files in the PEAR
24+ * library that are licensed under the PHP License (or with modified versions
25+ * of those files that use the same license as those files), and distribute
26+ * linked combinations including the two. You must obey the GNU General Public
27+ * License in all respects for all of the code used other than those files in
28+ * the PEAR library that are licensed under the PHP License. If you modify
29+ * this file, you may extend this exception to your version of the file,
30+ * but you are not obligated to do so. If you do not wish to do so, delete
31+ * this exception statement from your version.
32+*/
33+
34+--- phpthumb.class.php.org 2006-12-03 02:43:12.965183341 +0900
35++++ phpthumb.class.php 2006-12-03 02:43:52.306561152 +0900
36+@@ -2449,12 +2449,16 @@
37+ $this->thumbnailCropW = round($allowable_width);
38+ $this->thumbnailCropX = round(($this->source_width - $allowable_width) / 2);
39+
40++ // added by cles
41++ if( $this->sx !== null ) $this->thumbnailCropX = $this->sx;
42+ } elseif ($scaling_Y > $scaling_X) {
43+ // some of the height will need to be cropped
44+ $allowable_height = $this->source_height / $scaling_Y * $scaling_X;
45+ $this->thumbnailCropH = round($allowable_height);
46+ $this->thumbnailCropY = round(($this->source_height - $allowable_height) / 2);
47+
48++ // added by cles
49++ if( $this->sy !== null ) $this->thumbnailCropY = $this->sy;
50+ } else {
51+ // image fits perfectly, no cropping needed
52+ }
--- /dev/null
+++ b/trunk/NP_TrimImage/sharedlibs/phpthumb/phpthumb.bmp.php
@@ -0,0 +1,874 @@
1+<?php
2+/////////////////////////////////////////////////////////////////
3+/// getID3() by James Heinrich <info@getid3.org> //
4+// available at http://getid3.sourceforge.net //
5+// or http://www.getid3.org //
6+/////////////////////////////////////////////////////////////////
7+// See readme.txt for more details //
8+/////////////////////////////////////////////////////////////////
9+// //
10+// module.graphic.bmp.php //
11+// module for analyzing BMP Image files //
12+// dependencies: NONE //
13+// ///
14+/////////////////////////////////////////////////////////////////
15+// //
16+// Modified for use in phpThumb() - James Heinrich 2004.07.27 //
17+// //
18+/////////////////////////////////////////////////////////////////
19+
20+
21+class phpthumb_bmp {
22+
23+ function phpthumb_bmp() {
24+ return true;
25+ }
26+
27+ function phpthumb_bmp2gd(&$BMPdata, $truecolor=true) {
28+ $ThisFileInfo = array();
29+ if ($this->getid3_bmp($BMPdata, $ThisFileInfo, true, true)) {
30+ $gd = $this->PlotPixelsGD($ThisFileInfo['bmp'], $truecolor);
31+ return $gd;
32+ }
33+ return false;
34+ }
35+
36+ function phpthumb_bmpfile2gd($filename, $truecolor=true) {
37+ if ($fp = @fopen($filename, 'rb')) {
38+ $BMPdata = fread($fp, filesize($filename));
39+ fclose($fp);
40+ return $this->phpthumb_bmp2gd($BMPdata, $truecolor);
41+ }
42+ return false;
43+ }
44+
45+ function GD2BMPstring(&$gd_image) {
46+ $imageX = ImageSX($gd_image);
47+ $imageY = ImageSY($gd_image);
48+
49+ $BMP = '';
50+ for ($y = ($imageY - 1); $y >= 0; $y--) {
51+ $thisline = '';
52+ for ($x = 0; $x < $imageX; $x++) {
53+ $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
54+ $thisline .= chr($argb['blue']).chr($argb['green']).chr($argb['red']);
55+ }
56+ while (strlen($thisline) % 4) {
57+ $thisline .= "\x00";
58+ }
59+ $BMP .= $thisline;
60+ }
61+
62+ $bmpSize = strlen($BMP) + 14 + 40;
63+ // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
64+ $BITMAPFILEHEADER = 'BM'; // WORD bfType;
65+ $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String($bmpSize, 4); // DWORD bfSize;
66+ $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String( 0, 2); // WORD bfReserved1;
67+ $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String( 0, 2); // WORD bfReserved2;
68+ $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String( 54, 4); // DWORD bfOffBits;
69+
70+ // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
71+ $BITMAPINFOHEADER = phpthumb_functions::LittleEndian2String( 40, 4); // DWORD biSize;
72+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( $imageX, 4); // LONG biWidth;
73+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( $imageY, 4); // LONG biHeight;
74+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( 1, 2); // WORD biPlanes;
75+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( 24, 2); // WORD biBitCount;
76+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( 0, 4); // DWORD biCompression;
77+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( 0, 4); // DWORD biSizeImage;
78+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( 2835, 4); // LONG biXPelsPerMeter;
79+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( 2835, 4); // LONG biYPelsPerMeter;
80+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( 0, 4); // DWORD biClrUsed;
81+ $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String( 0, 4); // DWORD biClrImportant;
82+
83+ return $BITMAPFILEHEADER.$BITMAPINFOHEADER.$BMP;
84+ }
85+
86+ function getid3_bmp(&$BMPdata, &$ThisFileInfo, $ExtractPalette=false, $ExtractData=false) {
87+
88+ // shortcuts
89+ $ThisFileInfo['bmp']['header']['raw'] = array();
90+ $thisfile_bmp = &$ThisFileInfo['bmp'];
91+ $thisfile_bmp_header = &$thisfile_bmp['header'];
92+ $thisfile_bmp_header_raw = &$thisfile_bmp_header['raw'];
93+
94+ // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
95+ // all versions
96+ // WORD bfType;
97+ // DWORD bfSize;
98+ // WORD bfReserved1;
99+ // WORD bfReserved2;
100+ // DWORD bfOffBits;
101+
102+ $offset = 0;
103+ $overalloffset = 0;
104+ $BMPheader = substr($BMPdata, $overalloffset, 14 + 40);
105+ $overalloffset += (14 + 40);
106+
107+ $thisfile_bmp_header_raw['identifier'] = substr($BMPheader, $offset, 2);
108+ $offset += 2;
109+
110+ if ($thisfile_bmp_header_raw['identifier'] != 'BM') {
111+ $ThisFileInfo['error'][] = 'Expecting "BM" at offset '.intval(@$ThisFileInfo['avdataoffset']).', found "'.$thisfile_bmp_header_raw['identifier'].'"';
112+ unset($ThisFileInfo['fileformat']);
113+ unset($ThisFileInfo['bmp']);
114+ return false;
115+ }
116+
117+ $thisfile_bmp_header_raw['filesize'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
118+ $offset += 4;
119+ $thisfile_bmp_header_raw['reserved1'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
120+ $offset += 2;
121+ $thisfile_bmp_header_raw['reserved2'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
122+ $offset += 2;
123+ $thisfile_bmp_header_raw['data_offset'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
124+ $offset += 4;
125+ $thisfile_bmp_header_raw['header_size'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
126+ $offset += 4;
127+
128+
129+ // check if the hardcoded-to-1 "planes" is at offset 22 or 26
130+ $planes22 = $this->LittleEndian2Int(substr($BMPheader, 22, 2));
131+ $planes26 = $this->LittleEndian2Int(substr($BMPheader, 26, 2));
132+ if (($planes22 == 1) && ($planes26 != 1)) {
133+ $thisfile_bmp['type_os'] = 'OS/2';
134+ $thisfile_bmp['type_version'] = 1;
135+ } elseif (($planes26 == 1) && ($planes22 != 1)) {
136+ $thisfile_bmp['type_os'] = 'Windows';
137+ $thisfile_bmp['type_version'] = 1;
138+ } elseif ($thisfile_bmp_header_raw['header_size'] == 12) {
139+ $thisfile_bmp['type_os'] = 'OS/2';
140+ $thisfile_bmp['type_version'] = 1;
141+ } elseif ($thisfile_bmp_header_raw['header_size'] == 40) {
142+ $thisfile_bmp['type_os'] = 'Windows';
143+ $thisfile_bmp['type_version'] = 1;
144+ } elseif ($thisfile_bmp_header_raw['header_size'] == 84) {
145+ $thisfile_bmp['type_os'] = 'Windows';
146+ $thisfile_bmp['type_version'] = 4;
147+ } elseif ($thisfile_bmp_header_raw['header_size'] == 100) {
148+ $thisfile_bmp['type_os'] = 'Windows';
149+ $thisfile_bmp['type_version'] = 5;
150+ } else {
151+ $ThisFileInfo['error'][] = 'Unknown BMP subtype (or not a BMP file)';
152+ unset($ThisFileInfo['fileformat']);
153+ unset($ThisFileInfo['bmp']);
154+ return false;
155+ }
156+
157+ $ThisFileInfo['fileformat'] = 'bmp';
158+ $ThisFileInfo['video']['dataformat'] = 'bmp';
159+ $ThisFileInfo['video']['lossless'] = true;
160+ $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1;
161+
162+ if ($thisfile_bmp['type_os'] == 'OS/2') {
163+
164+ // OS/2-format BMP
165+ // http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm
166+
167+ // DWORD Size; /* Size of this structure in bytes */
168+ // DWORD Width; /* Bitmap width in pixels */
169+ // DWORD Height; /* Bitmap height in pixel */
170+ // WORD NumPlanes; /* Number of bit planes (color depth) */
171+ // WORD BitsPerPixel; /* Number of bits per pixel per plane */
172+
173+ $thisfile_bmp_header_raw['width'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
174+ $offset += 2;
175+ $thisfile_bmp_header_raw['height'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
176+ $offset += 2;
177+ $thisfile_bmp_header_raw['planes'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
178+ $offset += 2;
179+ $thisfile_bmp_header_raw['bits_per_pixel'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
180+ $offset += 2;
181+
182+ $ThisFileInfo['video']['resolution_x'] = $thisfile_bmp_header_raw['width'];
183+ $ThisFileInfo['video']['resolution_y'] = $thisfile_bmp_header_raw['height'];
184+ $ThisFileInfo['video']['codec'] = 'BI_RGB '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit';
185+ $ThisFileInfo['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel'];
186+
187+ if ($thisfile_bmp['type_version'] >= 2) {
188+ // DWORD Compression; /* Bitmap compression scheme */
189+ // DWORD ImageDataSize; /* Size of bitmap data in bytes */
190+ // DWORD XResolution; /* X resolution of display device */
191+ // DWORD YResolution; /* Y resolution of display device */
192+ // DWORD ColorsUsed; /* Number of color table indices used */
193+ // DWORD ColorsImportant; /* Number of important color indices */
194+ // WORD Units; /* Type of units used to measure resolution */
195+ // WORD Reserved; /* Pad structure to 4-byte boundary */
196+ // WORD Recording; /* Recording algorithm */
197+ // WORD Rendering; /* Halftoning algorithm used */
198+ // DWORD Size1; /* Reserved for halftoning algorithm use */
199+ // DWORD Size2; /* Reserved for halftoning algorithm use */
200+ // DWORD ColorEncoding; /* Color model used in bitmap */
201+ // DWORD Identifier; /* Reserved for application use */
202+
203+ $thisfile_bmp_header_raw['compression'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
204+ $offset += 4;
205+ $thisfile_bmp_header_raw['bmp_data_size'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
206+ $offset += 4;
207+ $thisfile_bmp_header_raw['resolution_h'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
208+ $offset += 4;
209+ $thisfile_bmp_header_raw['resolution_v'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
210+ $offset += 4;
211+ $thisfile_bmp_header_raw['colors_used'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
212+ $offset += 4;
213+ $thisfile_bmp_header_raw['colors_important'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
214+ $offset += 4;
215+ $thisfile_bmp_header_raw['resolution_units'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
216+ $offset += 2;
217+ $thisfile_bmp_header_raw['reserved1'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
218+ $offset += 2;
219+ $thisfile_bmp_header_raw['recording'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
220+ $offset += 2;
221+ $thisfile_bmp_header_raw['rendering'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
222+ $offset += 2;
223+ $thisfile_bmp_header_raw['size1'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
224+ $offset += 4;
225+ $thisfile_bmp_header_raw['size2'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
226+ $offset += 4;
227+ $thisfile_bmp_header_raw['color_encoding'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
228+ $offset += 4;
229+ $thisfile_bmp_header_raw['identifier'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
230+ $offset += 4;
231+
232+ $thisfile_bmp_header['compression'] = $this->BMPcompressionOS2Lookup($thisfile_bmp_header_raw['compression']);
233+
234+ $ThisFileInfo['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit';
235+ }
236+
237+ } elseif ($thisfile_bmp['type_os'] == 'Windows') {
238+
239+ // Windows-format BMP
240+
241+ // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
242+ // all versions
243+ // DWORD biSize;
244+ // LONG biWidth;
245+ // LONG biHeight;
246+ // WORD biPlanes;
247+ // WORD biBitCount;
248+ // DWORD biCompression;
249+ // DWORD biSizeImage;
250+ // LONG biXPelsPerMeter;
251+ // LONG biYPelsPerMeter;
252+ // DWORD biClrUsed;
253+ // DWORD biClrImportant;
254+
255+ $thisfile_bmp_header_raw['width'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4), true);
256+ $offset += 4;
257+ $thisfile_bmp_header_raw['height'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4), true);
258+ $offset += 4;
259+ $thisfile_bmp_header_raw['planes'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
260+ $offset += 2;
261+ $thisfile_bmp_header_raw['bits_per_pixel'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 2));
262+ $offset += 2;
263+ $thisfile_bmp_header_raw['compression'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
264+ $offset += 4;
265+ $thisfile_bmp_header_raw['bmp_data_size'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
266+ $offset += 4;
267+ $thisfile_bmp_header_raw['resolution_h'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4), true);
268+ $offset += 4;
269+ $thisfile_bmp_header_raw['resolution_v'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4), true);
270+ $offset += 4;
271+ $thisfile_bmp_header_raw['colors_used'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
272+ $offset += 4;
273+ $thisfile_bmp_header_raw['colors_important'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
274+ $offset += 4;
275+
276+ $thisfile_bmp_header['compression'] = $this->BMPcompressionWindowsLookup($thisfile_bmp_header_raw['compression']);
277+ $ThisFileInfo['video']['resolution_x'] = $thisfile_bmp_header_raw['width'];
278+ $ThisFileInfo['video']['resolution_y'] = $thisfile_bmp_header_raw['height'];
279+ $ThisFileInfo['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit';
280+ $ThisFileInfo['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel'];
281+
282+ if (($thisfile_bmp['type_version'] >= 4) || ($thisfile_bmp_header_raw['compression'] == 3)) {
283+ // should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen
284+ $BMPheader .= substr($BMPdata, $overalloffset, 44);
285+ $overalloffset += 44;
286+
287+ // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp
288+ // Win95+, WinNT4.0+
289+ // DWORD bV4RedMask;
290+ // DWORD bV4GreenMask;
291+ // DWORD bV4BlueMask;
292+ // DWORD bV4AlphaMask;
293+ // DWORD bV4CSType;
294+ // CIEXYZTRIPLE bV4Endpoints;
295+ // DWORD bV4GammaRed;
296+ // DWORD bV4GammaGreen;
297+ // DWORD bV4GammaBlue;
298+ $thisfile_bmp_header_raw['red_mask'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
299+ $offset += 4;
300+ $thisfile_bmp_header_raw['green_mask'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
301+ $offset += 4;
302+ $thisfile_bmp_header_raw['blue_mask'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
303+ $offset += 4;
304+ $thisfile_bmp_header_raw['alpha_mask'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
305+ $offset += 4;
306+ $thisfile_bmp_header_raw['cs_type'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
307+ $offset += 4;
308+ $thisfile_bmp_header_raw['ciexyz_red'] = substr($BMPheader, $offset, 4);
309+ $offset += 4;
310+ $thisfile_bmp_header_raw['ciexyz_green'] = substr($BMPheader, $offset, 4);
311+ $offset += 4;
312+ $thisfile_bmp_header_raw['ciexyz_blue'] = substr($BMPheader, $offset, 4);
313+ $offset += 4;
314+ $thisfile_bmp_header_raw['gamma_red'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
315+ $offset += 4;
316+ $thisfile_bmp_header_raw['gamma_green'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
317+ $offset += 4;
318+ $thisfile_bmp_header_raw['gamma_blue'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
319+ $offset += 4;
320+
321+ $thisfile_bmp_header['ciexyz_red'] = $this->FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_red']));
322+ $thisfile_bmp_header['ciexyz_green'] = $this->FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_green']));
323+ $thisfile_bmp_header['ciexyz_blue'] = $this->FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_blue']));
324+ }
325+
326+ if ($thisfile_bmp['type_version'] >= 5) {
327+ $BMPheader .= substr($BMPdata, $overalloffset, 16);
328+ $overalloffset += 16;
329+
330+ // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp
331+ // Win98+, Win2000+
332+ // DWORD bV5Intent;
333+ // DWORD bV5ProfileData;
334+ // DWORD bV5ProfileSize;
335+ // DWORD bV5Reserved;
336+ $thisfile_bmp_header_raw['intent'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
337+ $offset += 4;
338+ $thisfile_bmp_header_raw['profile_data_offset'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
339+ $offset += 4;
340+ $thisfile_bmp_header_raw['profile_data_size'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
341+ $offset += 4;
342+ $thisfile_bmp_header_raw['reserved3'] = $this->LittleEndian2Int(substr($BMPheader, $offset, 4));
343+ $offset += 4;
344+ }
345+
346+ } else {
347+
348+ $ThisFileInfo['error'][] = 'Unknown BMP format in header.';
349+ return false;
350+
351+ }
352+
353+ if ($ExtractPalette || $ExtractData) {
354+ $PaletteEntries = 0;
355+ if ($thisfile_bmp_header_raw['bits_per_pixel'] < 16) {
356+ $PaletteEntries = pow(2, $thisfile_bmp_header_raw['bits_per_pixel']);
357+ } elseif (isset($thisfile_bmp_header_raw['colors_used']) && ($thisfile_bmp_header_raw['colors_used'] > 0) && ($thisfile_bmp_header_raw['colors_used'] <= 256)) {
358+ $PaletteEntries = $thisfile_bmp_header_raw['colors_used'];
359+ }
360+ if ($PaletteEntries > 0) {
361+ $BMPpalette = substr($BMPdata, $overalloffset, 4 * $PaletteEntries);
362+ $overalloffset += 4 * $PaletteEntries;
363+
364+ $paletteoffset = 0;
365+ for ($i = 0; $i < $PaletteEntries; $i++) {
366+ // RGBQUAD - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_5f8y.asp
367+ // BYTE rgbBlue;
368+ // BYTE rgbGreen;
369+ // BYTE rgbRed;
370+ // BYTE rgbReserved;
371+ $blue = $this->LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
372+ $green = $this->LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
373+ $red = $this->LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1));
374+ if (($thisfile_bmp['type_os'] == 'OS/2') && ($thisfile_bmp['type_version'] == 1)) {
375+ // no padding byte
376+ } else {
377+ $paletteoffset++; // padding byte
378+ }
379+ $thisfile_bmp['palette'][$i] = (($red << 16) | ($green << 8) | ($blue));
380+ }
381+ }
382+ }
383+
384+ if ($ExtractData) {
385+ $RowByteLength = ceil(($thisfile_bmp_header_raw['width'] * ($thisfile_bmp_header_raw['bits_per_pixel'] / 8)) / 4) * 4; // round up to nearest DWORD boundry
386+
387+ $BMPpixelData = substr($BMPdata, $thisfile_bmp_header_raw['data_offset'], $thisfile_bmp_header_raw['height'] * $RowByteLength);
388+ $overalloffset = $thisfile_bmp_header_raw['data_offset'] + ($thisfile_bmp_header_raw['height'] * $RowByteLength);
389+
390+ $pixeldataoffset = 0;
391+ switch (@$thisfile_bmp_header_raw['compression']) {
392+
393+ case 0: // BI_RGB
394+ switch ($thisfile_bmp_header_raw['bits_per_pixel']) {
395+ case 1:
396+ for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) {
397+ for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) {
398+ $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++});
399+ for ($i = 7; $i >= 0; $i--) {
400+ $paletteindex = ($paletteindexbyte & (0x01 << $i)) >> $i;
401+ $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex];
402+ $col++;
403+ }
404+ }
405+ while (($pixeldataoffset % 4) != 0) {
406+ // lines are padded to nearest DWORD
407+ $pixeldataoffset++;
408+ }
409+ }
410+ break;
411+
412+ case 4:
413+ for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) {
414+ for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) {
415+ $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++});
416+ for ($i = 1; $i >= 0; $i--) {
417+ $paletteindex = ($paletteindexbyte & (0x0F << (4 * $i))) >> (4 * $i);
418+ $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex];
419+ $col++;
420+ }
421+ }
422+ while (($pixeldataoffset % 4) != 0) {
423+ // lines are padded to nearest DWORD
424+ $pixeldataoffset++;
425+ }
426+ }
427+ break;
428+
429+ case 8:
430+ for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) {
431+ for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) {
432+ $paletteindex = ord($BMPpixelData{$pixeldataoffset++});
433+ $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex];
434+ }
435+ while (($pixeldataoffset % 4) != 0) {
436+ // lines are padded to nearest DWORD
437+ $pixeldataoffset++;
438+ }
439+ }
440+ break;
441+
442+ case 24:
443+ for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) {
444+ for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) {
445+ $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset});
446+ $pixeldataoffset += 3;
447+ }
448+ while (($pixeldataoffset % 4) != 0) {
449+ // lines are padded to nearest DWORD
450+ $pixeldataoffset++;
451+ }
452+ }
453+ break;
454+
455+ case 32:
456+ for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) {
457+ for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) {
458+ $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData{$pixeldataoffset+3}) << 24) | (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset});
459+ $pixeldataoffset += 4;
460+ }
461+ while (($pixeldataoffset % 4) != 0) {
462+ // lines are padded to nearest DWORD
463+ $pixeldataoffset++;
464+ }
465+ }
466+ break;
467+
468+ case 16:
469+ // ?
470+ break;
471+
472+ default:
473+ $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data';
474+ break;
475+ }
476+ break;
477+
478+
479+ case 1: // BI_RLE8 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp
480+ switch ($thisfile_bmp_header_raw['bits_per_pixel']) {
481+ case 8:
482+ $pixelcounter = 0;
483+ while ($pixeldataoffset < strlen($BMPpixelData)) {
484+ $firstbyte = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
485+ $secondbyte = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
486+ if ($firstbyte == 0) {
487+
488+ // escaped/absolute mode - the first byte of the pair can be set to zero to
489+ // indicate an escape character that denotes the end of a line, the end of
490+ // a bitmap, or a delta, depending on the value of the second byte.
491+ switch ($secondbyte) {
492+ case 0:
493+ // end of line
494+ // no need for special processing, just ignore
495+ break;
496+
497+ case 1:
498+ // end of bitmap
499+ $pixeldataoffset = strlen($BMPpixelData); // force to exit loop just in case
500+ break;
501+
502+ case 2:
503+ // delta - The 2 bytes following the escape contain unsigned values
504+ // indicating the horizontal and vertical offsets of the next pixel
505+ // from the current position.
506+ $colincrement = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
507+ $rowincrement = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
508+ $col = ($pixelcounter % $thisfile_bmp_header_raw['width']) + $colincrement;
509+ $row = ($thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width'])) - $rowincrement;
510+ $pixelcounter = ($row * $thisfile_bmp_header_raw['width']) + $col;
511+ break;
512+
513+ default:
514+ // In absolute mode, the first byte is zero and the second byte is a
515+ // value in the range 03H through FFH. The second byte represents the
516+ // number of bytes that follow, each of which contains the color index
517+ // of a single pixel. Each run must be aligned on a word boundary.
518+ for ($i = 0; $i < $secondbyte; $i++) {
519+ $paletteindex = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
520+ $col = $pixelcounter % $thisfile_bmp_header_raw['width'];
521+ $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']);
522+ $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex];
523+ $pixelcounter++;
524+ }
525+ while (($pixeldataoffset % 2) != 0) {
526+ // Each run must be aligned on a word boundary.
527+ $pixeldataoffset++;
528+ }
529+ break;
530+ }
531+
532+ } else {
533+
534+ // encoded mode - the first byte specifies the number of consecutive pixels
535+ // to be drawn using the color index contained in the second byte.
536+ for ($i = 0; $i < $firstbyte; $i++) {
537+ $col = $pixelcounter % $thisfile_bmp_header_raw['width'];
538+ $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']);
539+ $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$secondbyte];
540+ $pixelcounter++;
541+ }
542+
543+ }
544+ }
545+ break;
546+
547+ default:
548+ $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data';
549+ break;
550+ }
551+ break;
552+
553+
554+
555+ case 2: // BI_RLE4 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp
556+ switch ($thisfile_bmp_header_raw['bits_per_pixel']) {
557+ case 4:
558+ $pixelcounter = 0;
559+ while ($pixeldataoffset < strlen($BMPpixelData)) {
560+ $firstbyte = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
561+ $secondbyte = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
562+ if ($firstbyte == 0) {
563+
564+ // escaped/absolute mode - the first byte of the pair can be set to zero to
565+ // indicate an escape character that denotes the end of a line, the end of
566+ // a bitmap, or a delta, depending on the value of the second byte.
567+ switch ($secondbyte) {
568+ case 0:
569+ // end of line
570+ // no need for special processing, just ignore
571+ break;
572+
573+ case 1:
574+ // end of bitmap
575+ $pixeldataoffset = strlen($BMPpixelData); // force to exit loop just in case
576+ break;
577+
578+ case 2:
579+ // delta - The 2 bytes following the escape contain unsigned values
580+ // indicating the horizontal and vertical offsets of the next pixel
581+ // from the current position.
582+ $colincrement = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
583+ $rowincrement = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
584+ $col = ($pixelcounter % $thisfile_bmp_header_raw['width']) + $colincrement;
585+ $row = ($thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width'])) - $rowincrement;
586+ $pixelcounter = ($row * $thisfile_bmp_header_raw['width']) + $col;
587+ break;
588+
589+ default:
590+ // In absolute mode, the first byte is zero. The second byte contains the number
591+ // of color indexes that follow. Subsequent bytes contain color indexes in their
592+ // high- and low-order 4 bits, one color index for each pixel. In absolute mode,
593+ // each run must be aligned on a word boundary.
594+ unset($paletteindexes);
595+ for ($i = 0; $i < ceil($secondbyte / 2); $i++) {
596+ $paletteindexbyte = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1));
597+ $paletteindexes[] = ($paletteindexbyte & 0xF0) >> 4;
598+ $paletteindexes[] = ($paletteindexbyte & 0x0F);
599+ }
600+ while (($pixeldataoffset % 2) != 0) {
601+ // Each run must be aligned on a word boundary.
602+ $pixeldataoffset++;
603+ }
604+
605+ foreach ($paletteindexes as $dummy => $paletteindex) {
606+ $col = $pixelcounter % $thisfile_bmp_header_raw['width'];
607+ $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']);
608+ $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex];
609+ $pixelcounter++;
610+ }
611+ break;
612+ }
613+
614+ } else {
615+
616+ // encoded mode - the first byte of the pair contains the number of pixels to be
617+ // drawn using the color indexes in the second byte. The second byte contains two
618+ // color indexes, one in its high-order 4 bits and one in its low-order 4 bits.
619+ // The first of the pixels is drawn using the color specified by the high-order
620+ // 4 bits, the second is drawn using the color in the low-order 4 bits, the third
621+ // is drawn using the color in the high-order 4 bits, and so on, until all the
622+ // pixels specified by the first byte have been drawn.
623+ $paletteindexes[0] = ($secondbyte & 0xF0) >> 4;
624+ $paletteindexes[1] = ($secondbyte & 0x0F);
625+ for ($i = 0; $i < $firstbyte; $i++) {
626+ $col = $pixelcounter % $thisfile_bmp_header_raw['width'];
627+ $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']);
628+ $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindexes[($i % 2)]];
629+ $pixelcounter++;
630+ }
631+
632+ }
633+ }
634+ break;
635+
636+ default:
637+ $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data';
638+ break;
639+ }
640+ break;
641+
642+
643+ case 3: // BI_BITFIELDS
644+ switch ($thisfile_bmp_header_raw['bits_per_pixel']) {
645+ case 16:
646+ case 32:
647+ $redshift = 0;
648+ $greenshift = 0;
649+ $blueshift = 0;
650+ if (!$thisfile_bmp_header_raw['red_mask'] || !$thisfile_bmp_header_raw['green_mask'] || !$thisfile_bmp_header_raw['blue_mask']) {
651+ $ThisFileInfo['error'][] = 'missing $thisfile_bmp_header_raw[(red|green|blue)_mask]';
652+ return false;
653+ }
654+ while ((($thisfile_bmp_header_raw['red_mask'] >> $redshift) & 0x01) == 0) {
655+ $redshift++;
656+ }
657+ while ((($thisfile_bmp_header_raw['green_mask'] >> $greenshift) & 0x01) == 0) {
658+ $greenshift++;
659+ }
660+ while ((($thisfile_bmp_header_raw['blue_mask'] >> $blueshift) & 0x01) == 0) {
661+ $blueshift++;
662+ }
663+ for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) {
664+ for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) {
665+ $pixelvalue = $this->LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset, $thisfile_bmp_header_raw['bits_per_pixel'] / 8));
666+ $pixeldataoffset += $thisfile_bmp_header_raw['bits_per_pixel'] / 8;
667+
668+ $red = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['red_mask']) >> $redshift) / ($thisfile_bmp_header_raw['red_mask'] >> $redshift)) * 255));
669+ $green = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['green_mask']) >> $greenshift) / ($thisfile_bmp_header_raw['green_mask'] >> $greenshift)) * 255));
670+ $blue = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['blue_mask']) >> $blueshift) / ($thisfile_bmp_header_raw['blue_mask'] >> $blueshift)) * 255));
671+ $thisfile_bmp['data'][$row][$col] = (($red << 16) | ($green << 8) | ($blue));
672+ }
673+ while (($pixeldataoffset % 4) != 0) {
674+ // lines are padded to nearest DWORD
675+ $pixeldataoffset++;
676+ }
677+ }
678+ break;
679+
680+ default:
681+ $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data';
682+ break;
683+ }
684+ break;
685+
686+
687+ default: // unhandled compression type
688+ $ThisFileInfo['error'][] = 'Unknown/unhandled compression type value ('.$thisfile_bmp_header_raw['compression'].') - cannot decompress pixel data';
689+ break;
690+ }
691+ }
692+
693+ return true;
694+ }
695+
696+ function IntColor2RGB($color) {
697+ $red = ($color & 0x00FF0000) >> 16;
698+ $green = ($color & 0x0000FF00) >> 8;
699+ $blue = ($color & 0x000000FF);
700+ return array($red, $green, $blue);
701+ }
702+
703+ function PlotPixelsGD(&$BMPdata, $truecolor=true) {
704+ $imagewidth = $BMPdata['header']['raw']['width'];
705+ $imageheight = $BMPdata['header']['raw']['height'];
706+
707+ if ($truecolor) {
708+
709+ $gd = @ImageCreateTrueColor($imagewidth, $imageheight);
710+
711+ } else {
712+
713+ $gd = @ImageCreate($imagewidth, $imageheight);
714+ if (!empty($BMPdata['palette'])) {
715+ // create GD palette from BMP palette
716+ foreach ($BMPdata['palette'] as $dummy => $color) {
717+ list($r, $g, $b) = $this->IntColor2RGB($color);
718+ ImageColorAllocate($gd, $r, $g, $b);
719+ }
720+ } else {
721+ // create 216-color websafe palette
722+ for ($r = 0x00; $r <= 0xFF; $r += 0x33) {
723+ for ($g = 0x00; $g <= 0xFF; $g += 0x33) {
724+ for ($b = 0x00; $b <= 0xFF; $b += 0x33) {
725+ ImageColorAllocate($gd, $r, $g, $b);
726+ }
727+ }
728+ }
729+ }
730+
731+ }
732+ if (!is_resource($gd)) {
733+ return false;
734+ }
735+
736+ foreach ($BMPdata['data'] as $row => $colarray) {
737+ @set_time_limit(30);
738+ foreach ($colarray as $col => $color) {
739+ list($red, $green, $blue) = $this->IntColor2RGB($color);
740+ if ($truecolor) {
741+ $pixelcolor = ImageColorAllocate($gd, $red, $green, $blue);
742+ } else {
743+ $pixelcolor = ImageColorClosest($gd, $red, $green, $blue);
744+ }
745+ ImageSetPixel($gd, $col, $row, $pixelcolor);
746+ }
747+ }
748+ return $gd;
749+ }
750+
751+ function PlotBMP(&$BMPinfo) {
752+ $starttime = time();
753+ if (!isset($BMPinfo['bmp']['data']) || !is_array($BMPinfo['bmp']['data'])) {
754+ echo 'ERROR: no pixel data<BR>';
755+ return false;
756+ }
757+ set_time_limit(intval(round($BMPinfo['resolution_x'] * $BMPinfo['resolution_y'] / 10000)));
758+ $im = $this->PlotPixelsGD($BMPinfo['bmp']);
759+ if (headers_sent()) {
760+ echo 'plotted '.($BMPinfo['resolution_x'] * $BMPinfo['resolution_y']).' pixels in '.(time() - $starttime).' seconds<BR>';
761+ ImageDestroy($im);
762+ exit;
763+ } else {
764+ header('Content-Type: image/png');
765+ ImagePNG($im);
766+ ImageDestroy($im);
767+ return true;
768+ }
769+ return false;
770+ }
771+
772+ function BMPcompressionWindowsLookup($compressionid) {
773+ static $BMPcompressionWindowsLookup = array(
774+ 0 => 'BI_RGB',
775+ 1 => 'BI_RLE8',
776+ 2 => 'BI_RLE4',
777+ 3 => 'BI_BITFIELDS',
778+ 4 => 'BI_JPEG',
779+ 5 => 'BI_PNG'
780+ );
781+ return (isset($BMPcompressionWindowsLookup[$compressionid]) ? $BMPcompressionWindowsLookup[$compressionid] : 'invalid');
782+ }
783+
784+ function BMPcompressionOS2Lookup($compressionid) {
785+ static $BMPcompressionOS2Lookup = array(
786+ 0 => 'BI_RGB',
787+ 1 => 'BI_RLE8',
788+ 2 => 'BI_RLE4',
789+ 3 => 'Huffman 1D',
790+ 4 => 'BI_RLE24',
791+ );
792+ return (isset($BMPcompressionOS2Lookup[$compressionid]) ? $BMPcompressionOS2Lookup[$compressionid] : 'invalid');
793+ }
794+
795+
796+ // from getid3.lib.php
797+
798+ function trunc($floatnumber) {
799+ // truncates a floating-point number at the decimal point
800+ // returns int (if possible, otherwise float)
801+ if ($floatnumber >= 1) {
802+ $truncatednumber = floor($floatnumber);
803+ } elseif ($floatnumber <= -1) {
804+ $truncatednumber = ceil($floatnumber);
805+ } else {
806+ $truncatednumber = 0;
807+ }
808+ if ($truncatednumber <= 1073741824) { // 2^30
809+ $truncatednumber = (int) $truncatednumber;
810+ }
811+ return $truncatednumber;
812+ }
813+
814+ function LittleEndian2Int($byteword) {
815+ $intvalue = 0;
816+ $byteword = strrev($byteword);
817+ $bytewordlen = strlen($byteword);
818+ for ($i = 0; $i < $bytewordlen; $i++) {
819+ $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
820+ }
821+ return $intvalue;
822+ }
823+
824+ function BigEndian2Int($byteword) {
825+ return $this->LittleEndian2Int(strrev($byteword));
826+ }
827+
828+ function BigEndian2Bin($byteword) {
829+ $binvalue = '';
830+ $bytewordlen = strlen($byteword);
831+ for ($i = 0; $i < $bytewordlen; $i++) {
832+ $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT);
833+ }
834+ return $binvalue;
835+ }
836+
837+ function FixedPoint2_30($rawdata) {
838+ $binarystring = $this->BigEndian2Bin($rawdata);
839+ return $this->Bin2Dec(substr($binarystring, 0, 2)) + (float) ($this->Bin2Dec(substr($binarystring, 2, 30)) / 1073741824);
840+ }
841+
842+ function Bin2Dec($binstring, $signed=false) {
843+ $signmult = 1;
844+ if ($signed) {
845+ if ($binstring{0} == '1') {
846+ $signmult = -1;
847+ }
848+ $binstring = substr($binstring, 1);
849+ }
850+ $decvalue = 0;
851+ for ($i = 0; $i < strlen($binstring); $i++) {
852+ $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i);
853+ }
854+ return $this->CastAsInt($decvalue * $signmult);
855+ }
856+
857+ function CastAsInt($floatnum) {
858+ // convert to float if not already
859+ $floatnum = (float) $floatnum;
860+
861+ // convert a float to type int, only if possible
862+ if ($this->trunc($floatnum) == $floatnum) {
863+ // it's not floating point
864+ if ($floatnum <= 1073741824) { // 2^30
865+ // it's within int range
866+ $floatnum = (int) $floatnum;
867+ }
868+ }
869+ return $floatnum;
870+ }
871+
872+}
873+
874+?>
\ No newline at end of file
--- /dev/null
+++ b/trunk/NP_TrimImage/sharedlibs/phpthumb/phpthumb.class.php
@@ -0,0 +1,3517 @@
1+<?php
2+//////////////////////////////////////////////////////////////
3+/// phpThumb() by James Heinrich <info@silisoftware.com> //
4+// available at http://phpthumb.sourceforge.net ///
5+//////////////////////////////////////////////////////////////
6+/// //
7+// See: phpthumb.readme.txt for usage instructions //
8+// ///
9+//////////////////////////////////////////////////////////////
10+
11+ob_start();
12+if (!include_once(dirname(__FILE__).'/phpthumb.functions.php')) {
13+ ob_end_flush();
14+ die('failed to include_once("'.realpath(dirname(__FILE__).'/phpthumb.functions.php').'")');
15+}
16+ob_end_clean();
17+
18+class phpthumb {
19+
20+ // public:
21+ // START PARAMETERS (for object mode and phpThumb.php)
22+ // See phpthumb.readme.txt for descriptions of what each of these values are
23+ var $src = null; // SouRCe filename
24+ var $new = null; // NEW image (phpThumb.php only)
25+ var $w = null; // Width
26+ var $h = null; // Height
27+ var $wp = null; // Width (Portrait Images Only)
28+ var $hp = null; // Height (Portrait Images Only)
29+ var $wl = null; // Width (Landscape Images Only)
30+ var $hl = null; // Height (Landscape Images Only)
31+ var $ws = null; // Width (Square Images Only)
32+ var $hs = null; // Height (Square Images Only)
33+ var $f = null; // Format
34+ var $q = 75; // jpeg output Quality
35+ var $sx = null; // Source crop top-left X position
36+ var $sy = null; // Source crop top-left Y position
37+ var $sw = null; // Source crop Width
38+ var $sh = null; // Source crop Height
39+ var $zc = null; // Zoom Crop
40+ var $bc = null; // Border Color
41+ var $bg = null; // BackGround color
42+ var $fltr = array(); // FiLTeRs
43+ var $goto = null; // GO TO url after processing
44+ var $err = null; // default ERRor image filename
45+ var $xto = null; // extract eXif Thumbnail Only
46+ var $ra = null; // Rotate by Angle
47+ var $ar = null; // Auto Rotate
48+ var $aoe = null; // Allow Output Enlargement
49+ var $far = null; // Fixed Aspect Ratio
50+ var $iar = null; // Ignore Aspect Ratio
51+ var $maxb = null; // MAXimum Bytes
52+ var $down = null; // DOWNload thumbnail filename
53+ var $md5s = null; // MD5 hash of Source image
54+ var $sfn = 0; // Source Frame Number
55+ var $dpi = 150; // Dots Per Inch for vector source formats
56+
57+ var $file = null; // >>>deprecated, DO NOT USE, will be removed in future versions<<<
58+
59+ var $phpThumbDebug = null;
60+ // END PARAMETERS
61+
62+
63+ // public:
64+ // START CONFIGURATION OPTIONS (for object mode only)
65+ // See phpThumb.config.php for descriptions of what each of these settings do
66+
67+ // * Directory Configuration
68+ var $config_cache_directory = null;
69+ var $config_cache_directory_depth = 0;
70+ var $config_cache_disable_warning = true;
71+ var $config_cache_source_enabled = false;
72+ var $config_cache_source_directory = null;
73+ var $config_temp_directory = null;
74+ var $config_document_root = null;
75+
76+ // * Default output configuration:
77+ var $config_output_format = 'jpeg';
78+ var $config_output_maxwidth = 0;
79+ var $config_output_maxheight = 0;
80+ var $config_output_interlace = true;
81+
82+ // * Error message configuration
83+ var $config_error_image_width = 400;
84+ var $config_error_image_height = 100;
85+ var $config_error_message_image_default = '';
86+ var $config_error_bgcolor = 'CCCCFF';
87+ var $config_error_textcolor = 'FF0000';
88+ var $config_error_fontsize = 1;
89+ var $config_error_die_on_error = false;
90+ var $config_error_silent_die_on_error = false;
91+ var $config_error_die_on_source_failure = true;
92+
93+ // * Anti-Hotlink Configuration:
94+ var $config_nohotlink_enabled = true;
95+ var $config_nohotlink_valid_domains = array();
96+ var $config_nohotlink_erase_image = true;
97+ var $config_nohotlink_text_message = 'Off-server thumbnailing is not allowed';
98+ // * Off-server Linking Configuration:
99+ var $config_nooffsitelink_enabled = false;
100+ var $config_nooffsitelink_valid_domains = array();
101+ var $config_nooffsitelink_require_refer = false;
102+ var $config_nooffsitelink_erase_image = true;
103+ var $config_nooffsitelink_text_message = 'Off-server linking is not allowed';
104+
105+ // * Border & Background default colors
106+ var $config_border_hexcolor = '000000';
107+ var $config_background_hexcolor = 'FFFFFF';
108+
109+ // * TrueType Fonts
110+ var $config_ttf_directory = '.';
111+
112+ var $config_max_source_pixels = null;
113+ var $config_use_exif_thumbnail_for_speed = false;
114+ var $allow_local_http_src = false;
115+
116+ var $config_imagemagick_path = null;
117+ var $config_prefer_imagemagick = true;
118+
119+ var $config_cache_maxage = null;
120+ var $config_cache_maxsize = null;
121+ var $config_cache_maxfiles = null;
122+ var $config_cache_source_filemtime_ignore_local = false;
123+ var $config_cache_source_filemtime_ignore_remote = true;
124+ var $config_cache_default_only_suffix = false;
125+ var $config_cache_force_passthru = true;
126+ var $config_cache_prefix = ''; // default value set in the constructor below
127+
128+ // * MySQL
129+ var $config_mysql_query = null;
130+ var $config_mysql_hostname = null;
131+ var $config_mysql_username = null;
132+ var $config_mysql_password = null;
133+ var $config_mysql_database = null;
134+
135+ // * Security
136+ var $config_high_security_enabled = false;
137+ var $config_high_security_password = null;
138+ var $config_disable_debug = false;
139+ var $config_allow_src_above_docroot = false;
140+ var $config_allow_src_above_phpthumb = true;
141+ var $config_allow_parameter_file = false;
142+ var $config_allow_parameter_goto = false;
143+
144+ // * HTTP fopen
145+ var $config_http_fopen_timeout = 10;
146+ var $config_http_follow_redirect = true;
147+
148+ // * Compatability
149+ var $config_disable_pathinfo_parsing = false;
150+ var $config_disable_imagecopyresampled = false;
151+ var $config_disable_onlycreateable_passthru = false;
152+
153+ var $config_http_user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7';
154+
155+ // END CONFIGURATION OPTIONS
156+
157+
158+ // public: error messages (read-only)
159+ var $debugmessages = array();
160+ var $debugtiming = array();
161+ var $fatalerror = null;
162+
163+
164+ // private: (should not be modified directly)
165+ var $thumbnailQuality = 75;
166+ var $thumbnailFormat = null;
167+
168+ var $sourceFilename = null;
169+ var $rawImageData = null;
170+ var $IMresizedData = null;
171+ var $outputImageData = null;
172+
173+ var $useRawIMoutput = false;
174+
175+ var $gdimg_output = null;
176+ var $gdimg_source = null;
177+
178+ var $getimagesizeinfo = null;
179+
180+ var $source_width = null;
181+ var $source_height = null;
182+
183+ var $thumbnailCropX = null;
184+ var $thumbnailCropY = null;
185+ var $thumbnailCropW = null;
186+ var $thumbnailCropH = null;
187+
188+ var $exif_thumbnail_width = null;
189+ var $exif_thumbnail_height = null;
190+ var $exif_thumbnail_type = null;
191+ var $exif_thumbnail_data = null;
192+ var $exif_raw_data = null;
193+
194+ var $thumbnail_width = null;
195+ var $thumbnail_height = null;
196+ var $thumbnail_image_width = null;
197+ var $thumbnail_image_height = null;
198+
199+ var $cache_filename = null;
200+
201+ var $AlphaCapableFormats = array('png', 'ico', 'gif');
202+ var $is_alpha = false;
203+
204+ var $iswindows = null;
205+
206+ var $phpthumb_version = '1.7.5-200610032215';
207+
208+ //////////////////////////////////////////////////////////////////////
209+
210+ // public: constructor
211+ function phpThumb() {
212+ $this->DebugTimingMessage('phpThumb() constructor', __FILE__, __LINE__);
213+ $this->DebugMessage('phpThumb() v'.$this->phpthumb_version, __FILE__, __LINE__);
214+ $this->config_max_source_pixels = round(max(intval(ini_get('memory_limit')), intval(get_cfg_var('memory_limit'))) * 1048576 * 0.20); // 20% of memory_limit
215+ $this->iswindows = (bool) (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN');
216+ $this->config_temp_directory = realpath($this->config_temp_directory ? $this->config_temp_directory : (getenv('TMPDIR') ? getenv('TMPDIR') : getenv('TMP')));
217+ $this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'] ? $_SERVER['DOCUMENT_ROOT'] : $this->config_document_root);
218+ $this->config_cache_prefix = 'phpThumb_cache_'.@$_SERVER['SERVER_NAME'];
219+
220+ $php_sapi_name = strtolower(function_exists('php_sapi_name') ? php_sapi_name() : '');
221+ if ($php_sapi_name == 'cli') {
222+ $this->config_allow_src_above_docroot = true;
223+ }
224+ }
225+
226+ // public:
227+ function setSourceFilename($sourceFilename) {
228+ $this->rawImageData = null;
229+ $this->sourceFilename = $sourceFilename;
230+ $this->src = $sourceFilename;
231+ $this->DebugMessage('setSourceFilename('.$sourceFilename.') set $this->sourceFilename to "'.$this->sourceFilename.'"', __FILE__, __LINE__);
232+ return true;
233+ }
234+
235+ // public:
236+ function setSourceData($rawImageData, $sourceFilename='') {
237+ $this->sourceFilename = null;
238+ $this->rawImageData = $rawImageData;
239+ $this->DebugMessage('setSourceData() setting $this->rawImageData ('.strlen($this->rawImageData).' bytes)', __FILE__, __LINE__);
240+ if ($this->config_cache_source_enabled) {
241+ $sourceFilename = ($sourceFilename ? $sourceFilename : md5($rawImageData));
242+ if (!is_dir($this->config_cache_source_directory)) {
243+ $this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not a directory');
244+ } elseif (!@is_writable($this->config_cache_source_directory)) {
245+ $this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not writable');
246+ }
247+ $this->DebugMessage('setSourceData() attempting to save source image to "'.$this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename).'"', __FILE__, __LINE__);
248+ if ($fp = @fopen($this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename), 'wb')) {
249+ fwrite($fp, $rawImageData);
250+ fclose($fp);
251+ } elseif (!$this->phpThumbDebug) {
252+ $this->ErrorImage('setSourceData() failed to write to source cache ('.$this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename).')');
253+ }
254+ }
255+ return true;
256+ }
257+
258+ // public:
259+ function setSourceImageResource($gdimg) {
260+ $this->gdimg_source = $gdimg;
261+ return true;
262+ }
263+
264+ // public:
265+ function setParameter($param, $value) {
266+ if ($param == 'src') {
267+ $this->setSourceFilename($this->ResolveFilenameToAbsolute($value));
268+ } elseif (@is_array($this->$param)) {
269+ if (is_array($value)) {
270+ foreach ($value as $arraykey => $arrayvalue) {
271+ array_push($this->$param, $arrayvalue);
272+ }
273+ } else {
274+ array_push($this->$param, $value);
275+ }
276+ } else {
277+ $this->$param = $value;
278+ }
279+ return true;
280+ }
281+
282+ // public:
283+ function getParameter($param) {
284+ //if (property_exists('phpThumb', $param)) {
285+ return $this->$param;
286+ //}
287+ //$this->DebugMessage('setParameter() attempting to get non-existant parameter "'.$param.'"', __FILE__, __LINE__);
288+ //return false;
289+ }
290+
291+
292+ // public:
293+ function GenerateThumbnail() {
294+
295+ $this->setOutputFormat();
296+ if ($this->phpThumbDebug == '8a') { $this->phpThumbDebug(); }
297+ $this->ResolveSource();
298+ if ($this->phpThumbDebug == '8b') { $this->phpThumbDebug(); }
299+ $this->SetCacheFilename();
300+ if ($this->phpThumbDebug == '8c') { $this->phpThumbDebug(); }
301+ $this->ExtractEXIFgetImageSize();
302+ if ($this->phpThumbDebug == '8d') { $this->phpThumbDebug(); }
303+ if ($this->useRawIMoutput) {
304+ $this->DebugMessage('Skipping rest of GenerateThumbnail() because $this->useRawIMoutput', __FILE__, __LINE__);
305+ return true;
306+ }
307+ if ($this->phpThumbDebug == '8e') { $this->phpThumbDebug(); }
308+ if (!$this->SourceImageToGD()) {
309+ $this->DebugMessage('SourceImageToGD() failed', __FILE__, __LINE__);
310+ return false;
311+ }
312+ if ($this->phpThumbDebug == '8f') { $this->phpThumbDebug(); }
313+ $this->Rotate();
314+ if ($this->phpThumbDebug == '8g') { $this->phpThumbDebug(); }
315+ $this->CreateGDoutput();
316+ if ($this->phpThumbDebug == '8h') { $this->phpThumbDebug(); }
317+
318+ switch ($this->far) {
319+ case 'L':
320+ case 'TL':
321+ case 'BL':
322+ $destination_offset_x = 0;
323+ $destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
324+ break;
325+ case 'R':
326+ case 'TR':
327+ case 'BR':
328+ $destination_offset_x = round($this->thumbnail_width - $this->thumbnail_image_width);
329+ $destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
330+ break;
331+ case 'T':
332+ case 'TL':
333+ case 'TR':
334+ $destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
335+ $destination_offset_y = 0;
336+ break;
337+ case 'B':
338+ case 'BL':
339+ case 'BR':
340+ $destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
341+ $destination_offset_y = round($this->thumbnail_height - $this->thumbnail_image_height);
342+ break;
343+ case 'C':
344+ default:
345+ $destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
346+ $destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
347+ }
348+
349+// // copy/resize image to appropriate dimensions
350+// $borderThickness = 0;
351+// if (!empty($this->fltr)) {
352+// foreach ($this->fltr as $key => $value) {
353+// if (ereg('^bord\|([0-9]+)', $value, $matches)) {
354+// $borderThickness = $matches[1];
355+// break;
356+// }
357+// }
358+// }
359+// if ($borderThickness > 0) {
360+// //$this->DebugMessage('Skipping ImageResizeFunction() because BorderThickness="'.$borderThickness.'"', __FILE__, __LINE__);
361+// $this->thumbnail_image_height /= 2;
362+// }
363+ $this->ImageResizeFunction(
364+ $this->gdimg_output,
365+ $this->gdimg_source,
366+ $destination_offset_x,
367+ $destination_offset_y,
368+ $this->thumbnailCropX,
369+ $this->thumbnailCropY,
370+ $this->thumbnail_image_width,
371+ $this->thumbnail_image_height,
372+ $this->thumbnailCropW,
373+ $this->thumbnailCropH
374+ );
375+
376+ $this->DebugMessage('memory_get_usage() after copy-resize = '.(function_exists('memory_get_usage') ? @memory_get_usage() : 'n/a'), __FILE__, __LINE__);
377+ ImageDestroy($this->gdimg_source);
378+ $this->DebugMessage('memory_get_usage() after ImageDestroy = '.(function_exists('memory_get_usage') ? @memory_get_usage() : 'n/a'), __FILE__, __LINE__);
379+
380+ if ($this->phpThumbDebug == '8i') { $this->phpThumbDebug(); }
381+ $this->AntiOffsiteLinking();
382+ if ($this->phpThumbDebug == '8j') { $this->phpThumbDebug(); }
383+ $this->ApplyFilters();
384+ if ($this->phpThumbDebug == '8k') { $this->phpThumbDebug(); }
385+ $this->AlphaChannelFlatten();
386+ if ($this->phpThumbDebug == '8l') { $this->phpThumbDebug(); }
387+ $this->MaxFileSize();
388+ if ($this->phpThumbDebug == '8m') { $this->phpThumbDebug(); }
389+
390+ $this->DebugMessage('GenerateThumbnail() completed successfully', __FILE__, __LINE__);
391+ return true;
392+ }
393+
394+
395+ // public:
396+ function RenderOutput() {
397+ if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
398+ $this->DebugMessage('RenderOutput() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
399+ return false;
400+ }
401+ if (!$this->thumbnailFormat) {
402+ $this->DebugMessage('RenderOutput() failed because $this->thumbnailFormat is empty', __FILE__, __LINE__);
403+ return false;
404+ }
405+ if ($this->useRawIMoutput) {
406+ $this->DebugMessage('RenderOutput copying $this->IMresizedData ('.strlen($this->IMresizedData).' bytes) to $this->outputImage', __FILE__, __LINE__);
407+ $this->outputImageData = $this->IMresizedData;
408+ return true;
409+ }
410+
411+ $builtin_formats = array();
412+ if (function_exists('ImageTypes')) {
413+ $imagetypes = ImageTypes();
414+ $builtin_formats['wbmp'] = (bool) ($imagetypes & IMG_WBMP);
415+ $builtin_formats['jpg'] = (bool) ($imagetypes & IMG_JPG);
416+ $builtin_formats['gif'] = (bool) ($imagetypes & IMG_GIF);
417+ $builtin_formats['png'] = (bool) ($imagetypes & IMG_PNG);
418+ }
419+ $this->DebugMessage('RenderOutput() attempting Image'.strtoupper(@$this->thumbnailFormat).'($this->gdimg_output)', __FILE__, __LINE__);
420+ ob_start();
421+ switch ($this->thumbnailFormat) {
422+ case 'wbmp':
423+ if (!@$builtin_formats['wbmp']) {
424+ $this->DebugMessage('GD does not have required built-in support for WBMP output', __FILE__, __LINE__);
425+ ob_end_clean();
426+ return false;
427+ }
428+ ImageJPEG($this->gdimg_output, null, $this->thumbnailQuality);
429+ $this->outputImageData = ob_get_contents();
430+ break;
431+
432+ case 'jpeg':
433+ case 'jpg': // should be "jpeg" not "jpg" but just in case...
434+ if (!@$builtin_formats['jpg']) {
435+ $this->DebugMessage('GD does not have required built-in support for JPEG output', __FILE__, __LINE__);
436+ ob_end_clean();
437+ return false;
438+ }
439+ ImageJPEG($this->gdimg_output, null, $this->thumbnailQuality);
440+ $this->outputImageData = ob_get_contents();
441+ break;
442+
443+ case 'png':
444+ if (!@$builtin_formats['png']) {
445+ $this->DebugMessage('GD does not have required built-in support for PNG output', __FILE__, __LINE__);
446+ ob_end_clean();
447+ return false;
448+ }
449+ ImagePNG($this->gdimg_output);
450+ $this->outputImageData = ob_get_contents();
451+ break;
452+
453+ case 'gif':
454+ if (!@$builtin_formats['gif']) {
455+ $this->DebugMessage('GD does not have required built-in support for GIF output', __FILE__, __LINE__);
456+ ob_end_clean();
457+ return false;
458+ }
459+ ImageGIF($this->gdimg_output);
460+ $this->outputImageData = ob_get_contents();
461+ break;
462+
463+ case 'bmp':
464+ $ImageOutFunction = '"builtin BMP output"';
465+ if (!@include_once(dirname(__FILE__).'/phpthumb.bmp.php')) {
466+ $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__);
467+ ob_end_clean();
468+ return false;
469+ }
470+ $phpthumb_bmp = new phpthumb_bmp();
471+ $this->outputImageData = $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
472+ unset($phpthumb_bmp);
473+ break;
474+
475+ case 'ico':
476+ $ImageOutFunction = '"builtin ICO output"';
477+ if (!@include_once(dirname(__FILE__).'/phpthumb.ico.php')) {
478+ $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__);
479+ ob_end_clean();
480+ return false;
481+ }
482+ $phpthumb_ico = new phpthumb_ico();
483+ $arrayOfOutputImages = array($this->gdimg_output);
484+ $this->outputImageData = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
485+ unset($phpthumb_ico);
486+ break;
487+
488+ default:
489+ $this->DebugMessage('RenderOutput failed because $this->thumbnailFormat "'.$this->thumbnailFormat.'" is not valid', __FILE__, __LINE__);
490+ ob_end_clean();
491+ return false;
492+ }
493+ ob_end_clean();
494+ if (!$this->outputImageData) {
495+ $this->DebugMessage('RenderOutput() for "'.$this->thumbnailFormat.'" failed', __FILE__, __LINE__);
496+ ob_end_clean();
497+ return false;
498+ }
499+ $this->DebugMessage('RenderOutput() completing with $this->outputImageData = '.strlen($this->outputImageData).' bytes', __FILE__, __LINE__);
500+ return true;
501+ }
502+
503+ function RenderToFile($filename) {
504+ if (eregi('^(f|ht)tps?\://', $filename)) {
505+ $this->DebugMessage('RenderToFile() failed because $filename ('.$filename.') is a URL', __FILE__, __LINE__);
506+ return false;
507+ }
508+ // render thumbnail to this file only, do not cache, do not output to browser
509+ //$renderfilename = $this->ResolveFilenameToAbsolute(dirname($filename)).DIRECTORY_SEPARATOR.basename($filename);
510+ $renderfilename = $filename;
511+ if (($filename{0} != '/') && ($filename{0} != '\\') && ($filename{1} != ':')) {
512+ $renderfilename = $this->ResolveFilenameToAbsolute($renderfilename);
513+ }
514+ if (!@is_writable(dirname($renderfilename))) {
515+ $this->DebugMessage('RenderToFile() failed because "'.dirname($renderfilename).'/" is not writable', __FILE__, __LINE__);
516+ return false;
517+ }
518+ if (@is_file($renderfilename) && !@is_writable($renderfilename)) {
519+ $this->DebugMessage('RenderToFile() failed because "'.$renderfilename.'" is not writable', __FILE__, __LINE__);
520+ return false;
521+ }
522+
523+ if ($this->RenderOutput()) {
524+ if (file_put_contents($renderfilename, $this->outputImageData)) {
525+ $this->DebugMessage('RenderToFile('.$renderfilename.') succeeded', __FILE__, __LINE__);
526+ return true;
527+ }
528+ if (!@file_exists($renderfilename)) {
529+ $this->DebugMessage('RenderOutput ['.$this->thumbnailFormat.'('.$renderfilename.')] did not appear to fail, but the output image does not exist either...', __FILE__, __LINE__);
530+ }
531+ } else {
532+ $this->DebugMessage('RenderOutput ['.$this->thumbnailFormat.'('.$renderfilename.')] failed', __FILE__, __LINE__);
533+ }
534+ return false;
535+ }
536+
537+
538+ // public:
539+ function OutputThumbnail() {
540+ if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
541+ $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
542+ return false;
543+ }
544+ if (headers_sent()) {
545+ return $this->ErrorImage('OutputThumbnail() failed - headers already sent');
546+ exit;
547+ }
548+
549+ if ($this->down) {
550+ $downloadfilename = ereg_replace('[/\\:\*\?"<>|]', '_', $this->down);
551+ if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
552+ $downloadfilename = trim($downloadfilename, '.');
553+ }
554+ if ($downloadfilename != $this->down) {
555+ $this->DebugMessage('renaming output file for "down" from "'.$this->down.'" to "'.$downloadfilename.'"', __FILE__, __LINE__);
556+ }
557+ if ($downloadfilename) {
558+ header('Content-Disposition: attachment; filename="'.$downloadfilename.'"');
559+ } else {
560+ $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__);
561+ }
562+ }
563+
564+ if ($this->useRawIMoutput) {
565+
566+ header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
567+ echo $this->IMresizedData;
568+
569+ } else {
570+
571+ $this->DebugMessage('ImageInterlace($this->gdimg_output, '.intval($this->config_output_interlace).')', __FILE__, __LINE__);
572+ ImageInterlace($this->gdimg_output, intval($this->config_output_interlace));
573+ switch ($this->thumbnailFormat) {
574+ case 'jpeg':
575+ header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
576+ $ImageOutFunction = 'image'.$this->thumbnailFormat;
577+ @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality);
578+ break;
579+
580+ case 'png':
581+ case 'gif':
582+ header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
583+ $ImageOutFunction = 'image'.$this->thumbnailFormat;
584+ @$ImageOutFunction($this->gdimg_output);
585+ break;
586+
587+ case 'bmp':
588+ if (!@include_once(dirname(__FILE__).'/phpthumb.bmp.php')) {
589+ $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__);
590+ return false;
591+ }
592+ $phpthumb_bmp = new phpthumb_bmp();
593+ if (is_object($phpthumb_bmp)) {
594+ $bmp_data = $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
595+ unset($phpthumb_bmp);
596+ if (!$bmp_data) {
597+ $this->DebugMessage('$phpthumb_bmp->GD2BMPstring() failed', __FILE__, __LINE__);
598+ return false;
599+ }
600+ header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
601+ echo $bmp_data;
602+ } else {
603+ $this->DebugMessage('new phpthumb_bmp() failed', __FILE__, __LINE__);
604+ return false;
605+ }
606+ break;
607+
608+ case 'ico':
609+ if (!@include_once(dirname(__FILE__).'/phpthumb.ico.php')) {
610+ $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__);
611+ return false;
612+ }
613+ $phpthumb_ico = new phpthumb_ico();
614+ if (is_object($phpthumb_ico)) {
615+ $arrayOfOutputImages = array($this->gdimg_output);
616+ $ico_data = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
617+ unset($phpthumb_ico);
618+ if (!$ico_data) {
619+ $this->DebugMessage('$phpthumb_ico->GD2ICOstring() failed', __FILE__, __LINE__);
620+ return false;
621+ }
622+ header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
623+ echo $ico_data;
624+ } else {
625+ $this->DebugMessage('new phpthumb_ico() failed', __FILE__, __LINE__);
626+ return false;
627+ }
628+ break;
629+
630+ default:
631+ $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "'.$this->thumbnailFormat.'" is not valid', __FILE__, __LINE__);
632+ return false;
633+ break;
634+ }
635+
636+ }
637+ return true;
638+ }
639+
640+
641+ // public:
642+ function CleanUpCacheDirectory() {
643+ if (($this->config_cache_maxage > 0) || ($this->config_cache_maxsize > 0) || ($this->config_cache_maxfiles > 0)) {
644+ $CacheDirOldFilesAge = array();
645+ $CacheDirOldFilesSize = array();
646+ if ($dirhandle = opendir($this->config_cache_directory)) {
647+ while ($oldcachefile = readdir($dirhandle)) {
648+ $fullfilename = $this->config_cache_directory.DIRECTORY_SEPARATOR.$oldcachefile;
649+ if (eregi('^phpThumb_cache_', $oldcachefile) && file_exists($fullfilename)) {
650+ $CacheDirOldFilesAge[$oldcachefile] = @fileatime($fullfilename);
651+ if ($CacheDirOldFilesAge[$oldcachefile] == 0) {
652+ $CacheDirOldFilesAge[$oldcachefile] = @filemtime($fullfilename);
653+ }
654+
655+ $CacheDirOldFilesSize[$oldcachefile] = @filesize($fullfilename);
656+ }
657+ }
658+ }
659+ asort($CacheDirOldFilesAge);
660+
661+ if ($this->config_cache_maxfiles > 0) {
662+ $TotalCachedFiles = count($CacheDirOldFilesAge);
663+ $DeletedKeys = array();
664+ foreach ($CacheDirOldFilesAge as $oldcachefile => $filedate) {
665+ if ($TotalCachedFiles > $this->config_cache_maxfiles) {
666+ $fullfilename = $this->config_cache_directory.DIRECTORY_SEPARATOR.$oldcachefile;
667+ if (@unlink($fullfilename)) {
668+ $TotalCachedFiles--;
669+ $DeletedKeys[] = $oldcachefile;
670+ }
671+ } else {
672+ // there are few enough files to keep the rest
673+ break;
674+ }
675+ }
676+ foreach ($DeletedKeys as $dummy => $oldcachefile) {
677+ unset($CacheDirOldFilesAge[$oldcachefile]);
678+ unset($CacheDirOldFilesSize[$oldcachefile]);
679+ }
680+ }
681+
682+ if ($this->config_cache_maxage > 0) {
683+ $mindate = time() - $this->config_cache_maxage;
684+ $DeletedKeys = array();
685+ foreach ($CacheDirOldFilesAge as $oldcachefile => $filedate) {
686+ if ($filedate > 0) {
687+ if ($filedate < $mindate) {
688+ $fullfilename = $this->config_cache_directory.DIRECTORY_SEPARATOR.$oldcachefile;
689+ if (@unlink($fullfilename)) {
690+ $DeletedKeys[] = $oldcachefile;
691+ }
692+ } else {
693+ // the rest of the files are new enough to keep
694+ break;
695+ }
696+ }
697+ }
698+ foreach ($DeletedKeys as $dummy => $oldcachefile) {
699+ unset($CacheDirOldFilesAge[$oldcachefile]);
700+ unset($CacheDirOldFilesSize[$oldcachefile]);
701+ }
702+ }
703+
704+ if ($this->config_cache_maxsize > 0) {
705+ $TotalCachedFileSize = array_sum($CacheDirOldFilesSize);
706+ $DeletedKeys = array();
707+ foreach ($CacheDirOldFilesAge as $oldcachefile => $filedate) {
708+ if ($TotalCachedFileSize > $this->config_cache_maxsize) {
709+ $fullfilename = $this->config_cache_directory.DIRECTORY_SEPARATOR.$oldcachefile;
710+ if (@unlink($fullfilename)) {
711+ $TotalCachedFileSize -= $CacheDirOldFilesSize[$oldcachefile];
712+ $DeletedKeys[] = $oldcachefile;
713+ }
714+ } else {
715+ // the total filesizes are small enough to keep the rest of the files
716+ break;
717+ }
718+ }
719+ foreach ($DeletedKeys as $dummy => $oldcachefile) {
720+ unset($CacheDirOldFilesAge[$oldcachefile]);
721+ unset($CacheDirOldFilesSize[$oldcachefile]);
722+ }
723+ }
724+
725+ }
726+ return true;
727+ }
728+
729+ //////////////////////////////////////////////////////////////////////
730+
731+ function ResolveSource() {
732+ if (is_resource($this->gdimg_source)) {
733+ $this->DebugMessage('ResolveSource() exiting because is_resource($this->gdimg_source)', __FILE__, __LINE__);
734+ return true;
735+ }
736+ if ($this->rawImageData) {
737+ $this->sourceFilename = null;
738+ $this->DebugMessage('ResolveSource() exiting because $this->rawImageData is set ('.number_format(strlen($this->rawImageData)).' bytes)', __FILE__, __LINE__);
739+ return true;
740+ }
741+ if ($this->sourceFilename) {
742+ $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->sourceFilename);
743+ $this->DebugMessage('$this->sourceFilename set to "'.$this->sourceFilename.'"', __FILE__, __LINE__);
744+ } elseif ($this->src) {
745+ $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->src);
746+ $this->DebugMessage('$this->sourceFilename set to "'.$this->sourceFilename.'" from $this->src ('.$this->src.')', __FILE__, __LINE__);
747+ } else {
748+ return $this->ErrorImage('$this->sourceFilename and $this->src are both empty');
749+ }
750+ if ($this->iswindows && ((substr($this->sourceFilename, 0, 2) == '//') || (substr($this->sourceFilename, 0, 2) == '\\\\'))) {
751+ // Windows \\share\filename.ext
752+ } elseif (eregi('^(f|ht)tps?\://', $this->sourceFilename)) {
753+ // URL
754+ if ($this->config_http_user_agent) {
755+ ini_set('user_agent', $this->config_http_user_agent);
756+ }
757+ } elseif (!@file_exists($this->sourceFilename)) {
758+ return $this->ErrorImage('"'.$this->sourceFilename.'" does not exist');
759+ } elseif (!@is_file($this->sourceFilename)) {
760+ return $this->ErrorImage('"'.$this->sourceFilename.'" is not a file');
761+ }
762+ return true;
763+ }
764+
765+ function setOutputFormat() {
766+ static $alreadyCalled = false;
767+ if ($this->thumbnailFormat && $alreadyCalled) {
768+ return true;
769+ }
770+ $alreadyCalled = true;
771+
772+ $AvailableImageOutputFormats = array();
773+ $AvailableImageOutputFormats[] = 'text';
774+ if (@is_readable(dirname(__FILE__).'/phpthumb.ico.php')) {
775+ $AvailableImageOutputFormats[] = 'ico';
776+ }
777+ if (@is_readable(dirname(__FILE__).'/phpthumb.bmp.php')) {
778+ $AvailableImageOutputFormats[] = 'bmp';
779+ }
780+
781+ $this->thumbnailFormat = 'ico';
782+
783+ // Set default output format based on what image types are available
784+ if (function_exists('ImageTypes')) {
785+ $imagetypes = ImageTypes();
786+ if ($imagetypes & IMG_WBMP) {
787+ $this->thumbnailFormat = 'wbmp';
788+ $AvailableImageOutputFormats[] = 'wbmp';
789+ }
790+ if ($imagetypes & IMG_GIF) {
791+ $this->thumbnailFormat = 'gif';
792+ $AvailableImageOutputFormats[] = 'gif';
793+ }
794+ if ($imagetypes & IMG_PNG) {
795+ $this->thumbnailFormat = 'png';
796+ $AvailableImageOutputFormats[] = 'png';
797+ }
798+ if ($imagetypes & IMG_JPG) {
799+ $this->thumbnailFormat = 'jpeg';
800+ $AvailableImageOutputFormats[] = 'jpeg';
801+ }
802+ } else {
803+ //return $this->ErrorImage('ImageTypes() does not exist - GD support might not be enabled?');
804+ $this->DebugMessage('ImageTypes() does not exist - GD support might not be enabled?', __FILE__, __LINE__);
805+ }
806+ if ($this->ImageMagickVersion()) {
807+ $IMformats = array('jpeg', 'png', 'gif', 'bmp', 'ico', 'wbmp');
808+ $this->DebugMessage('Addding ImageMagick formats to $AvailableImageOutputFormats ('.implode(';', $AvailableImageOutputFormats).')', __FILE__, __LINE__);
809+ foreach ($IMformats as $key => $format) {
810+ $AvailableImageOutputFormats[] = $format;
811+ }
812+ }
813+ $AvailableImageOutputFormats = array_unique($AvailableImageOutputFormats);
814+ $this->DebugMessage('$AvailableImageOutputFormats = array('.implode(';', $AvailableImageOutputFormats).')', __FILE__, __LINE__);
815+
816+ if (strtolower($this->config_output_format) == 'jpg') {
817+ $this->config_output_format = 'jpeg';
818+ }
819+ if (strtolower($this->f) == 'jpg') {
820+ $this->f = 'jpeg';
821+ }
822+ if (phpthumb_functions::CaseInsensitiveInArray($this->config_output_format, $AvailableImageOutputFormats)) {
823+ // set output format to config default if that format is available
824+ $this->DebugMessage('$this->thumbnailFormat set to $this->config_output_format "'.strtolower($this->config_output_format).'"', __FILE__, __LINE__);
825+ $this->thumbnailFormat = strtolower($this->config_output_format);
826+ } elseif ($this->config_output_format) {
827+ $this->DebugMessage('$this->thumbnailFormat staying as "'.$this->thumbnailFormat.'" because $this->config_output_format ('.strtolower($this->config_output_format).') is not in $AvailableImageOutputFormats', __FILE__, __LINE__);
828+ }
829+ if ($this->f && (phpthumb_functions::CaseInsensitiveInArray($this->f, $AvailableImageOutputFormats))) {
830+ // override output format if $this->f is set and that format is available
831+ $this->DebugMessage('$this->thumbnailFormat set to $this->f "'.strtolower($this->f).'"', __FILE__, __LINE__);
832+ $this->thumbnailFormat = strtolower($this->f);
833+ } elseif ($this->f) {
834+ $this->DebugMessage('$this->thumbnailFormat staying as "'.$this->thumbnailFormat.'" because $this->f ('.strtolower($this->f).') is not in $AvailableImageOutputFormats', __FILE__, __LINE__);
835+ }
836+
837+ // for JPEG images, quality 1 (worst) to 99 (best)
838+ // quality < 25 is nasty, with not much size savings - not recommended
839+ // problems with 100 - invalid JPEG?
840+ $this->thumbnailQuality = max(1, min(99, ($this->q ? $this->q : 75)));
841+ $this->DebugMessage('$this->thumbnailQuality set to "'.$this->thumbnailQuality.'"', __FILE__, __LINE__);
842+
843+ return true;
844+ }
845+
846+ function setCacheDirectory() {
847+ // resolve cache directory to absolute pathname
848+ $this->DebugMessage('setCacheDirectory() starting with config_cache_directory = "'.$this->config_cache_directory.'"', __FILE__, __LINE__);
849+ if (substr($this->config_cache_directory, 0, 1) == '.') {
850+ if (eregi('^(f|ht)tps?\://', $this->src)) {
851+ if (!$this->config_cache_disable_warning) {
852+ $this->ErrorImage('$this->config_cache_directory ('.$this->config_cache_directory.') cannot be used for remote images. Adjust "cache_directory" or "cache_disable_warning" in phpThumb.config.php');
853+ }
854+ } elseif ($this->src) {
855+ // resolve relative cache directory to source image
856+ $this->config_cache_directory = dirname($this->ResolveFilenameToAbsolute($this->src)).DIRECTORY_SEPARATOR.$this->config_cache_directory;
857+ } else {
858+ // $this->new is probably set
859+ }
860+ }
861+ if (substr($this->config_cache_directory, -1) == '/') {
862+ $this->config_cache_directory = substr($this->config_cache_directory, 0, -1);
863+ }
864+ if ($this->iswindows) {
865+ $this->config_cache_directory = str_replace('/', DIRECTORY_SEPARATOR, $this->config_cache_directory);
866+ }
867+ if ($this->config_cache_directory) {
868+ $real_cache_path = realpath($this->config_cache_directory);
869+ if (!$real_cache_path) {
870+ $this->DebugMessage('realpath($this->config_cache_directory) failed for "'.$this->config_cache_directory.'"', __FILE__, __LINE__);
871+ if (!is_dir($this->config_cache_directory)) {
872+ $this->DebugMessage('!is_dir('.$this->config_cache_directory.')', __FILE__, __LINE__);
873+ }
874+ }
875+ if ($real_cache_path) {
876+ $this->DebugMessage('setting config_cache_directory to realpath('.$this->config_cache_directory.') = "'.$real_cache_path.'"', __FILE__, __LINE__);
877+ $this->config_cache_directory = $real_cache_path;
878+ }
879+ }
880+ if (!is_dir($this->config_cache_directory)) {
881+ if (!$this->config_cache_disable_warning) {
882+ $this->ErrorImage('$this->config_cache_directory ('.$this->config_cache_directory.') does not exist. Adjust "cache_directory" or "cache_disable_warning" in phpThumb.config.php');
883+ }
884+ $this->DebugMessage('$this->config_cache_directory ('.$this->config_cache_directory.') is not a directory', __FILE__, __LINE__);
885+ $this->config_cache_directory = null;
886+ } elseif (!@is_writable($this->config_cache_directory)) {
887+ $this->DebugMessage('$this->config_cache_directory is not writable ('.$this->config_cache_directory.')', __FILE__, __LINE__);
888+ }
889+
890+ if (!@is_dir($this->config_temp_directory) || !@is_writable($this->config_temp_directory) && @is_dir($this->config_cache_directory) && @is_writable($this->config_cache_directory)) {
891+ $this->DebugMessage('setting $this->config_temp_directory = $this->config_cache_directory ('.$this->config_cache_directory.')', __FILE__, __LINE__);
892+ $this->config_temp_directory = $this->config_cache_directory;
893+ }
894+ return true;
895+ }
896+
897+
898+ function ResolveFilenameToAbsolute($filename) {
899+ if (!$filename) {
900+ return false;
901+ }
902+
903+ //if (eregi('^(f|ht)tps?\://', $filename)) {
904+ if (eregi('^[a-z0-9]+\:/{1,2}', $filename)) {
905+ // eg: http://host/path/file.jpg (HTTP URL)
906+ // eg: ftp://host/path/file.jpg (FTP URL)
907+ // eg: data1:/path/file.jpg (Netware path)
908+
909+ //$AbsoluteFilename = $filename;
910+ return $filename;
911+
912+ } elseif ($this->iswindows && ($filename{1} == ':')) {
913+
914+ // absolute pathname (Windows)
915+ $AbsoluteFilename = $filename;
916+
917+ } elseif ($this->iswindows && ((substr($filename, 0, 2) == '//') || (substr($filename, 0, 2) == '\\\\'))) {
918+
919+ // absolute pathname (Windows)
920+ $AbsoluteFilename = $filename;
921+
922+ } elseif ($filename{0} == '/') {
923+
924+ if (@is_readable($filename) && !@is_readable($this->config_document_root.$filename)) {
925+
926+ // absolute filename (*nix)
927+ $AbsoluteFilename = $filename;
928+
929+ } elseif ($filename{1} == '~') {
930+
931+ // /~user/path
932+ if ($ApacheLookupURIarray = phpthumb_functions::ApacheLookupURIarray($filename)) {
933+ $AbsoluteFilename = $ApacheLookupURIarray['filename'];
934+ } else {
935+ $AbsoluteFilename = realpath($filename);
936+ if (@is_readable($AbsoluteFilename)) {
937+ $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.'", but the correct filename ('.$AbsoluteFilename.') seems to have been resolved with realpath($filename)', __FILE__, __LINE__);
938+ } else {
939+ return $this->ErrorImage('phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.'". This has been known to fail on Apache2 - try using the absolute filename for the source image (ex: "/home/user/httpdocs/image.jpg" instead of "/~user/image.jpg")');
940+ }
941+ }
942+
943+ } else {
944+
945+ // relative filename (any OS)
946+ if (ereg('^'.preg_quote($this->config_document_root), $filename)) {
947+ $AbsoluteFilename = $filename;
948+ $this->DebugMessage('ResolveFilenameToAbsolute() NOT prepending $this->config_document_root ('.$this->config_document_root.') to $filename ('.$filename.') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.'")', __FILE__, __LINE__);
949+ } else {
950+ $AbsoluteFilename = $this->config_document_root.$filename;
951+ $this->DebugMessage('ResolveFilenameToAbsolute() prepending $this->config_document_root ('.$this->config_document_root.') to $filename ('.$filename.') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.'")', __FILE__, __LINE__);
952+ }
953+
954+ }
955+
956+ } else {
957+
958+ // relative to current directory (any OS)
959+ $AbsoluteFilename = $this->config_document_root.dirname(@$_SERVER['PHP_SELF']).DIRECTORY_SEPARATOR.$filename;
960+ //if (!@file_exists($AbsoluteFilename) && @file_exists(realpath($this->DotPadRelativeDirectoryPath($filename)))) {
961+ // $AbsoluteFilename = realpath($this->DotPadRelativeDirectoryPath($filename));
962+ //}
963+
964+ if (substr(dirname(@$_SERVER['PHP_SELF']), 0, 2) == '/~') {
965+ if ($ApacheLookupURIarray = phpthumb_functions::ApacheLookupURIarray(dirname(@$_SERVER['PHP_SELF']))) {
966+ $AbsoluteFilename = $ApacheLookupURIarray['filename'].DIRECTORY_SEPARATOR.$filename;
967+ } else {
968+ $AbsoluteFilename = realpath('.').DIRECTORY_SEPARATOR.$filename;
969+ if (@is_readable($AbsoluteFilename)) {
970+ $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname(@$_SERVER['PHP_SELF']).'", but the correct filename ('.$AbsoluteFilename.') seems to have been resolved with realpath(.)/$filename', __FILE__, __LINE__);
971+ } else {
972+ return $this->ErrorImage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname(@$_SERVER['PHP_SELF']).'". This has been known to fail on Apache2 - try using the absolute filename for the source image');
973+ }
974+ }
975+ }
976+
977+ }
978+ if (is_link($AbsoluteFilename)) {
979+ $this->DebugMessage('is_link()==true, changing "'.$AbsoluteFilename.'" to "'.readlink($AbsoluteFilename).'"', __FILE__, __LINE__);
980+ $AbsoluteFilename = readlink($AbsoluteFilename);
981+ }
982+ if (realpath($AbsoluteFilename)) {
983+ $AbsoluteFilename = realpath($AbsoluteFilename);
984+ }
985+ if ($this->iswindows) {
986+ $AbsoluteFilename = eregi_replace('^'.preg_quote(realpath($this->config_document_root)), realpath($this->config_document_root), $AbsoluteFilename);
987+ $AbsoluteFilename = str_replace(DIRECTORY_SEPARATOR, '/', $AbsoluteFilename);
988+ }
989+ if (!$this->config_allow_src_above_docroot && !ereg('^'.preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', realpath($this->config_document_root))), $AbsoluteFilename)) {
990+ $this->DebugMessage('!$this->config_allow_src_above_docroot therefore setting "'.$AbsoluteFilename.'" (outside "'.realpath($this->config_document_root).'") to null', __FILE__, __LINE__);
991+ return false;
992+ }
993+ if (!$this->config_allow_src_above_phpthumb && !ereg('^'.preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__))), $AbsoluteFilename)) {
994+ $this->DebugMessage('!$this->config_allow_src_above_phpthumb therefore setting "'.$AbsoluteFilename.'" (outside "'.dirname(__FILE__).'") to null', __FILE__, __LINE__);
995+ return false;
996+ }
997+ return $AbsoluteFilename;
998+ }
999+
1000+ function ImageMagickWhichConvert() {
1001+ static $WhichConvert = null;
1002+ if (is_null($WhichConvert)) {
1003+ if ($this->iswindows) {
1004+ $WhichConvert = false;
1005+ } else {
1006+ $WhichConvert = trim(phpthumb_functions::SafeExec('which convert'));
1007+ }
1008+ }
1009+ return $WhichConvert;
1010+ }
1011+
1012+ function ImageMagickCommandlineBase() {
1013+ static $commandline = null;
1014+ if (is_null($commandline)) {
1015+ $commandline = (!is_null($this->config_imagemagick_path) ? $this->config_imagemagick_path : '');
1016+
1017+ if ($this->config_imagemagick_path && ($this->config_imagemagick_path != realpath($this->config_imagemagick_path))) {
1018+ if (@is_executable(realpath($this->config_imagemagick_path))) {
1019+ $this->DebugMessage('Changing $this->config_imagemagick_path ('.$this->config_imagemagick_path.') to realpath($this->config_imagemagick_path) ('.realpath($this->config_imagemagick_path).')', __FILE__, __LINE__);
1020+ $this->config_imagemagick_path = realpath($this->config_imagemagick_path);
1021+ } else {
1022+ $this->DebugMessage('Leaving $this->config_imagemagick_path as ('.$this->config_imagemagick_path.') because !is_execuatable(realpath($this->config_imagemagick_path)) ('.realpath($this->config_imagemagick_path).')', __FILE__, __LINE__);
1023+ }
1024+ }
1025+ $this->DebugMessage(' file_exists('.$this->config_imagemagick_path.') = '.intval( @file_exists($this->config_imagemagick_path)), __FILE__, __LINE__);
1026+ $this->DebugMessage('is_executable('.$this->config_imagemagick_path.') = '.intval(@is_executable($this->config_imagemagick_path)), __FILE__, __LINE__);
1027+ if (@file_exists($this->config_imagemagick_path)) {
1028+ $this->DebugMessage('using ImageMagick path from $this->config_imagemagick_path ('.$this->config_imagemagick_path.')', __FILE__, __LINE__);
1029+ if ($this->iswindows) {
1030+ $commandline = substr($this->config_imagemagick_path, 0, 2).' && cd "'.str_replace('/', DIRECTORY_SEPARATOR, substr(dirname($this->config_imagemagick_path), 2)).'" && '.basename($this->config_imagemagick_path);
1031+ } else {
1032+ $commandline = '"'.$this->config_imagemagick_path.'"';
1033+ }
1034+ return $commandline;
1035+ }
1036+
1037+ $which_convert = $this->ImageMagickWhichConvert();
1038+ $IMversion = $this->ImageMagickVersion();
1039+
1040+ if ($which_convert && ($which_convert{0} == '/') && @file_exists($which_convert)) {
1041+
1042+ // `which convert` *should* return the path if "convert" exist, or nothing if it doesn't
1043+ // other things *may* get returned, like "sh: convert: not found" or "no convert in /usr/local/bin /usr/sbin /usr/bin /usr/ccs/bin"
1044+ // so only do this if the value returned exists as a file
1045+ $this->DebugMessage('using ImageMagick path from `which convert` ('.$which_convert.')', __FILE__, __LINE__);
1046+ $commandline = 'convert';
1047+
1048+ } elseif ($IMversion) {
1049+
1050+ $this->DebugMessage('setting ImageMagick path to $this->config_imagemagick_path ('.$this->config_imagemagick_path.') ['.$IMversion.']', __FILE__, __LINE__);
1051+ $commandline = $this->config_imagemagick_path;
1052+
1053+ } else {
1054+
1055+ $this->DebugMessage('ImageMagickThumbnailToGD() aborting because cannot find convert in $this->config_imagemagick_path ('.$this->config_imagemagick_path.'), and `which convert` returned ('.$which_convert.')', __FILE__, __LINE__);
1056+ $commandline = '';
1057+
1058+ }
1059+ }
1060+ return $commandline;
1061+ }
1062+
1063+ function ImageMagickVersion($returnRAW=false) {
1064+ static $versionstring = null;
1065+ if (is_null($versionstring)) {
1066+ $commandline = $this->ImageMagickCommandlineBase();
1067+ $commandline = (!is_null($commandline) ? $commandline : '');
1068+
1069+ $versionstring = array(0=>'', 1=>'');
1070+ if ($commandline) {
1071+ $commandline .= ' --version';
1072+ $this->DebugMessage('ImageMagick version checked with "'.$commandline.'"', __FILE__, __LINE__);
1073+ $versionstring[1] = trim(phpthumb_functions::SafeExec($commandline));
1074+ if (eregi('^Version: [^0-9]*([ 0-9\\.\\:Q/]+) (http|file)\:', $versionstring[1], $matches)) {
1075+ $versionstring[0] = $matches[1];
1076+ } else {
1077+ $versionstring[0] = false;
1078+ $this->DebugMessage('ImageMagick did not return recognized version string ('.$versionstring[1].')', __FILE__, __LINE__);
1079+ }
1080+ $this->DebugMessage('ImageMagick convert --version says "'.$matches[0].'"', __FILE__, __LINE__);
1081+ }
1082+ }
1083+ return @$versionstring[intval($returnRAW)];
1084+ }
1085+
1086+ function ImageMagickSwitchAvailable($switchname) {
1087+ static $IMoptions = null;
1088+ if (is_null($IMoptions)) {
1089+ $IMoptions = array();
1090+ $commandline = $this->ImageMagickCommandlineBase();
1091+ if (!is_null($commandline)) {
1092+ $commandline .= ' -help';
1093+ $IMhelp_lines = explode("\n", phpthumb_functions::SafeExec($commandline));
1094+ foreach ($IMhelp_lines as $line) {
1095+ if (ereg('^[\+\-]([a-z\-]+) ', trim($line), $matches)) {
1096+ $IMoptions[$matches[1]] = true;
1097+ }
1098+ }
1099+ }
1100+ }
1101+ if (is_array($switchname)) {
1102+ $allOK = true;
1103+ foreach ($switchname as $key => $value) {
1104+ if (!isset($IMoptions[$value])) {
1105+ $allOK = false;
1106+ break;
1107+ }
1108+ }
1109+ $this->DebugMessage('ImageMagickSwitchAvailable('.implode(';', $switchname).') = '.intval($allOK).'', __FILE__, __LINE__);
1110+ } else {
1111+ $allOK = isset($IMoptions[$switchname]);
1112+ $this->DebugMessage('ImageMagickSwitchAvailable('.$switchname.') = '.intval($allOK).'', __FILE__, __LINE__);
1113+ }
1114+ return $allOK;
1115+ }
1116+
1117+ function ImageMagickThumbnailToGD() {
1118+ // http://www.imagemagick.org/script/command-line-options.php
1119+
1120+ $this->useRawIMoutput = true;
1121+ if (phpthumb_functions::gd_version()) {
1122+ //$UnAllowedParameters = array('sx', 'sy', 'sw', 'sh', 'xto', 'ra', 'ar', 'bg', 'bc', 'fltr');
1123+ $UnAllowedParameters = array('xto', 'ra', 'ar', 'bg', 'bc', 'fltr');
1124+ foreach ($UnAllowedParameters as $dummy => $parameter) {
1125+ if ($this->$parameter) {
1126+ $this->DebugMessage('$this->useRawIMoutput=false because "'.$parameter.'" is set', __FILE__, __LINE__);
1127+ $this->useRawIMoutput = false;
1128+ break;
1129+ }
1130+ }
1131+ }
1132+ $outputFormat = $this->thumbnailFormat;
1133+ if (phpthumb_functions::gd_version()) {
1134+ if ($this->useRawIMoutput) {
1135+ switch ($this->thumbnailFormat) {
1136+ case 'gif':
1137+ $ImageCreateFunction = 'ImageCreateFromGIF';
1138+ $this->is_alpha = true;
1139+ break;
1140+ case 'png':
1141+ $ImageCreateFunction = 'ImageCreateFromPNG';
1142+ $this->is_alpha = true;
1143+ break;
1144+ case 'jpg':
1145+ case 'jpeg':
1146+ $ImageCreateFunction = 'ImageCreateFromJPEG';
1147+ break;
1148+ default:
1149+ $outputFormat = 'png';
1150+ $ImageCreateFunction = 'ImageCreateFromPNG';
1151+ $this->is_alpha = true;
1152+ $this->useRawIMoutput = false;
1153+ break;
1154+ }
1155+ if (!function_exists(@$ImageCreateFunction)) {
1156+ // ImageMagickThumbnailToGD() depends on ImageCreateFromPNG/ImageCreateFromGIF
1157+ //$this->DebugMessage('ImageMagickThumbnailToGD() aborting because '.@$ImageCreateFunction.'() is not available', __FILE__, __LINE__);
1158+ $this->useRawIMoutput = true;
1159+ //return false;
1160+ }
1161+ } else {
1162+ $outputFormat = 'png';
1163+ $ImageCreateFunction = 'ImageCreateFromPNG';
1164+ $this->is_alpha = true;
1165+ $this->useRawIMoutput = false;
1166+ }
1167+ }
1168+
1169+ // http://freealter.org/doc_distrib/ImageMagick-5.1.1/www/convert.html
1170+ if (!$this->sourceFilename) {
1171+ $this->DebugMessage('ImageMagickThumbnailToGD() aborting because $this->sourceFilename is empty', __FILE__, __LINE__);
1172+ $this->useRawIMoutput = false;
1173+ return false;
1174+ }
1175+ if (ini_get('safe_mode')) {
1176+ $this->DebugMessage('ImageMagickThumbnailToGD() aborting because safe_mode is enabled', __FILE__, __LINE__);
1177+ $this->useRawIMoutput = false;
1178+ return false;
1179+ }
1180+
1181+ $commandline = $this->ImageMagickCommandlineBase();
1182+ if ($commandline) {
1183+ if ($IMtempfilename = $this->phpThumb_tempnam()) {
1184+ $IMtempfilename = realpath($IMtempfilename);
1185+
1186+ $IMuseExplicitImageOutputDimensions = false;
1187+ if ($this->ImageMagickSwitchAvailable('thumbnail')) {
1188+ $IMresizeParameter = 'thumbnail';
1189+ } else {
1190+ $IMresizeParameter = 'resize';
1191+
1192+ // some (older? around 2002) versions of IM won't accept "-resize 100x" but require "-resize 100x100"
1193+ $commandline_test = $this->ImageMagickCommandlineBase().' logo: -resize 1x "'.$IMtempfilename.'" 2>&1';
1194+ $IMresult_test = phpthumb_functions::SafeExec($commandline_test);
1195+ $IMuseExplicitImageOutputDimensions = eregi('image dimensions are zero', $IMresult_test);
1196+ $this->DebugMessage('IMuseExplicitImageOutputDimensions = '.intval($IMuseExplicitImageOutputDimensions), __FILE__, __LINE__);
1197+ if ($fp_im_temp = @fopen($IMtempfilename, 'wb')) {
1198+ // erase temp image so ImageMagick logo doesn't get output if other processing fails
1199+ fclose($fp_im_temp);
1200+ }
1201+ }
1202+
1203+
1204+ if (!is_null($this->dpi) && $this->ImageMagickSwitchAvailable('modulate')) {
1205+ // for raster source formats only (WMF, PDF, etc)
1206+ $commandline .= ' -density '.$this->dpi;
1207+ }
1208+ ob_start();
1209+ $getimagesize = GetImageSize($this->sourceFilename);
1210+ $GetImageSizeError = ob_get_contents();
1211+ ob_end_clean();
1212+ if (is_array($getimagesize)) {
1213+ $this->DebugMessage('GetImageSize('.$this->sourceFilename.') SUCCEEDED: '.serialize($getimagesize), __FILE__, __LINE__);
1214+ } else {
1215+ $this->DebugMessage('GetImageSize('.$this->sourceFilename.') FAILED with error "'.$GetImageSizeError.'"', __FILE__, __LINE__);
1216+ }
1217+ if (is_array($getimagesize)) {
1218+ $this->DebugMessage('GetImageSize('.$this->sourceFilename.') returned [w='.$getimagesize[0].';h='.$getimagesize[1].';f='.$getimagesize[2].']', __FILE__, __LINE__);
1219+ $this->source_width = $getimagesize[0];
1220+ $this->source_height = $getimagesize[1];
1221+ $this->DebugMessage('source dimensions set to '.$this->source_width.'x'.$this->source_height, __FILE__, __LINE__);
1222+ $this->SetOrientationDependantWidthHeight();
1223+
1224+ if (!eregi('('.implode('|', $this->AlphaCapableFormats).')', $outputFormat)) {
1225+ // not a transparency-capable format
1226+ $commandline .= ' -background "#'.($this->bg ? $this->bg : 'FFFFFF').'"';
1227+ if ($getimagesize[2] == 1) {
1228+ $commandline .= ' -flatten';
1229+ }
1230+ }
1231+ if ($getimagesize[2] == 1) {
1232+ $commandline .= ' -coalesce'; // may be needed for animated GIFs
1233+ }
1234+ if ($this->source_width || $this->source_height) {
1235+ if ($this->zc) {
1236+
1237+ $borderThickness = 0;
1238+ if (!empty($this->fltr)) {
1239+ foreach ($this->fltr as $key => $value) {
1240+ if (ereg('^bord\|([0-9]+)', $value, $matches)) {
1241+ $borderThickness = $matches[1];
1242+ break;
1243+ }
1244+ }
1245+ }
1246+ $wAll = intval(max($this->w, $this->wp, $this->wl, $this->ws)) - (2 * $borderThickness);
1247+ $hAll = intval(max($this->h, $this->hp, $this->hl, $this->hs)) - (2 * $borderThickness);
1248+ $imAR = $this->source_width / $this->source_height;
1249+ //$zcAR = (($wAll && $hAll) ? $wAll / $hAll : $imAR);
1250+ $zcAR = (($wAll && $hAll) ? $wAll / $hAll : 1);
1251+//echo '<pre>';
1252+//var_dump($wAll);
1253+//var_dump($hAll);
1254+//var_dump($zcAR);
1255+ //if (($wAll > $borderThickness) && ($wAll > $borderThickness)) {
1256+ // $zcAR = ($wAll - (2 * $borderThickness)) / ($hAll - (2 * $borderThickness));
1257+ //}
1258+//echo ($wAll - (2 * $borderThickness))."\n";
1259+//echo ($hAll - (2 * $borderThickness))."\n";
1260+//var_dump($zcAR);
1261+ $side = phpthumb_functions::nonempty_min($this->source_width, $this->source_height, max($wAll, $hAll));
1262+ $sideX = phpthumb_functions::nonempty_min($this->source_width, $wAll, round($hAll * $zcAR));
1263+ $sideY = phpthumb_functions::nonempty_min( $this->source_height, $hAll, round($wAll / $zcAR));
1264+
1265+ $thumbnailH = round(max($sideY, ($sideY * $zcAR) / $imAR));
1266+ if ($IMuseExplicitImageOutputDimensions) {
1267+ $commandline .= ' -'.$IMresizeParameter.' '.$thumbnailH.'x'.$thumbnailH;
1268+ } else {
1269+ $commandline .= ' -'.$IMresizeParameter.' x'.$thumbnailH;
1270+ }
1271+//echo '<pre>';
1272+//var_dump($this->w);
1273+//var_dump($this->wp);
1274+//var_dump($this->wl);
1275+//var_dump($this->ws);
1276+//var_dump($wAll);
1277+//var_dump($side);
1278+//var_dump($sideX);
1279+//var_dump($sideY);
1280+//var_dump($zcAR);
1281+//var_dump($thumbnailH);
1282+//print_r($getimagesize);
1283+//echo '</pre>';
1284+
1285+ $commandline .= ' -gravity center';
1286+
1287+ if (($wAll > 0) && ($hAll > 0)) {
1288+ $commandline .= ' -crop '.$wAll.'x'.$hAll.'+0+0';
1289+ } else {
1290+ $commandline .= ' -crop '.$side.'x'.$side.'+0+0';
1291+ }
1292+ if ($this->ImageMagickSwitchAvailable('repage')) {
1293+ $commandline .= ' +repage';
1294+ } else {
1295+ $this->DebugMessage('Skipping "+repage" because ImageMagick (v'.$this->ImageMagickVersion().') does not support it', __FILE__, __LINE__);
1296+ }
1297+
1298+ } elseif ($this->sw || $this->sh || $this->sx || $this->sy) {
1299+
1300+ $commandline .= ' -crop '.($this->sw ? $this->sw : $this->source_width).'x'.($this->sh ? $this->sh : $this->source_height).'+'.$this->sx.'+'.$this->sy;
1301+ // this is broken for aoe=1, but unsure how to fix. Send advice to info@silisoftware.com
1302+ if ($this->w || $this->h) {
1303+ if ($this->ImageMagickSwitchAvailable('repage')) {
1304+ $commandline .= ' -repage';
1305+ } else {
1306+ $this->DebugMessage('Skipping "-repage" because ImageMagick (v'.$this->ImageMagickVersion().') does not support it', __FILE__, __LINE__);
1307+ }
1308+ if ($IMuseExplicitImageOutputDimensions) {
1309+ if ($this->w && !$this->h) {
1310+ $this->h = ceil($this->w / ($this->source_width / $this->source_height));
1311+ } elseif ($this->h && !$this->w) {
1312+ $this->w = ceil($this->h * ($this->source_width / $this->source_height));
1313+ }
1314+ }
1315+ $commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
1316+ }
1317+
1318+ } else {
1319+
1320+ if ($this->iar && (intval($this->w) > 0) && (intval($this->h) > 0)) {
1321+ $commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h.'!';
1322+ } else {
1323+//echo '<pre>';
1324+//print_r($getimagesize);
1325+//echo '</pre>';
1326+//echo $this->w.'x'.$this->h.'<br>';
1327+ $this->w = ((($this->aoe || $this->far) && $this->w) ? $this->w : ($this->w ? phpthumb_functions::nonempty_min($this->w, $getimagesize[0]) : ''));
1328+ $this->h = ((($this->aoe || $this->far) && $this->h) ? $this->h : ($this->h ? phpthumb_functions::nonempty_min($this->h, $getimagesize[1]) : ''));
1329+//echo $this->w.'x'.$this->h.'<br>';
1330+ if ($this->w || $this->h) {
1331+ if ($IMuseExplicitImageOutputDimensions) {
1332+ if ($this->w && !$this->h) {
1333+ $this->h = ceil($this->w / ($this->source_width / $this->source_height));
1334+ } elseif ($this->h && !$this->w) {
1335+ $this->w = ceil($this->h * ($this->source_width / $this->source_height));
1336+ }
1337+ }
1338+ $commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
1339+ }
1340+ }
1341+ }
1342+ }
1343+
1344+ } else {
1345+
1346+ $this->DebugMessage('GetImageSize('.$this->sourceFilename.') failed', __FILE__, __LINE__);
1347+ if ($this->w || $this->h) {
1348+ if ($IMuseExplicitImageOutputDimensions) {
1349+ // unknown source aspect ration, just put large number and hope IM figures it out
1350+ $commandline .= ' -'.$IMresizeParameter.' '.($this->w ? $this->w : '9999').'x'.($this->h ? $this->h : '9999');
1351+ } else {
1352+ $commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
1353+ }
1354+ if ($this->iar && (intval($this->w) > 0) && (intval($this->h) > 0)) {
1355+ $commandline .= '!';
1356+ }
1357+ }
1358+
1359+ }
1360+ foreach ($this->fltr as $filterkey => $filtercommand) {
1361+ @list($command, $parameter) = explode('|', $filtercommand, 2);
1362+ switch ($command) {
1363+ case 'brit':
1364+ if ($this->ImageMagickSwitchAvailable('modulate')) {
1365+ $commandline .= ' -modulate '.(100 + $parameter).',100,100';
1366+ unset($this->fltr[$filterkey]);
1367+ }
1368+ break;
1369+
1370+ case 'cont':
1371+ if ($this->ImageMagickSwitchAvailable('contrast')) {
1372+ $contDiv10 = round($parameter / 10);
1373+ if ($contDiv10 > 0) {
1374+ for ($i = 0; $i < $contDiv10; $i++) {
1375+ $commandline .= ' -contrast'; // increase contrast by 10%
1376+ }
1377+ } elseif ($contDiv10 < 0) {
1378+ for ($i = $contDiv10; $i < 0; $i++) {
1379+ $commandline .= ' +contrast'; // decrease contrast by 10%
1380+ }
1381+ } else {
1382+ // do nothing
1383+ }
1384+ unset($this->fltr[$filterkey]);
1385+ }
1386+ break;
1387+
1388+ case 'ds':
1389+ if ($this->ImageMagickSwitchAvailable(array('colorspace', 'modulate'))) {
1390+ if ($parameter == 100) {
1391+ $commandline .= ' -colorspace GRAY -modulate 100,0,100';
1392+ } else {
1393+ $commandline .= ' -modulate 100,'.(100 - $parameter).',100';
1394+ }
1395+ unset($this->fltr[$filterkey]);
1396+ }
1397+ break;
1398+
1399+ case 'sat':
1400+ if ($this->ImageMagickSwitchAvailable(array('colorspace', 'modulate'))) {
1401+ if ($parameter == -100) {
1402+ $commandline .= ' -colorspace GRAY -modulate 100,0,100';
1403+ } else {
1404+ $commandline .= ' -modulate 100,'.(100 + $parameter).',100';
1405+ }
1406+ unset($this->fltr[$filterkey]);
1407+ }
1408+ break;
1409+
1410+ case 'gray':
1411+ if ($this->ImageMagickSwitchAvailable(array('colorspace', 'modulate'))) {
1412+ $commandline .= ' -colorspace GRAY -modulate 100,0,100';
1413+ //$commandline .= ' -colorspace GRAY';
1414+ unset($this->fltr[$filterkey]);
1415+ }
1416+ break;
1417+
1418+ case 'clr':
1419+ if ($this->ImageMagickSwitchAvailable(array('fill', 'colorize'))) {
1420+ @list($amount, $color) = explode('|', $parameter);
1421+ $commandline .= ' -fill #'.$color.' -colorize '.$amount;
1422+ }
1423+ break;
1424+
1425+ case 'sep':
1426+ if ($this->ImageMagickSwitchAvailable('sepia-tone')) {
1427+ @list($amount, $color) = explode('|', $parameter);
1428+ $amount = ($amount ? $amount : 80);
1429+ if (!$color) {
1430+ $commandline .= ' -sepia-tone '.$amount.'%';
1431+ unset($this->fltr[$filterkey]);
1432+ }
1433+ }
1434+ break;
1435+
1436+ case 'gam':
1437+ if ($this->ImageMagickSwitchAvailable('gamma')) {
1438+ $commandline .= ' -gamma '.$parameter;
1439+ unset($this->fltr[$filterkey]);
1440+ }
1441+ break;
1442+
1443+ case 'neg':
1444+ if ($this->ImageMagickSwitchAvailable('negate')) {
1445+ $commandline .= ' -negate';
1446+ unset($this->fltr[$filterkey]);
1447+ }
1448+ break;
1449+
1450+ case 'th':
1451+ if ($this->ImageMagickSwitchAvailable(array('threshold', 'dither', 'monochrome'))) {
1452+ $commandline .= ' -threshold '.round($parameter / 2.55).'% -dither -monochrome';
1453+ unset($this->fltr[$filterkey]);
1454+ }
1455+ break;
1456+
1457+ case 'rcd':
1458+ if ($this->ImageMagickSwitchAvailable(array('colors', 'dither'))) {
1459+ @list($colors, $dither) = explode('|', $parameter);
1460+ $colors = ($colors ? (int) $colors : 256);
1461+ $dither = ((strlen($dither) > 0) ? (bool) $dither : true);
1462+ $commandline .= ' -colors '.max($colors, 8); // ImageMagick will otherwise fail with "cannot quantize to fewer than 8 colors"
1463+ $commandline .= ($dither ? ' -dither' : ' +dither');
1464+ unset($this->fltr[$filterkey]);
1465+ }
1466+ break;
1467+
1468+ case 'flip':
1469+ if ($this->ImageMagickSwitchAvailable(array('flip', 'flop'))) {
1470+ if (strpos(strtolower($parameter), 'x') !== false) {
1471+ $commandline .= ' -flop';
1472+ }
1473+ if (strpos(strtolower($parameter), 'y') !== false) {
1474+ $commandline .= ' -flip';
1475+ }
1476+ unset($this->fltr[$filterkey]);
1477+ }
1478+ break;
1479+
1480+ case 'edge':
1481+ if ($this->ImageMagickSwitchAvailable('edge')) {
1482+ $parameter = ($parameter ? $parameter : 2);
1483+ $commandline .= ' -edge '.($parameter ? $parameter : 1);
1484+ unset($this->fltr[$filterkey]);
1485+ }
1486+ break;
1487+
1488+ case 'emb':
1489+ if ($this->ImageMagickSwitchAvailable(array('emboss', 'negate'))) {
1490+ $parameter = ($parameter ? $parameter : 2);
1491+ $commandline .= ' -emboss '.$parameter;
1492+ if ($parameter < 2) {
1493+ $commandline .= ' -negate'; // ImageMagick negates the image for some reason with '-emboss 1';
1494+ }
1495+ unset($this->fltr[$filterkey]);
1496+ }
1497+ break;
1498+
1499+ case 'lvl':
1500+ if ($this->ImageMagickSwitchAvailable(array('normalize', 'level'))) {
1501+ @list($band, $min, $max) = explode('|', $parameter);
1502+ $band = ($band ? $band : '*');
1503+ $min = ((strlen($min) > 0) ? $min : '-1');
1504+ $max = ((strlen($max) > 0) ? $max : '-1');
1505+ if ($band == '*') {
1506+ if (($min == -1) && ($max == -1)) {
1507+ $commandline .= ' -normalize';
1508+ unset($this->fltr[$filterkey]);
1509+ } elseif (($min == -1) || ($max == -1)) {
1510+ //
1511+ } else {
1512+ $commandline .= ' -level '.$min.'%,'.$max.'%';
1513+ unset($this->fltr[$filterkey]);
1514+ }
1515+ }
1516+ }
1517+ break;
1518+
1519+ case 'blur':
1520+ if ($this->ImageMagickSwitchAvailable('blur')) {
1521+ @list($radius) = explode('|', $parameter);
1522+ $radius = ($radius ? $radius : 1);
1523+ $commandline .= ' -blur '.$radius;
1524+ unset($this->fltr[$filterkey]);
1525+ }
1526+ break;
1527+
1528+ case 'gblr':
1529+ if ($this->ImageMagickSwitchAvailable('gaussian')) {
1530+ @list($radius) = explode('|', $parameter);
1531+ $radius = ($radius ? $radius : 1);
1532+ $commandline .= ' -gaussian '.$radius;
1533+ unset($this->fltr[$filterkey]);
1534+ }
1535+ break;
1536+
1537+ case 'usm':
1538+ if ($this->ImageMagickSwitchAvailable('unsharp')) {
1539+ @list($amount, $radius, $threshold) = explode('|', $parameter);
1540+ $amount = ($amount ? $amount : 80);
1541+ $radius = ($radius ? $radius : 0.5);
1542+ $threshold = (strlen($threshold) ? $threshold : 3);
1543+ $commandline .= ' -unsharp '.number_format(($radius * 2) - 1, 2).'x1+'.number_format($amount / 100, 2).'+'.number_format($threshold / 100, 2);
1544+ unset($this->fltr[$filterkey]);
1545+ }
1546+ break;
1547+
1548+ case 'bord':
1549+ if ($this->ImageMagickSwitchAvailable(array('border', 'bordercolor', 'thumbnail', 'crop'))) {
1550+ if (!$this->zc) {
1551+ @list($width, $rX, $rY, $color) = explode('|', $parameter);
1552+ if ($width && !$rX && !$rY) {
1553+ if (!phpthumb_functions::IsHexColor($color)) {
1554+ $color = ($this->bc ? $this->bc : '000000');
1555+ }
1556+ $commandline .= ' -border '.$width.' -bordercolor "#'.$color.'"';
1557+ if (ereg(' \-crop ([0-9]+)x([0-9]+)\+0\+0 ', $commandline, $matches)) {
1558+ $commandline = str_replace(' -crop '.$matches[1].'x'.$matches[2].'+0+0 ', ' -crop '.($matches[1] - (2 * $width)).'x'.($matches[2] - (2 * $width)).'+0+0 ', $commandline);
1559+ } elseif (ereg(' \-'.$IMresizeParameter.' ([0-9]+)x([0-9]+) ', $commandline, $matches)) {
1560+ $commandline = str_replace(' -'.$IMresizeParameter.' '.$matches[1].'x'.$matches[2].' ', ' -'.$IMresizeParameter.' '.($matches[1] - (2 * $width)).'x'.($matches[2] - (2 * $width)).' ', $commandline);
1561+ }
1562+ unset($this->fltr[$filterkey]);
1563+ }
1564+ }
1565+ }
1566+ break;
1567+
1568+ case 'crop':
1569+ break;
1570+
1571+ case 'sblr':
1572+ break;
1573+
1574+ case 'mean':
1575+ break;
1576+
1577+ case 'smth':
1578+ break;
1579+
1580+ case 'bvl':
1581+ break;
1582+
1583+ case 'wmi':
1584+ break;
1585+
1586+ case 'wmt':
1587+ break;
1588+
1589+ case 'over':
1590+ break;
1591+
1592+ case 'wb':
1593+ break;
1594+
1595+ case 'hist':
1596+ break;
1597+
1598+ case 'fram':
1599+ break;
1600+
1601+ case 'drop':
1602+ break;
1603+
1604+ case 'mask':
1605+ break;
1606+
1607+ case 'elip':
1608+ break;
1609+
1610+ case 'ric':
1611+ break;
1612+
1613+ }
1614+ if (!isset($this->fltr[$filterkey])) {
1615+ $this->DebugMessage('Processed $this->fltr['.$filterkey.'] ('.$filtercommand.') with ImageMagick', __FILE__, __LINE__);
1616+ } else {
1617+ $this->DebugMessage('Skipping $this->fltr['.$filterkey.'] ('.$filtercommand.') with ImageMagick', __FILE__, __LINE__);
1618+ }
1619+ }
1620+ $this->DebugMessage('Remaining $this->fltr after ImageMagick: ('.$this->phpThumbDebugVarDump($this->fltr).')', __FILE__, __LINE__);
1621+
1622+ if (eregi('jpe?g', $outputFormat) && $this->q) {
1623+ if ($this->ImageMagickSwitchAvailable(array('quality', 'interlace'))) {
1624+ $commandline .= ' -quality '.$this->thumbnailQuality;
1625+ if ($this->config_output_interlace) {
1626+ // causes weird things with animated GIF... leave for JPEG only
1627+ $commandline .= ' -interlace line '; // Use Line or Plane to create an interlaced PNG or GIF or progressive JPEG image
1628+ }
1629+ }
1630+ }
1631+ $commandline .= ' "'.str_replace('/', DIRECTORY_SEPARATOR, $this->sourceFilename).(($outputFormat == 'gif') ? '' : '['.intval($this->sfn).']').'"'; // [0] means first frame of (GIF) animation, can be ignored
1632+ $commandline .= ' '.$outputFormat.':"'.$IMtempfilename.'"';
1633+ $commandline .= ' 2>&1';
1634+ $this->DebugMessage('ImageMagick called as ('.$commandline.')', __FILE__, __LINE__);
1635+ $IMresult = phpthumb_functions::SafeExec($commandline);
1636+ clearstatcache();
1637+ if (!@file_exists($IMtempfilename) || !@filesize($IMtempfilename)) {
1638+
1639+ $this->DebugMessage('ImageMagick failed with message ('.$IMresult.')', __FILE__, __LINE__);
1640+ if ($this->iswindows && !$IMresult) {
1641+ $this->DebugMessage('Check to make sure that PHP has read+write permissions to "'.dirname($IMtempfilename).'"', __FILE__, __LINE__);
1642+ }
1643+
1644+ } else {
1645+
1646+ $this->IMresizedData = file_get_contents($IMtempfilename);
1647+ $getimagesize_imresized = @GetImageSize($IMtempfilename);
1648+ if (($this->config_max_source_pixels > 0) && (($getimagesize_imresized[0] * $getimagesize_imresized[1]) > $this->config_max_source_pixels)) {
1649+ $this->DebugMessage('skipping ImageMagickThumbnailToGD::'.$ImageCreateFunction.'() because IM output is too large ('.$getimagesize_imresized[0].'x'.$getimagesize_imresized[0].' = '.($getimagesize_imresized[0] * $getimagesize_imresized[1]).' > '.$this->config_max_source_pixels.')', __FILE__, __LINE__);
1650+ } elseif (function_exists(@$ImageCreateFunction) && ($this->gdimg_source = @$ImageCreateFunction($IMtempfilename))) {
1651+//header('Content-Type: image/png');
1652+//ImageSaveAlpha($this->gdimg_source, true);
1653+//ImagePNG($this->gdimg_source);
1654+//exit;
1655+ $this->source_width = ImageSX($this->gdimg_source);
1656+ $this->source_height = ImageSY($this->gdimg_source);
1657+ $this->DebugMessage('ImageMagickThumbnailToGD::'.$ImageCreateFunction.'() succeeded, $this->gdimg_source is now ('.$this->source_width.'x'.$this->source_height.')', __FILE__, __LINE__);
1658+ $this->DebugMessage('ImageMagickThumbnailToGD() returning $IMresizedData ('.strlen($this->IMresizedData).' bytes)', __FILE__, __LINE__);
1659+ } else {
1660+ $this->useRawIMoutput = true;
1661+ $this->DebugMessage('$this->useRawIMoutput set to TRUE because '.@$ImageCreateFunction.'('.$IMtempfilename.') failed', __FILE__, __LINE__);
1662+ }
1663+ @unlink($IMtempfilename);
1664+ return true;
1665+
1666+ }
1667+ unlink($IMtempfilename);
1668+
1669+ } else {
1670+ $this->DebugMessage('ImageMagickThumbnailToGD() aborting, phpThumb_tempnam() failed', __FILE__, __LINE__);
1671+ }
1672+ } else {
1673+ $this->DebugMessage('ImageMagickThumbnailToGD() aborting because ImageMagickCommandlineBase() failed', __FILE__, __LINE__);
1674+ }
1675+ $this->useRawIMoutput = false;
1676+ return false;
1677+ }
1678+
1679+
1680+ function Rotate() {
1681+ if ($this->ra || $this->ar) {
1682+ if (!function_exists('ImageRotate')) {
1683+ $this->DebugMessage('!function_exists(ImageRotate)', __FILE__, __LINE__);
1684+ return false;
1685+ }
1686+ if (!include_once(dirname(__FILE__).'/phpthumb.filters.php')) {
1687+ $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying filters ('.implode(';', $this->fltr).')', __FILE__, __LINE__);
1688+ return false;
1689+ }
1690+
1691+ $this->config_background_hexcolor = ($this->bg ? $this->bg : $this->config_background_hexcolor);
1692+ if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
1693+ return $this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
1694+ }
1695+
1696+ $rotate_angle = 0;
1697+ if ($this->ra) {
1698+
1699+ $rotate_angle = floatval($this->ra);
1700+
1701+ } else {
1702+
1703+ if ($this->ar == 'x') {
1704+ if (phpthumb_functions::version_compare_replacement(phpversion(), '4.2.0', '>=')) {
1705+ if ($this->sourceFilename) {
1706+ if (function_exists('exif_read_data')) {
1707+ if ($exif_data = @exif_read_data($this->sourceFilename, 'IFD0')) {
1708+ // http://sylvana.net/jpegcrop/exif_orientation.html
1709+ switch (@$exif_data['Orientation']) {
1710+ case 1:
1711+ $rotate_angle = 0;
1712+ break;
1713+ case 3:
1714+ $rotate_angle = 180;
1715+ break;
1716+ case 6:
1717+ $rotate_angle = 270;
1718+ break;
1719+ case 8:
1720+ $rotate_angle = 90;
1721+ break;
1722+
1723+ default:
1724+ $this->DebugMessage('EXIF auto-rotate failed because unknown $exif_data[Orientation] "'.@$exif_data['Orientation'].'"', __FILE__, __LINE__);
1725+ return false;
1726+ break;
1727+ }
1728+ $this->DebugMessage('EXIF auto-rotate set to '.$rotate_angle.' degrees ($exif_data[Orientation] = "'.@$exif_data['Orientation'].'")', __FILE__, __LINE__);
1729+ } else {
1730+ $this->DebugMessage('failed: exif_read_data('.$this->sourceFilename.')', __FILE__, __LINE__);
1731+ return false;
1732+ }
1733+ } else {
1734+ $this->DebugMessage('!function_exists(exif_read_data)', __FILE__, __LINE__);
1735+ return false;
1736+ }
1737+ } else {
1738+ $this->DebugMessage('Cannot auto-rotate from EXIF data because $this->sourceFilename is empty', __FILE__, __LINE__);
1739+ return false;
1740+ }
1741+ } else {
1742+ $this->DebugMessage('Cannot auto-rotate from EXIF data because PHP is less than v4.2.0 ('.phpversion().')', __FILE__, __LINE__);
1743+ return false;
1744+ }
1745+ } elseif (($this->ar == 'l') && ($this->source_height > $this->source_width)) {
1746+ $rotate_angle = 270;
1747+ } elseif (($this->ar == 'L') && ($this->source_height > $this->source_width)) {
1748+ $rotate_angle = 90;
1749+ } elseif (($this->ar == 'p') && ($this->source_width > $this->source_height)) {
1750+ $rotate_angle = 90;
1751+ } elseif (($this->ar == 'P') && ($this->source_width > $this->source_height)) {
1752+ $rotate_angle = 270;
1753+ }
1754+
1755+ }
1756+ if ($rotate_angle % 90) {
1757+ $this->is_alpha = true;
1758+ }
1759+ phpthumb_filters::ImprovedImageRotate($this->gdimg_source, $rotate_angle, $this->config_background_hexcolor, $this->bg);
1760+ $this->source_width = ImageSX($this->gdimg_source);
1761+ $this->source_height = ImageSY($this->gdimg_source);
1762+ }
1763+ return true;
1764+ }
1765+
1766+
1767+ function FixedAspectRatio() {
1768+ // optional fixed-dimension images (regardless of aspect ratio)
1769+
1770+ if (!$this->far) {
1771+ // do nothing
1772+ return true;
1773+ }
1774+
1775+ if (!$this->w || !$this->h) {
1776+ return false;
1777+ }
1778+ $this->thumbnail_width = $this->w;
1779+ $this->thumbnail_height = $this->h;
1780+ $this->is_alpha = true;
1781+ if ($this->thumbnail_image_width >= $this->thumbnail_width) {
1782+
1783+ if ($this->w) {
1784+ $aspectratio = $this->thumbnail_image_height / $this->thumbnail_image_width;
1785+ $this->thumbnail_image_height = round($this->thumbnail_image_width * $aspectratio);
1786+ $this->thumbnail_height = ($this->h ? $this->h : $this->thumbnail_image_height);
1787+ } elseif ($this->thumbnail_image_height < $this->thumbnail_height) {
1788+ $this->thumbnail_image_height = $this->thumbnail_height;
1789+ $this->thumbnail_image_width = round($this->thumbnail_image_height / $aspectratio);
1790+ }
1791+
1792+ } else {
1793+ if ($this->h) {
1794+ $aspectratio = $this->thumbnail_image_width / $this->thumbnail_image_height;
1795+ $this->thumbnail_image_width = round($this->thumbnail_image_height * $aspectratio);
1796+ } elseif ($this->thumbnail_image_width < $this->thumbnail_width) {
1797+ $this->thumbnail_image_width = $this->thumbnail_width;
1798+ $this->thumbnail_image_height = round($this->thumbnail_image_width / $aspectratio);
1799+ }
1800+
1801+ }
1802+ return true;
1803+ }
1804+
1805+
1806+ function AntiOffsiteLinking() {
1807+ // Optional anti-offsite hijacking of the thumbnail script
1808+ $allow = true;
1809+ if ($allow && $this->config_nooffsitelink_enabled && (@$_SERVER['HTTP_REFERER'] || $this->config_nooffsitelink_require_refer)) {
1810+ $this->DebugMessage('AntiOffsiteLinking() checking $_SERVER[HTTP_REFERER] "'.@$_SERVER['HTTP_REFERER'].'"', __FILE__, __LINE__);
1811+ $parsed_url = parse_url(@$_SERVER['HTTP_REFERER']);
1812+ if (!phpthumb_functions::CaseInsensitiveInArray(@$parsed_url['host'], $this->config_nooffsitelink_valid_domains)) {
1813+ $allow = false;
1814+ $erase = $this->config_nooffsitelink_erase_image;
1815+ $message = $this->config_nooffsitelink_text_message;
1816+ $this->DebugMessage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is NOT in $this->config_nooffsitelink_valid_domains ('.implode(';', $this->config_nooffsitelink_valid_domains).')', __FILE__, __LINE__);
1817+ } else {
1818+ $this->DebugMessage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is in $this->config_nooffsitelink_valid_domains ('.implode(';', $this->config_nooffsitelink_valid_domains).')', __FILE__, __LINE__);
1819+ }
1820+ }
1821+
1822+ if ($allow && $this->config_nohotlink_enabled && eregi('^(f|ht)tps?\://', $this->src)) {
1823+ $parsed_url = parse_url($this->src);
1824+ if (!phpthumb_functions::CaseInsensitiveInArray(@$parsed_url['host'], $this->config_nohotlink_valid_domains)) {
1825+ // This domain is not allowed
1826+ $allow = false;
1827+ $erase = $this->config_nohotlink_erase_image;
1828+ $message = $this->config_nohotlink_text_message;
1829+ $this->DebugMessage('AntiOffsiteLinking() - "'.$parsed_url['host'].'" is NOT in $this->config_nohotlink_valid_domains ('.implode(';', $this->config_nohotlink_valid_domains).')', __FILE__, __LINE__);
1830+ } else {
1831+ $this->DebugMessage('AntiOffsiteLinking() - "'.$parsed_url['host'].'" is in $this->config_nohotlink_valid_domains ('.implode(';', $this->config_nohotlink_valid_domains).')', __FILE__, __LINE__);
1832+ }
1833+ }
1834+
1835+ if ($allow) {
1836+ $this->DebugMessage('AntiOffsiteLinking() says this is allowed', __FILE__, __LINE__);
1837+ return true;
1838+ }
1839+
1840+ if (!phpthumb_functions::IsHexColor($this->config_error_bgcolor)) {
1841+ return $this->ErrorImage('Invalid hex color string "'.$this->config_error_bgcolor.'" for $this->config_error_bgcolor');
1842+ }
1843+ if (!phpthumb_functions::IsHexColor($this->config_error_textcolor)) {
1844+ return $this->ErrorImage('Invalid hex color string "'.$this->config_error_textcolor.'" for $this->config_error_textcolor');
1845+ }
1846+ if ($erase) {
1847+
1848+ return $this->ErrorImage($message, $this->thumbnail_width, $this->thumbnail_height, $this->config_error_bgcolor, $this->config_error_textcolor, $this->config_error_fontsize);
1849+
1850+ } else {
1851+
1852+ $nohotlink_text_array = explode("\n", wordwrap($message, floor($this->thumbnail_width / ImageFontWidth($this->config_error_fontsize)), "\n"));
1853+ $nohotlink_text_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_output, $this->config_error_textcolor);
1854+
1855+ $topoffset = round(($this->thumbnail_height - (count($nohotlink_text_array) * ImageFontHeight($this->config_error_fontsize))) / 2);
1856+
1857+ $rowcounter = 0;
1858+ $this->DebugMessage('AntiOffsiteLinking() writing '.count($nohotlink_text_array).' lines of text "'.$message.'" (in #'.$this->config_error_textcolor.') on top of image', __FILE__, __LINE__);
1859+ foreach ($nohotlink_text_array as $dummy => $textline) {
1860+ $leftoffset = max(0, round(($this->thumbnail_width - (strlen($textline) * ImageFontWidth($this->config_error_fontsize))) / 2));
1861+ ImageString($this->gdimg_output, $this->config_error_fontsize, $leftoffset, $topoffset + ($rowcounter++ * ImageFontHeight($this->config_error_fontsize)), $textline, $nohotlink_text_color);
1862+ }
1863+
1864+ }
1865+ return true;
1866+ }
1867+
1868+
1869+ function AlphaChannelFlatten() {
1870+ if (!$this->is_alpha) {
1871+ // image doesn't have alpha transparency, no need to flatten
1872+ $this->DebugMessage('skipping AlphaChannelFlatten() because !$this->is_alpha', __FILE__, __LINE__);
1873+ return false;
1874+ }
1875+ switch ($this->thumbnailFormat) {
1876+ case 'png':
1877+ case 'ico':
1878+ // image has alpha transparency, but output as PNG or ICO which can handle it
1879+ $this->DebugMessage('skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.'")', __FILE__, __LINE__);
1880+ return false;
1881+ break;
1882+
1883+ case 'gif':
1884+ // image has alpha transparency, but output as GIF which can handle only single-color transparency
1885+ $CurrentImageColorTransparent = ImageColorTransparent($this->gdimg_output);
1886+ if ($CurrentImageColorTransparent == -1) {
1887+ // no transparent color defined
1888+
1889+ if (phpthumb_functions::gd_version() < 2.0) {
1890+ $this->DebugMessage('AlphaChannelFlatten() failed because GD version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
1891+ return false;
1892+ }
1893+
1894+ if ($img_alpha_mixdown_dither = @ImageCreateTrueColor(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output))) {
1895+
1896+ for ($i = 0; $i <= 255; $i++) {
1897+ $dither_color[$i] = ImageColorAllocate($img_alpha_mixdown_dither, $i, $i, $i);
1898+ }
1899+
1900+ // scan through current truecolor image copy alpha channel to temp image as grayscale
1901+ for ($x = 0; $x < $this->thumbnail_width; $x++) {
1902+ for ($y = 0; $y < $this->thumbnail_height; $y++) {
1903+ $PixelColor = phpthumb_functions::GetPixelColor($this->gdimg_output, $x, $y);
1904+ ImageSetPixel($img_alpha_mixdown_dither, $x, $y, $dither_color[($PixelColor['alpha'] * 2)]);
1905+ }
1906+ }
1907+
1908+ // dither alpha channel grayscale version down to 2 colors
1909+ ImageTrueColorToPalette($img_alpha_mixdown_dither, true, 2);
1910+
1911+ // reduce color palette to 256-1 colors (leave one palette position for transparent color)
1912+ ImageTrueColorToPalette($this->gdimg_output, true, 255);
1913+
1914+ // allocate a new color for transparent color index
1915+ $TransparentColor = ImageColorAllocate($this->gdimg_output, 1, 254, 253);
1916+ ImageColorTransparent($this->gdimg_output, $TransparentColor);
1917+
1918+ // scan through alpha channel image and note pixels with >50% transparency
1919+ $TransparentPixels = array();
1920+ for ($x = 0; $x < $this->thumbnail_width; $x++) {
1921+ for ($y = 0; $y < $this->thumbnail_height; $y++) {
1922+ $AlphaChannelPixel = phpthumb_functions::GetPixelColor($img_alpha_mixdown_dither, $x, $y);
1923+ if ($AlphaChannelPixel['red'] > 127) {
1924+ ImageSetPixel($this->gdimg_output, $x, $y, $TransparentColor);
1925+ }
1926+ }
1927+ }
1928+ ImageDestroy($img_alpha_mixdown_dither);
1929+
1930+ $this->DebugMessage('AlphaChannelFlatten() set image to 255+1 colors with transparency for GIF output', __FILE__, __LINE__);
1931+ return true;
1932+
1933+ } else {
1934+ $this->DebugMessage('AlphaChannelFlatten() failed ImageCreate('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).')', __FILE__, __LINE__);
1935+ return false;
1936+ }
1937+
1938+ } else {
1939+ // a single transparent color already defined, leave as-is
1940+ $this->DebugMessage('skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.'") and ImageColorTransparent returned "'.$CurrentImageColorTransparent.'"', __FILE__, __LINE__);
1941+ return true;
1942+ }
1943+ break;
1944+ }
1945+ $this->DebugMessage('continuing AlphaChannelFlatten() for output format "'.$this->thumbnailFormat.'"', __FILE__, __LINE__);
1946+
1947+ // image has alpha transparency, and is being output in a format that doesn't support it -- flatten
1948+ if ($gdimg_flatten_temp = phpthumb_functions::ImageCreateFunction($this->thumbnail_width, $this->thumbnail_height)) {
1949+
1950+ $this->config_background_hexcolor = ($this->bg ? $this->bg : $this->config_background_hexcolor);
1951+ if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
1952+ return $this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
1953+ }
1954+ $background_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_output, $this->config_background_hexcolor);
1955+ ImageFilledRectangle($gdimg_flatten_temp, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $background_color);
1956+ ImageCopy($gdimg_flatten_temp, $this->gdimg_output, 0, 0, 0, 0, $this->thumbnail_width, $this->thumbnail_height);
1957+
1958+ ImageAlphaBlending($this->gdimg_output, true);
1959+ ImageSaveAlpha($this->gdimg_output, false);
1960+ ImageColorTransparent($this->gdimg_output, -1);
1961+ ImageCopy($this->gdimg_output, $gdimg_flatten_temp, 0, 0, 0, 0, $this->thumbnail_width, $this->thumbnail_height);
1962+
1963+ ImageDestroy($gdimg_flatten_temp);
1964+ return true;
1965+
1966+ } else {
1967+ $this->DebugMessage('ImageCreateFunction() failed', __FILE__, __LINE__);
1968+ }
1969+ return false;
1970+ }
1971+
1972+
1973+ function ApplyFilters() {
1974+ if ($this->fltr && is_array($this->fltr)) {
1975+ if (!include_once(dirname(__FILE__).'/phpthumb.filters.php')) {
1976+ $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying filters ('.implode(';', $this->fltr).')', __FILE__, __LINE__);
1977+ return false;
1978+ }
1979+ $phpthumbFilters = new phpthumb_filters();
1980+ $phpthumbFilters->phpThumbObject = $this;
1981+ foreach ($this->fltr as $dummy => $filtercommand) {
1982+ @list($command, $parameter) = explode('|', $filtercommand, 2);
1983+ $this->DebugMessage('Attempting to process filter command "'.$command.'('.$parameter.')"', __FILE__, __LINE__);
1984+ switch ($command) {
1985+ case 'brit': // Brightness
1986+ $phpthumbFilters->Brightness($this->gdimg_output, $parameter);
1987+ break;
1988+
1989+ case 'cont': // Contrast
1990+ $phpthumbFilters->Contrast($this->gdimg_output, $parameter);
1991+ break;
1992+
1993+ case 'ds': // Desaturation
1994+ $phpthumbFilters->Desaturate($this->gdimg_output, $parameter, '');
1995+ break;
1996+
1997+ case 'sat': // Saturation
1998+ $phpthumbFilters->Saturation($this->gdimg_output, $parameter, '');
1999+ break;
2000+
2001+ case 'gray': // Grayscale
2002+ $phpthumbFilters->Grayscale($this->gdimg_output);
2003+ break;
2004+
2005+ case 'clr': // Colorize
2006+ if (phpthumb_functions::gd_version() < 2) {
2007+ $this->DebugMessage('Skipping Colorize() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2008+ break;
2009+ }
2010+ @list($amount, $color) = explode('|', $parameter);
2011+ $phpthumbFilters->Colorize($this->gdimg_output, $amount, $color);
2012+ break;
2013+
2014+ case 'sep': // Sepia
2015+ if (phpthumb_functions::gd_version() < 2) {
2016+ $this->DebugMessage('Skipping Sepia() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2017+ break;
2018+ }
2019+ @list($amount, $color) = explode('|', $parameter);
2020+ $phpthumbFilters->Sepia($this->gdimg_output, $amount, $color);
2021+ break;
2022+
2023+ case 'gam': // Gamma correction
2024+ $phpthumbFilters->Gamma($this->gdimg_output, $parameter);
2025+ break;
2026+
2027+ case 'neg': // Negative colors
2028+ $phpthumbFilters->Negative($this->gdimg_output);
2029+ break;
2030+
2031+ case 'th': // Threshold
2032+ $phpthumbFilters->Threshold($this->gdimg_output, $parameter);
2033+ break;
2034+
2035+ case 'rcd': // ReduceColorDepth
2036+ if (phpthumb_functions::gd_version() < 2) {
2037+ $this->DebugMessage('Skipping ReduceColorDepth() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2038+ break;
2039+ }
2040+ @list($colors, $dither) = explode('|', $parameter);
2041+ $colors = ($colors ? (int) $colors : 256);
2042+ $dither = ((strlen($dither) > 0) ? (bool) $dither : true);
2043+ $phpthumbFilters->ReduceColorDepth($this->gdimg_output, $colors, $dither);
2044+ break;
2045+
2046+ case 'flip': // Flip
2047+ $phpthumbFilters->Flip($this->gdimg_output, (strpos(strtolower($parameter), 'x') !== false), (strpos(strtolower($parameter), 'y') !== false));
2048+ break;
2049+
2050+ case 'edge': // EdgeDetect
2051+ $phpthumbFilters->EdgeDetect($this->gdimg_output);
2052+ break;
2053+
2054+ case 'emb': // Emboss
2055+ $phpthumbFilters->Emboss($this->gdimg_output);
2056+ break;
2057+
2058+ case 'bvl': // Bevel
2059+ @list($width, $color1, $color2) = explode('|', $parameter);
2060+ $phpthumbFilters->Bevel($this->gdimg_output, $width, $color1, $color2);
2061+ break;
2062+
2063+ case 'lvl': // autoLevels
2064+ @list($band, $min, $max) = explode('|', $parameter);
2065+ $band = ($band ? $band : '*');
2066+ $min = ((strlen($min) > 0) ? $min : '-1');
2067+ $max = ((strlen($max) > 0) ? $max : '-1');
2068+ $phpthumbFilters->HistogramStretch($this->gdimg_output, $band, $min, $max);
2069+ break;
2070+
2071+ case 'wb': // WhiteBalance
2072+ $phpthumbFilters->WhiteBalance($this->gdimg_output, $parameter);
2073+ break;
2074+
2075+ case 'hist': // Histogram overlay
2076+ if (phpthumb_functions::gd_version() < 2) {
2077+ $this->DebugMessage('Skipping HistogramOverlay() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2078+ break;
2079+ }
2080+ @list($bands, $colors, $width, $height, $alignment, $opacity, $margin_x, $margin_y) = explode('|', $parameter);
2081+ $bands = ($bands ? $bands : '*');
2082+ $colors = ($colors ? $colors : '');
2083+ $width = ($width ? $width : 0.25);
2084+ $height = ($height ? $height : 0.25);
2085+ $alignment = ($alignment ? $alignment : 'BR');
2086+ $opacity = ($opacity ? $opacity : 50);
2087+ $margin_x = ($margin_x ? $margin_x : 5);
2088+ $margin_y = $margin_y; // just to note it wasn't forgotten, but let the value always pass unchanged
2089+ $phpthumbFilters->HistogramOverlay($this->gdimg_output, $bands, $colors, $width, $height, $alignment, $opacity, $margin);
2090+ break;
2091+
2092+ case 'fram': // Frame
2093+ @list($frame_width, $edge_width, $color_frame, $color1, $color2) = explode('|', $parameter);
2094+ $phpthumbFilters->Frame($this->gdimg_output, $frame_width, $edge_width, $color_frame, $color1, $color2);
2095+ break;
2096+
2097+ case 'drop': // DropShadow
2098+ if (phpthumb_functions::gd_version() < 2) {
2099+ $this->DebugMessage('Skipping DropShadow() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2100+ return false;
2101+ }
2102+ $this->is_alpha = true;
2103+ @list($distance, $width, $color, $angle, $fade) = explode('|', $parameter);
2104+ $phpthumbFilters->DropShadow($this->gdimg_output, $distance, $width, $color, $angle, $fade);
2105+ break;
2106+
2107+ case 'mask': // Mask cropping
2108+ if (phpthumb_functions::gd_version() < 2) {
2109+ $this->DebugMessage('Skipping Mask() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2110+ return false;
2111+ }
2112+ $mask_filename = $this->ResolveFilenameToAbsolute($parameter);
2113+ if (@is_readable($mask_filename) && ($fp_mask = @fopen($mask_filename, 'rb'))) {
2114+ $MaskImageData = '';
2115+ do {
2116+ $buffer = fread($fp_mask, 8192);
2117+ $MaskImageData .= $buffer;
2118+ } while (strlen($buffer) > 0);
2119+ fclose($fp_mask);
2120+ if ($gdimg_mask = $this->ImageCreateFromStringReplacement($MaskImageData)) {
2121+ $this->is_alpha = true;
2122+ $phpthumbFilters->ApplyMask($gdimg_mask, $this->gdimg_output);
2123+ ImageDestroy($gdimg_mask);
2124+ } else {
2125+ $this->DebugMessage('ImageCreateFromStringReplacement() failed for "'.$mask_filename.'"', __FILE__, __LINE__);
2126+ }
2127+ } else {
2128+ $this->DebugMessage('Cannot open mask file "'.$mask_filename.'"', __FILE__, __LINE__);
2129+ }
2130+ break;
2131+
2132+ case 'elip': // Elipse cropping
2133+ if (phpthumb_functions::gd_version() < 2) {
2134+ $this->DebugMessage('Skipping Elipse() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2135+ return false;
2136+ }
2137+ $this->is_alpha = true;
2138+ $phpthumbFilters->Elipse($this->gdimg_output);
2139+ break;
2140+
2141+ case 'ric': // RoundedImageCorners
2142+ if (phpthumb_functions::gd_version() < 2) {
2143+ $this->DebugMessage('Skipping RoundedImageCorners() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2144+ return false;
2145+ }
2146+ @list($radius_x, $radius_y) = explode('|', $parameter);
2147+ if (($radius_x < 1) || ($radius_y < 1)) {
2148+ $this->DebugMessage('Skipping RoundedImageCorners('.$radius_x.', '.$radius_y.') because x/y radius is less than 1', __FILE__, __LINE__);
2149+ break;
2150+ }
2151+ $this->is_alpha = true;
2152+ $phpthumbFilters->RoundedImageCorners($this->gdimg_output, $radius_x, $radius_y);
2153+ break;
2154+
2155+ case 'crop': // Crop
2156+ @list($left, $right, $top, $bottom) = explode('|', $parameter);
2157+ $phpthumbFilters->Crop($this->gdimg_output, $left, $right, $top, $bottom);
2158+ break;
2159+
2160+ case 'bord': // Border
2161+ @list($border_width, $radius_x, $radius_y, $hexcolor_border) = explode('|', $parameter);
2162+ $this->is_alpha = true;
2163+ $phpthumbFilters->ImageBorder($this->gdimg_output, $border_width, $radius_x, $radius_y, $hexcolor_border);
2164+ break;
2165+
2166+ case 'over': // Overlay
2167+ @list($filename, $underlay, $margin, $opacity) = explode('|', $parameter);
2168+ $underlay = (bool) ($underlay ? $underlay : false);
2169+ $margin = ((strlen($margin) > 0) ? $margin : ($underlay ? 0.1 : 0.0));
2170+ $opacity = ((strlen($opacity) > 0) ? $opacity : 100);
2171+ if (($margin > 0) && ($margin < 1)) {
2172+ $margin = min(0.499, $margin);
2173+ } elseif (($margin > -1) && ($margin < 0)) {
2174+ $margin = max(-0.499, $margin);
2175+ }
2176+
2177+ $filename = $this->ResolveFilenameToAbsolute($filename);
2178+ if (@is_readable($filename) && ($fp_watermark = @fopen($filename, 'rb'))) {
2179+ $WatermarkImageData = '';
2180+ do {
2181+ $buffer = fread($fp_watermark, 8192);
2182+ $WatermarkImageData .= $buffer;
2183+ } while (strlen($buffer) > 0);
2184+ fclose($fp_watermark);
2185+ if ($img_watermark = $this->ImageCreateFromStringReplacement($WatermarkImageData)) {
2186+ if ($margin < 1) {
2187+ $resized_x = max(1, ImageSX($this->gdimg_output) - round(2 * (ImageSX($this->gdimg_output) * $margin)));
2188+ $resized_y = max(1, ImageSY($this->gdimg_output) - round(2 * (ImageSY($this->gdimg_output) * $margin)));
2189+ } else {
2190+ $resized_x = max(1, ImageSX($this->gdimg_output) - round(2 * $margin));
2191+ $resized_y = max(1, ImageSY($this->gdimg_output) - round(2 * $margin));
2192+ }
2193+
2194+ if ($underlay) {
2195+
2196+ if ($img_watermark_resized = phpthumb_functions::ImageCreateFunction(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output))) {
2197+ ImageAlphaBlending($img_watermark_resized, false);
2198+ ImageSaveAlpha($img_watermark_resized, true);
2199+ $this->ImageResizeFunction($img_watermark_resized, $img_watermark, 0, 0, 0, 0, ImageSX($img_watermark_resized), ImageSY($img_watermark_resized), ImageSX($img_watermark), ImageSY($img_watermark));
2200+ if ($img_source_resized = phpthumb_functions::ImageCreateFunction($resized_x, $resized_y)) {
2201+ ImageAlphaBlending($img_source_resized, false);
2202+ ImageSaveAlpha($img_source_resized, true);
2203+ $this->ImageResizeFunction($img_source_resized, $this->gdimg_output, 0, 0, 0, 0, ImageSX($img_source_resized), ImageSY($img_source_resized), ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2204+ $phpthumbFilters->WatermarkOverlay($img_watermark_resized, $img_source_resized, 'C', $opacity, $margin);
2205+ ImageCopy($this->gdimg_output, $img_watermark_resized, 0, 0, 0, 0, ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2206+ } else {
2207+ $this->DebugMessage('phpthumb_functions::ImageCreateFunction('.$resized_x.', '.$resized_y.')', __FILE__, __LINE__);
2208+ }
2209+ ImageDestroy($img_watermark_resized);
2210+ } else {
2211+ $this->DebugMessage('phpthumb_functions::ImageCreateFunction('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).')', __FILE__, __LINE__);
2212+ }
2213+
2214+ } else { // overlay
2215+
2216+ if ($img_watermark_resized = phpthumb_functions::ImageCreateFunction($resized_x, $resized_y)) {
2217+ ImageAlphaBlending($img_watermark_resized, false);
2218+ ImageSaveAlpha($img_watermark_resized, true);
2219+ $this->ImageResizeFunction($img_watermark_resized, $img_watermark, 0, 0, 0, 0, ImageSX($img_watermark_resized), ImageSY($img_watermark_resized), ImageSX($img_watermark), ImageSY($img_watermark));
2220+ $phpthumbFilters->WatermarkOverlay($this->gdimg_output, $img_watermark_resized, 'C', $opacity, $margin);
2221+ ImageDestroy($img_watermark_resized);
2222+ } else {
2223+ $this->DebugMessage('phpthumb_functions::ImageCreateFunction('.$resized_x.', '.$resized_y.')', __FILE__, __LINE__);
2224+ }
2225+
2226+ }
2227+ ImageDestroy($img_watermark);
2228+
2229+ } else {
2230+ $this->DebugMessage('ImageCreateFromStringReplacement() failed for "'.$filename.'"', __FILE__, __LINE__);
2231+ }
2232+ } else {
2233+ $this->DebugMessage('Cannot open overlay file "'.$filename.'"', __FILE__, __LINE__);
2234+ }
2235+ break;
2236+
2237+ case 'wmi': // WaterMarkImage
2238+ @list($filename, $alignment, $opacity, $margin['x'], $margin['y']) = explode('|', $parameter);
2239+ $alignment = ($alignment ? $alignment : 'BR');
2240+ $opacity = (strlen($opacity) ? $opacity : 50);
2241+ $margins = array('x', 'y');
2242+ foreach ($margins as $dummy => $xy) {
2243+ $margin[$xy] = (strlen($margin[$xy]) ? $margin[$xy] : 5);
2244+ if (($margin[$xy] > 0) && ($margin[$xy] < 1)) {
2245+ $margin[$xy] = min(0.499, $margin[$xy]);
2246+ } elseif (($margin[$xy] > -1) && ($margin[$xy] < 0)) {
2247+ $margin[$xy] = max(-0.499, $margin[$xy]);
2248+ }
2249+ }
2250+
2251+ $filename = $this->ResolveFilenameToAbsolute($filename);
2252+ if (@is_readable($filename)) {
2253+ if ($img_watermark = $this->ImageCreateFromFilename($filename)) {
2254+ // great
2255+ $phpthumbFilters->WatermarkOverlay($this->gdimg_output, $img_watermark, $alignment, $opacity, $margin);
2256+ ImageDestroy($img_watermark);
2257+ } else {
2258+ $this->DebugMessage('ImageCreateFromFilename() failed for "'.$filename.'"', __FILE__, __LINE__);
2259+ }
2260+ } else {
2261+ $this->DebugMessage('!is_readable('.$filename.')', __FILE__, __LINE__);
2262+ }
2263+ break;
2264+
2265+ case 'wmt': // WaterMarkText
2266+ @list($text, $size, $alignment, $hex_color, $ttffont, $opacity, $margin, $angle, $bg_color, $bg_opacity, $fillextend) = explode('|', $parameter);
2267+ $text = ($text ? $text : '');
2268+ $size = ($size ? $size : 3);
2269+ $alignment = ($alignment ? $alignment : 'BR');
2270+ $hex_color = ($hex_color ? $hex_color : '000000');
2271+ $ttffont = ($ttffont ? $ttffont : '');
2272+ $opacity = (strlen($opacity) ? $opacity : 50);
2273+ $margin = (strlen($margin) ? $margin : 5);
2274+ $angle = (strlen($angle) ? $angle : 0);
2275+ $bg_color = ($bg_color ? $bg_color : false);
2276+ $bg_opacity = ($bg_opacity ? $bg_opacity : 0);
2277+ $fillextend = ($fillextend ? $fillextend : '');
2278+
2279+ if (basename($ttffont) == $ttffont) {
2280+ $ttffont = realpath($this->config_ttf_directory.DIRECTORY_SEPARATOR.$ttffont);
2281+ } else {
2282+ $ttffont = $this->ResolveFilenameToAbsolute($ttffont);
2283+ }
2284+ $phpthumbFilters->WatermarkText($this->gdimg_output, $text, $size, $alignment, $hex_color, $ttffont, $opacity, $margin, $angle, $bg_color, $bg_opacity, $fillextend);
2285+ break;
2286+
2287+ case 'blur': // Blur
2288+ @list($radius) = explode('|', $parameter);
2289+ $radius = ($radius ? $radius : 1);
2290+ if (phpthumb_functions::gd_version() < 2) {
2291+ $this->DebugMessage('Skipping Blur() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2292+ return false;
2293+ }
2294+ $phpthumbFilters->Blur($this->gdimg_output, $radius);
2295+ break;
2296+
2297+ case 'gblr': // Gaussian Blur
2298+ $phpthumbFilters->BlurGaussian($this->gdimg_output);
2299+ break;
2300+
2301+ case 'sblr': // Selective Blur
2302+ $phpthumbFilters->BlurSelective($this->gdimg_output);
2303+ break;
2304+
2305+ case 'mean': // MeanRemoval blur
2306+ $phpthumbFilters->MeanRemoval($this->gdimg_output);
2307+ break;
2308+
2309+ case 'smth': // Smooth blur
2310+ $phpthumbFilters->Smooth($this->gdimg_output, $parameter);
2311+ break;
2312+
2313+ case 'usm': // UnSharpMask sharpening
2314+ @list($amount, $radius, $threshold) = explode('|', $parameter);
2315+ $amount = ($amount ? $amount : 80);
2316+ $radius = ($radius ? $radius : 0.5);
2317+ $threshold = (strlen($threshold) ? $threshold : 3);
2318+ if (phpthumb_functions::gd_version() >= 2.0) {
2319+ ob_start();
2320+ if (!@include_once(dirname(__FILE__).'/phpthumb.unsharp.php')) {
2321+ $include_error = ob_get_contents();
2322+ if ($include_error) {
2323+ $this->DebugMessage('include_once("'.dirname(__FILE__).'/phpthumb.unsharp.php") generated message: "'.$include_error.'"', __FILE__, __LINE__);
2324+ }
2325+ $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.unsharp.php" which is required for unsharp masking', __FILE__, __LINE__);
2326+ ob_end_clean();
2327+ return false;
2328+ }
2329+ ob_end_clean();
2330+ phpUnsharpMask::applyUnsharpMask($this->gdimg_output, $amount, $radius, $threshold);
2331+ } else {
2332+ $this->DebugMessage('Skipping unsharp mask because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2333+ return false;
2334+ }
2335+ break;
2336+
2337+ case 'rot': // ROTate
2338+ @list($angle, $bgcolor) = explode('|', $parameter);
2339+ $phpthumbFilters->ImprovedImageRotate($this->gdimg_output, $angle, $bgcolor);
2340+ break;
2341+ }
2342+ }
2343+ }
2344+ return true;
2345+ }
2346+
2347+
2348+ function MaxFileSize() {
2349+ if (phpthumb_functions::gd_version() < 2) {
2350+ $this->DebugMessage('Skipping MaxFileSize() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
2351+ return false;
2352+ }
2353+ if ($this->maxb > 0) {
2354+ switch ($this->thumbnailFormat) {
2355+ case 'png':
2356+ case 'gif':
2357+ $imgRenderFunction = 'image'.$this->thumbnailFormat;
2358+
2359+ ob_start();
2360+ $imgRenderFunction($this->gdimg_output);
2361+ $imgdata = ob_get_contents();
2362+ ob_end_clean();
2363+
2364+ if (strlen($imgdata) > $this->maxb) {
2365+ for ($i = 8; $i >= 1; $i--) {
2366+ $tempIMG = ImageCreateTrueColor(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2367+ ImageCopy($tempIMG, $this->gdimg_output, 0, 0, 0, 0, ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2368+ ImageTrueColorToPalette($tempIMG, true, pow(2, $i));
2369+ ob_start();
2370+ $imgRenderFunction($tempIMG);
2371+ $imgdata = ob_get_contents();
2372+ ob_end_clean();
2373+
2374+ if (strlen($imgdata) <= $this->maxb) {
2375+ ImageTrueColorToPalette($this->gdimg_output, true, pow(2, $i));
2376+ break;
2377+ }
2378+ }
2379+ }
2380+ if (strlen($imgdata) > $this->maxb) {
2381+ ImageTrueColorToPalette($this->gdimg_output, true, pow(2, $i));
2382+ return false;
2383+ }
2384+ break;
2385+
2386+ case 'jpeg':
2387+ ob_start();
2388+ ImageJPEG($this->gdimg_output);
2389+ $imgdata = ob_get_contents();
2390+ ob_end_clean();
2391+
2392+ $OriginalJPEGquality = $this->thumbnailQuality;
2393+ if (strlen($imgdata) > $this->maxb) {
2394+ for ($i = 3; $i < 20; $i++) {
2395+ $q = round(100 * (1 - log10($i / 2)));
2396+ ob_start();
2397+ ImageJPEG($this->gdimg_output, '', $q);
2398+ $imgdata = ob_get_contents();
2399+ ob_end_clean();
2400+
2401+ $this->thumbnailQuality = $q;
2402+ if (strlen($imgdata) <= $this->maxb) {
2403+ break;
2404+ }
2405+ }
2406+ }
2407+ if (strlen($imgdata) > $this->maxb) {
2408+ return false;
2409+ }
2410+ break;
2411+
2412+ default:
2413+ return false;
2414+ break;
2415+ }
2416+ }
2417+ return true;
2418+ }
2419+
2420+
2421+ function CalculateThumbnailDimensions() {
2422+//echo $this->source_width.'x'.$this->source_height.'<hr>';
2423+ $this->thumbnailCropX = ($this->sx ? (($this->sx >= 1) ? $this->sx : round($this->sx * $this->source_width)) : 0);
2424+//echo $this->thumbnailCropX.'<br>';
2425+ $this->thumbnailCropY = ($this->sy ? (($this->sy >= 1) ? $this->sy : round($this->sy * $this->source_height)) : 0);
2426+//echo $this->thumbnailCropY.'<br>';
2427+ $this->thumbnailCropW = ($this->sw ? (($this->sw >= 1) ? $this->sw : round($this->sw * $this->source_width)) : $this->source_width);
2428+//echo $this->thumbnailCropW.'<br>';
2429+ $this->thumbnailCropH = ($this->sh ? (($this->sh >= 1) ? $this->sh : round($this->sh * $this->source_height)) : $this->source_height);
2430+//echo $this->thumbnailCropH.'<hr>';
2431+
2432+ // limit source area to original image area
2433+ $this->thumbnailCropW = max(1, min($this->thumbnailCropW, $this->source_width - $this->thumbnailCropX));
2434+ $this->thumbnailCropH = max(1, min($this->thumbnailCropH, $this->source_height - $this->thumbnailCropY));
2435+
2436+ $this->DebugMessage('CalculateThumbnailDimensions() [x,y,w,h] initially set to ['.$this->thumbnailCropX.','.$this->thumbnailCropY.','.$this->thumbnailCropW.','.$this->thumbnailCropH.']', __FILE__, __LINE__);
2437+
2438+
2439+ if ($this->zc && $this->w && $this->h) {
2440+ // Zoom Crop
2441+ // retain proportional resizing we did above, but crop off larger dimension so smaller
2442+ // dimension fully fits available space
2443+
2444+ $scaling_X = $this->source_width / $this->w;
2445+ $scaling_Y = $this->source_height / $this->h;
2446+ if ($scaling_X > $scaling_Y) {
2447+ // some of the width will need to be cropped
2448+ $allowable_width = $this->source_width / $scaling_X * $scaling_Y;
2449+ $this->thumbnailCropW = round($allowable_width);
2450+ $this->thumbnailCropX = round(($this->source_width - $allowable_width) / 2);
2451+
2452+ // added by cles
2453+ if( $this->sx !== null ) $this->thumbnailCropX = $this->sx;
2454+ } elseif ($scaling_Y > $scaling_X) {
2455+ // some of the height will need to be cropped
2456+ $allowable_height = $this->source_height / $scaling_Y * $scaling_X;
2457+ $this->thumbnailCropH = round($allowable_height);
2458+ $this->thumbnailCropY = round(($this->source_height - $allowable_height) / 2);
2459+
2460+ // added by cles
2461+ if( $this->sy !== null ) $this->thumbnailCropY = $this->sy;
2462+ } else {
2463+ // image fits perfectly, no cropping needed
2464+ }
2465+ $this->thumbnail_width = $this->w;
2466+ $this->thumbnail_height = $this->h;
2467+ $this->thumbnail_image_width = $this->thumbnail_width;
2468+ $this->thumbnail_image_height = $this->thumbnail_height;
2469+
2470+ } elseif ($this->iar && $this->w && $this->h) {
2471+
2472+ // Ignore Aspect Ratio
2473+ // stretch image to fit exactly 'w' x 'h'
2474+ $this->thumbnail_width = $this->w;
2475+ $this->thumbnail_height = $this->h;
2476+ $this->thumbnail_image_width = $this->thumbnail_width;
2477+ $this->thumbnail_image_height = $this->thumbnail_height;
2478+
2479+ } else {
2480+
2481+ $original_aspect_ratio = $this->thumbnailCropW / $this->thumbnailCropH;
2482+ if ($this->aoe) {
2483+ if ($this->w && $this->h) {
2484+ $maxwidth = min($this->w, $this->h * $original_aspect_ratio);
2485+ $maxheight = min($this->h, $this->w / $original_aspect_ratio);
2486+ } elseif ($this->w) {
2487+ $maxwidth = $this->w;
2488+ $maxheight = $this->w / $original_aspect_ratio;
2489+ } elseif ($this->h) {
2490+ $maxwidth = $this->h * $original_aspect_ratio;
2491+ $maxheight = $this->h;
2492+ } else {
2493+ $maxwidth = $this->thumbnailCropW;
2494+ $maxheight = $this->thumbnailCropH;
2495+ }
2496+ } else {
2497+ $maxwidth = phpthumb_functions::nonempty_min($this->w, $this->thumbnailCropW, $this->config_output_maxwidth);
2498+ $maxheight = phpthumb_functions::nonempty_min($this->h, $this->thumbnailCropH, $this->config_output_maxheight);
2499+//echo $maxwidth.'x'.$maxheight.'<br>';
2500+ $maxwidth = min($maxwidth, $maxheight * $original_aspect_ratio);
2501+ $maxheight = min($maxheight, $maxwidth / $original_aspect_ratio);
2502+//echo $maxwidth.'x'.$maxheight.'<hr>';
2503+ }
2504+
2505+ $this->thumbnail_image_width = $maxwidth;
2506+ $this->thumbnail_image_height = $maxheight;
2507+ $this->thumbnail_width = $maxwidth;
2508+ $this->thumbnail_height = $maxheight;
2509+
2510+ $this->FixedAspectRatio();
2511+ }
2512+
2513+ $this->thumbnail_width = max(1, floor($this->thumbnail_width));
2514+ $this->thumbnail_height = max(1, floor($this->thumbnail_height));
2515+ return true;
2516+ }
2517+
2518+
2519+ function CreateGDoutput() {
2520+ $this->CalculateThumbnailDimensions();
2521+
2522+ // Create the GD image (either true-color or 256-color, depending on GD version)
2523+ $this->gdimg_output = phpthumb_functions::ImageCreateFunction($this->thumbnail_width, $this->thumbnail_height);
2524+
2525+ // Images that have transparency must have the background filled with the configured 'bg' color
2526+ // otherwise the transparent color will appear as black
2527+ ImageSaveAlpha($this->gdimg_output, true);
2528+ if ($this->is_alpha && phpthumb_functions::gd_version() >= 2) {
2529+
2530+ ImageAlphaBlending($this->gdimg_output, false);
2531+ $output_full_alpha = phpthumb_functions::ImageColorAllocateAlphaSafe($this->gdimg_output, 255, 255, 255, 127);
2532+ ImageFilledRectangle($this->gdimg_output, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $output_full_alpha);
2533+
2534+ } else {
2535+
2536+ $current_transparent_color = ImageColorTransparent($this->gdimg_source);
2537+ if ($this->bg || (@$current_transparent_color >= 0)) {
2538+
2539+ $this->config_background_hexcolor = ($this->bg ? $this->bg : $this->config_background_hexcolor);
2540+ if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
2541+ return $this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
2542+ }
2543+ $background_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_output, $this->config_background_hexcolor);
2544+ ImageFilledRectangle($this->gdimg_output, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $background_color);
2545+
2546+ }
2547+
2548+ }
2549+ $this->DebugMessage('CreateGDoutput() returning canvas "'.$this->thumbnail_width.'x'.$this->thumbnail_height.'"', __FILE__, __LINE__);
2550+ return true;
2551+ }
2552+
2553+ function SetOrientationDependantWidthHeight() {
2554+ $this->DebugMessage('SetOrientationDependantWidthHeight() starting with "'.$this->source_width.'"x"'.$this->source_height.'"', __FILE__, __LINE__);
2555+ if ($this->source_height > $this->source_width) {
2556+ // portrait
2557+ $this->w = phpthumb_functions::OneOfThese($this->wp, $this->w, $this->ws, $this->wl);
2558+ $this->h = phpthumb_functions::OneOfThese($this->hp, $this->h, $this->hs, $this->hl);
2559+ } elseif ($this->source_height < $this->source_width) {
2560+ // landscape
2561+ $this->w = phpthumb_functions::OneOfThese($this->wl, $this->w, $this->ws, $this->wp);
2562+ $this->h = phpthumb_functions::OneOfThese($this->hl, $this->h, $this->hs, $this->hp);
2563+ } else {
2564+ // square
2565+ $this->w = phpthumb_functions::OneOfThese($this->ws, $this->w, $this->wl, $this->wp);
2566+ $this->h = phpthumb_functions::OneOfThese($this->hs, $this->h, $this->hl, $this->hp);
2567+ }
2568+ //$this->w = round($this->w ? $this->w : (($this->h && $this->source_height) ? $this->h * $this->source_width / $this->source_height : $this->w));
2569+ //$this->h = round($this->h ? $this->h : (($this->w && $this->source_width) ? $this->w * $this->source_height / $this->source_width : $this->h));
2570+ $this->DebugMessage('SetOrientationDependantWidthHeight() setting w="'.intval($this->w).'", h="'.intval($this->h).'"', __FILE__, __LINE__);
2571+ return true;
2572+ }
2573+
2574+ function ExtractEXIFgetImageSize() {
2575+ $this->DebugMessage('starting ExtractEXIFgetImageSize()', __FILE__, __LINE__);
2576+
2577+ if (is_resource($this->gdimg_source)) {
2578+
2579+ $this->source_width = ImageSX($this->gdimg_source);
2580+ $this->source_height = ImageSY($this->gdimg_source);
2581+
2582+ $this->SetOrientationDependantWidthHeight();
2583+
2584+ } elseif ($this->rawImageData && !$this->sourceFilename) {
2585+
2586+ $this->DebugMessage('bypassing EXIF and GetImageSize sections because $this->rawImageData is set and $this->sourceFilename is not set', __FILE__, __LINE__);
2587+
2588+ }
2589+
2590+ if (is_null($this->getimagesizeinfo)) {
2591+ $this->getimagesizeinfo = @GetImageSize($this->sourceFilename);
2592+ }
2593+
2594+ if (!empty($this->getimagesizeinfo)) {
2595+ // great
2596+ $this->getimagesizeinfo['filesize'] = @filesize($this->sourceFilename);
2597+ } elseif (!$this->rawImageData) {
2598+ $this->DebugMessage('GetImageSize("'.$this->sourceFilename.'") failed', __FILE__, __LINE__);
2599+ }
2600+
2601+ if ($this->config_prefer_imagemagick) {
2602+ if ($this->ImageMagickThumbnailToGD()) {
2603+ return true;
2604+ }
2605+ $this->DebugMessage('ImageMagickThumbnailToGD() failed', __FILE__, __LINE__);
2606+ }
2607+
2608+ $this->source_width = $this->getimagesizeinfo[0];
2609+ $this->source_height = $this->getimagesizeinfo[1];
2610+
2611+ $this->SetOrientationDependantWidthHeight();
2612+
2613+ if (phpthumb_functions::version_compare_replacement(phpversion(), '4.2.0', '>=') && function_exists('exif_read_data')) {
2614+ $this->exif_raw_data = @exif_read_data($this->sourceFilename, 0, true);
2615+ }
2616+ if (function_exists('exif_thumbnail') && ($this->getimagesizeinfo[2] == 2)) {
2617+ // Extract EXIF info from JPEGs
2618+
2619+ $this->exif_thumbnail_width = '';
2620+ $this->exif_thumbnail_height = '';
2621+ $this->exif_thumbnail_type = '';
2622+
2623+ // The parameters width, height and imagetype are available since PHP v4.3.0
2624+ if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=')) {
2625+
2626+ $this->exif_thumbnail_data = @exif_thumbnail($this->sourceFilename, $this->exif_thumbnail_width, $this->exif_thumbnail_height, $this->exif_thumbnail_type);
2627+
2628+ } else {
2629+
2630+ // older versions of exif_thumbnail output an error message but NOT return false on failure
2631+ ob_start();
2632+ $this->exif_thumbnail_data = exif_thumbnail($this->sourceFilename);
2633+ $exit_thumbnail_error = ob_get_contents();
2634+ ob_end_clean();
2635+ if (!$exit_thumbnail_error && $this->exif_thumbnail_data) {
2636+
2637+ if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) {
2638+ $this->exif_thumbnail_width = ImageSX($gdimg_exif_temp);
2639+ $this->exif_thumbnail_height = ImageSY($gdimg_exif_temp);
2640+ $this->exif_thumbnail_type = 2; // (2 == JPEG) before PHP v4.3.0 only JPEG format EXIF thumbnails are returned
2641+ unset($gdimg_exif_temp);
2642+ } else {
2643+ return $this->ErrorImage('Failed - $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data) in '.__FILE__.' on line '.__LINE__);
2644+ }
2645+
2646+ }
2647+
2648+ }
2649+
2650+ } elseif (!function_exists('exif_thumbnail')) {
2651+
2652+ $this->DebugMessage('exif_thumbnail() does not exist, cannot extract EXIF thumbnail', __FILE__, __LINE__);
2653+ return false;
2654+
2655+ }
2656+
2657+ $this->DebugMessage('EXIF thumbnail extraction: (size='.strlen($this->exif_thumbnail_data).'; type="'.$this->exif_thumbnail_type.'"; '.intval($this->exif_thumbnail_width).'x'.intval($this->exif_thumbnail_height).')', __FILE__, __LINE__);
2658+
2659+ // see if EXIF thumbnail can be used directly with no processing
2660+ if ($this->config_use_exif_thumbnail_for_speed && $this->exif_thumbnail_data) {
2661+ while (true) {
2662+ if (!$this->xto) {
2663+ $source_ar = $this->source_width / $this->source_height;
2664+ $exif_ar = $this->exif_thumbnail_width / $this->exif_thumbnail_height;
2665+ if (number_format($source_ar, 2) != number_format($exif_ar, 2)) {
2666+ $this->DebugMessage('not using EXIF thumbnail because $source_ar != $exif_ar ('.$source_ar.' != '.$exif_ar.')', __FILE__, __LINE__);
2667+ break;
2668+ }
2669+ if ($this->w && ($this->w != $this->exif_thumbnail_width)) {
2670+ $this->DebugMessage('not using EXIF thumbnail because $this->w != $this->exif_thumbnail_width ('.$this->w.' != '.$this->exif_thumbnail_width.')', __FILE__, __LINE__);
2671+ break;
2672+ }
2673+ if ($this->h && ($this->h != $this->exif_thumbnail_height)) {
2674+ $this->DebugMessage('not using EXIF thumbnail because $this->h != $this->exif_thumbnail_height ('.$this->h.' != '.$this->exif_thumbnail_height.')', __FILE__, __LINE__);
2675+ break;
2676+ }
2677+ $CannotBeSetParameters = array('sx', 'sy', 'sh', 'sw', 'far', 'bg', 'bc', 'fltr', 'phpThumbDebug');
2678+ foreach ($CannotBeSetParameters as $dummy => $parameter) {
2679+ if ($this->$parameter) {
2680+ break 2;
2681+ }
2682+ }
2683+ }
2684+
2685+ $this->DebugMessage('setting $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data)', __FILE__, __LINE__);
2686+ $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data);
2687+ $this->source_width = ImageSX($this->gdimg_source);
2688+ $this->source_height = ImageSY($this->gdimg_source);
2689+ return true;
2690+ }
2691+ }
2692+
2693+ if (($this->config_max_source_pixels > 0) && (($this->source_width * $this->source_height) > $this->config_max_source_pixels)) {
2694+
2695+ // Source image is larger than would fit in available PHP memory.
2696+ // If ImageMagick is installed, use it to generate the thumbnail.
2697+ // Else, if an EXIF thumbnail is available, use that as the source image.
2698+ // Otherwise, no choice but to fail with an error message
2699+ $this->DebugMessage('image is '.$this->source_width.'x'.$this->source_height.' and therefore contains more pixels ('.($this->source_width * $this->source_height).') than $this->config_max_source_pixels setting ('.$this->config_max_source_pixels.')', __FILE__, __LINE__);
2700+ if (!$this->config_prefer_imagemagick && $this->ImageMagickThumbnailToGD()) {
2701+ // excellent, we have a thumbnailed source image
2702+ return true;
2703+ }
2704+
2705+ }
2706+ return true;
2707+ }
2708+
2709+
2710+ function SetCacheFilename() {
2711+ if (!is_null($this->cache_filename)) {
2712+ $this->DebugMessage('$this->cache_filename already set, skipping SetCacheFilename()', __FILE__, __LINE__);
2713+ return true;
2714+ }
2715+ $this->setOutputFormat();
2716+ $this->setCacheDirectory();
2717+ if (!$this->config_cache_directory) {
2718+ $this->DebugMessage('SetCacheFilename() failed because $this->config_cache_directory is empty', __FILE__, __LINE__);
2719+ return false;
2720+ }
2721+
2722+ if (!$this->sourceFilename && !$this->rawImageData && $this->src) {
2723+ $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->src);
2724+ }
2725+
2726+ if ($this->config_cache_default_only_suffix && $this->sourceFilename) {
2727+ // simplified cache filenames:
2728+ // only use default parameters in phpThumb.config.php
2729+ // substitute source filename into * in $this->config_cache_default_only_suffix
2730+ // (eg: '*_thumb' becomes 'picture_thumb.jpg')
2731+ if (strpos($this->config_cache_default_only_suffix, '*') === false) {
2732+ $this->DebugMessage('aborting simplified caching filename because no * in "'.$this->config_cache_default_only_suffix.'"', __FILE__, __LINE__);
2733+ } else {
2734+ eregi('(.+)(\.[a-z0-9]+)?$', basename($this->sourceFilename), $matches);
2735+ $this->cache_filename = $this->config_cache_directory.DIRECTORY_SEPARATOR.rawurlencode(str_replace('*', @$matches[1], $this->config_cache_default_only_suffix)).'.'.strtolower($this->thumbnailFormat);
2736+ return true;
2737+ }
2738+ }
2739+
2740+ $this->cache_filename = '';
2741+ $broad_directory_name = '';
2742+ if ($this->new) {
2743+ $broad_directory_name = strtolower(md5($this->new));
2744+ $this->cache_filename .= '_new'.$broad_directory_name;
2745+ } elseif ($this->md5s) {
2746+ // source image MD5 hash provided
2747+ $this->DebugMessage('SetCacheFilename() _raw set from $this->md5s = "'.$this->md5s.'"', __FILE__, __LINE__);
2748+ $broad_directory_name = $this->md5s;
2749+ $this->cache_filename .= '_raw'.$this->md5s;
2750+ } elseif (!$this->src && $this->rawImageData) {
2751+ $this->DebugMessage('SetCacheFilename() _raw set from md5($this->rawImageData) = "'.md5($this->rawImageData).'"', __FILE__, __LINE__);
2752+ $broad_directory_name = strtolower(md5($this->rawImageData));
2753+ $this->cache_filename .= '_raw'.$broad_directory_name;
2754+ } else {
2755+ $this->DebugMessage('SetCacheFilename() _src set from md5($this->sourceFilename) "'.$this->sourceFilename.'" = "'.md5($this->sourceFilename).'"', __FILE__, __LINE__);
2756+ $broad_directory_name = strtolower(md5($this->sourceFilename));
2757+ $this->cache_filename .= '_src'.$broad_directory_name;
2758+ }
2759+ if (@$_SERVER['HTTP_REFERER'] && $this->config_nooffsitelink_enabled) {
2760+ $parsed_url1 = @parse_url(@$_SERVER['HTTP_REFERER']);
2761+ $parsed_url2 = @parse_url('http://'.@$_SERVER['HTTP_HOST']);
2762+ if (@$parsed_url1['host'] && @$parsed_url2['host'] && ($parsed_url1['host'] != $parsed_url2['host'])) {
2763+ // include "_offsite" only if nooffsitelink_enabled and if referrer doesn't match the domain of the current server
2764+ $this->cache_filename .= '_offsite';
2765+ }
2766+ }
2767+
2768+ $ParametersString = '';
2769+ if ($this->fltr && is_array($this->fltr)) {
2770+ $ParametersString .= '_fltr'.implode('_fltr', $this->fltr);
2771+ }
2772+ $FilenameParameters1 = array('ar', 'bg', 'bc', 'far', 'sx', 'sy', 'sw', 'sh', 'zc');
2773+ foreach ($FilenameParameters1 as $dummy => $key) {
2774+ if ($this->$key) {
2775+ $ParametersString .= '_'.$key.$this->$key;
2776+ }
2777+ }
2778+ $FilenameParameters2 = array('h', 'w', 'wl', 'wp', 'ws', 'hp', 'hs', 'xto', 'ra', 'iar', 'aoe', 'maxb', 'sfn', 'dpi');
2779+ foreach ($FilenameParameters2 as $dummy => $key) {
2780+ if ($this->$key) {
2781+ $ParametersString .= '_'.$key.intval($this->$key);
2782+ }
2783+ }
2784+ if ($this->thumbnailFormat == 'jpeg') {
2785+ // only JPEG output has variable quality option
2786+ $ParametersString .= '_q'.intval($this->thumbnailQuality);
2787+ }
2788+ $this->DebugMessage('SetCacheFilename() _par set from md5('.$ParametersString.')', __FILE__, __LINE__);
2789+ $this->cache_filename .= '_par'.strtolower(md5($ParametersString));
2790+
2791+ if ($this->md5s) {
2792+ // source image MD5 hash provided
2793+ // do not source image modification date --
2794+ // cached image will be used even if file was modified or removed
2795+ } elseif (!$this->config_cache_source_filemtime_ignore_remote && eregi('^(f|ht)tps?\://', $this->src)) {
2796+ $this->cache_filename .= '_dat'.intval(phpthumb_functions::filedate_remote($this->src));
2797+ } elseif (!$this->config_cache_source_filemtime_ignore_local && $this->src && !$this->rawImageData) {
2798+ $this->cache_filename .= '_dat'.intval(@filemtime($this->sourceFilename));
2799+ }
2800+
2801+ $this->cache_filename .= '.'.strtolower($this->thumbnailFormat);
2802+ $broad_directories = '';
2803+ for ($i = 0; $i < $this->config_cache_directory_depth; $i++) {
2804+ $broad_directories .= DIRECTORY_SEPARATOR.substr($broad_directory_name, 0, $i + 1);
2805+ }
2806+
2807+ $this->cache_filename = $this->config_cache_directory.$broad_directories.DIRECTORY_SEPARATOR.$this->config_cache_prefix.rawurlencode($this->cache_filename);
2808+ return true;
2809+ }
2810+
2811+
2812+ function SourceImageIsTooLarge($width, $height) {
2813+ if (!$this->config_max_source_pixels) {
2814+ return false;
2815+ }
2816+ return (bool) (($width * $height) > $this->config_max_source_pixels);
2817+ }
2818+
2819+ function ImageCreateFromFilename($filename) {
2820+ // try to create GD image source directly via GD, if possible,
2821+ // rather than buffering to memory and creating with ImageCreateFromString
2822+ $ImageCreateWasAttempted = false;
2823+ $gd_image = false;
2824+
2825+ $this->DebugMessage('starting ImageCreateFromFilename('.$filename.')', __FILE__, __LINE__);
2826+
2827+ if ($filename && ($getimagesizeinfo = @GetImageSize($filename))) {
2828+ if (!$this->SourceImageIsTooLarge($getimagesizeinfo[0], $getimagesizeinfo[1])) {
2829+ $ImageCreateFromFunction = array(
2830+ 1 => 'ImageCreateFromGIF',
2831+ 2 => 'ImageCreateFromJPEG',
2832+ 3 => 'ImageCreateFromPNG',
2833+ 15 => 'ImageCreateFromWBMP',
2834+ );
2835+ $this->DebugMessage('ImageCreateFromFilename found ($getimagesizeinfo[2]=='.@$getimagesizeinfo[2].')', __FILE__, __LINE__);
2836+ switch (@$getimagesizeinfo[2]) {
2837+ case 1: // GIF
2838+ case 2: // JPEG
2839+ case 3: // PNG
2840+ case 15: // WBMP
2841+ $ImageCreateFromFunctionName = $ImageCreateFromFunction[$getimagesizeinfo[2]];
2842+ if (function_exists($ImageCreateFromFunctionName)) {
2843+ $this->DebugMessage('Calling '.$ImageCreateFromFunctionName.'('.$filename.')', __FILE__, __LINE__);
2844+ $ImageCreateWasAttempted = true;
2845+ $gd_image = @$ImageCreateFromFunctionName($filename);
2846+ } else {
2847+ $this->DebugMessage('NOT calling '.$ImageCreateFromFunctionName.'('.$filename.') because !function_exists('.$ImageCreateFromFunctionName.')', __FILE__, __LINE__);
2848+ }
2849+ break;
2850+
2851+ case 4: // SWF
2852+ case 5: // PSD
2853+ case 6: // BMP
2854+ case 7: // TIFF (LE)
2855+ case 8: // TIFF (BE)
2856+ case 9: // JPC
2857+ case 10: // JP2
2858+ case 11: // JPX
2859+ case 12: // JB2
2860+ case 13: // SWC
2861+ case 14: // IFF
2862+ case 16: // XBM
2863+ $this->DebugMessage('No built-in image creation function for image type "'.@$getimagesizeinfo[2].'" ($getimagesizeinfo[2])', __FILE__, __LINE__);
2864+ break;
2865+
2866+ default:
2867+ $this->DebugMessage('Unknown value for $getimagesizeinfo[2]: "'.@$getimagesizeinfo[2].'"', __FILE__, __LINE__);
2868+ break;
2869+ }
2870+ } else {
2871+ $this->DebugMessage('image is '.$getimagesizeinfo[0].'x'.$getimagesizeinfo[1].' and therefore contains more pixels ('.($getimagesizeinfo[0] * $getimagesizeinfo[1]).') than $this->config_max_source_pixels setting ('.$this->config_max_source_pixels.')', __FILE__, __LINE__);
2872+ return false;
2873+ }
2874+ } else {
2875+ $this->DebugMessage('empty $filename or GetImageSize('.$filename.') failed', __FILE__, __LINE__);
2876+ }
2877+
2878+ if (!$gd_image) {
2879+ // cannot create from filename, attempt to create source image with ImageCreateFromString, if possible
2880+ if ($ImageCreateWasAttempted) {
2881+ $this->DebugMessage(@$ImageCreateFromFunctionName.'() was attempted but FAILED', __FILE__, __LINE__);
2882+ }
2883+ $this->DebugMessage('Populating $rawimagedata', __FILE__, __LINE__);
2884+ $rawimagedata = '';
2885+ if ($fp = @fopen($filename, 'rb')) {
2886+ $filesize = filesize($filename);
2887+ $blocksize = 8192;
2888+ $blockreads = ceil($filesize / $blocksize);
2889+ for ($i = 0; $i < $blockreads; $i++) {
2890+ $rawimagedata .= fread($fp, $blocksize);
2891+ }
2892+ fclose($fp);
2893+ } else {
2894+ $this->DebugMessage('cannot fopen('.$filename.')', __FILE__, __LINE__);
2895+ }
2896+ if ($rawimagedata) {
2897+ $this->DebugMessage('attempting ImageCreateFromStringReplacement($rawimagedata ('.strlen($rawimagedata).' bytes), true)', __FILE__, __LINE__);
2898+ $gd_image = $this->ImageCreateFromStringReplacement($rawimagedata, true);
2899+ }
2900+ }
2901+ return $gd_image;
2902+ }
2903+
2904+ function SourceImageToGD() {
2905+ if (is_resource($this->gdimg_source)) {
2906+ $this->source_width = ImageSX($this->gdimg_source);
2907+ $this->source_height = ImageSY($this->gdimg_source);
2908+ $this->DebugMessage('skipping SourceImageToGD() because $this->gdimg_source is already a resource ('.$this->source_width.'x'.$this->source_height.')', __FILE__, __LINE__);
2909+ return true;
2910+ }
2911+ $this->DebugMessage('starting SourceImageToGD()', __FILE__, __LINE__);
2912+
2913+ if (!$this->gdimg_source && $this->rawImageData) {
2914+
2915+ if ($this->md5s && ($this->md5s != md5($this->rawImageData))) {
2916+ return $this->ErrorImage('$this->md5s != md5($this->rawImageData)'."\n".'"'.$this->md5s.'" != '."\n".'"'.md5($this->rawImageData).'"');
2917+ }
2918+ $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->rawImageData);
2919+ if (!$this->gdimg_source) {
2920+ return $this->ErrorImage('Unknown image type identified by "'.substr($this->rawImageData, 0, 4).'" ('.phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 4)).') in SourceImageToGD()['.__LINE__.']');
2921+ }
2922+
2923+ } elseif (!$this->gdimg_source && $this->sourceFilename) {
2924+
2925+ if ($this->md5s && ($this->md5s != phpthumb_functions::md5_file_safe($this->sourceFilename))) {
2926+ return $this->ErrorImage('$this->md5s != md5(sourceFilename)'."\n".'"'.$this->md5s.'" != '."\n".'"'.phpthumb_functions::md5_file_safe($this->sourceFilename).'"');
2927+ }
2928+ switch (@$this->getimagesizeinfo[2]) {
2929+ case 1:
2930+ case 3:
2931+ // GIF or PNG input file may have transparency
2932+ $this->is_alpha = true;
2933+ break;
2934+ }
2935+ $this->gdimg_source = $this->ImageCreateFromFilename($this->sourceFilename);
2936+
2937+ }
2938+
2939+ while (true) {
2940+ if ($this->gdimg_source) {
2941+ $this->DebugMessage('Not using EXIF thumbnail data because $this->gdimg_source is already set', __FILE__, __LINE__);
2942+ break;
2943+ }
2944+ if (!$this->exif_thumbnail_data) {
2945+ $this->DebugMessage('Not using EXIF thumbnail data because $this->exif_thumbnail_data is empty', __FILE__, __LINE__);
2946+ break;
2947+ }
2948+ if (ini_get('safe_mode')) {
2949+ if (($this->config_max_source_pixels > 0) && (($this->source_width * $this->source_height) > $this->config_max_source_pixels)) {
2950+ $this->DebugMessage('Using EXIF thumbnail data because source image too large and safe_mode enabled', __FILE__, __LINE__);
2951+ $this->aoe = true;
2952+ } else {
2953+ break;
2954+ }
2955+ } else {
2956+ if (!$this->config_use_exif_thumbnail_for_speed) {
2957+ $this->DebugMessage('Not using EXIF thumbnail data because $this->config_use_exif_thumbnail_for_speed is FALSE', __FILE__, __LINE__);
2958+ break;
2959+ }
2960+ if (($this->thumbnailCropX != 0) || ($this->thumbnailCropY != 0)) {
2961+ $this->DebugMessage('Not using EXIF thumbnail data because source cropping is enabled ('.$this->thumbnailCropX.','.$this->thumbnailCropY.')', __FILE__, __LINE__);
2962+ break;
2963+ }
2964+ if (($this->w > $this->exif_thumbnail_width) || ($this->h > $this->exif_thumbnail_height)) {
2965+ $this->DebugMessage('Not using EXIF thumbnail data because EXIF thumbnail is too small ('.$this->exif_thumbnail_width.'x'.$this->exif_thumbnail_height.' vs '.$this->w.'x'.$this->h.')', __FILE__, __LINE__);
2966+ break;
2967+ }
2968+ $source_ar = $this->source_width / $this->source_height;
2969+ $exif_ar = $this->exif_thumbnail_width / $this->exif_thumbnail_height;
2970+ if (number_format($source_ar, 2) != number_format($exif_ar, 2)) {
2971+ $this->DebugMessage('not using EXIF thumbnail because $source_ar != $exif_ar ('.$source_ar.' != '.$exif_ar.')', __FILE__, __LINE__);
2972+ break;
2973+ }
2974+ }
2975+
2976+ // EXIF thumbnail exists, and is equal to or larger than destination thumbnail, and will be use as source image
2977+ $this->DebugMessage('Trying to use EXIF thumbnail as source image', __FILE__, __LINE__);
2978+
2979+ if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) {
2980+
2981+ $this->DebugMessage('Successfully using EXIF thumbnail as source image', __FILE__, __LINE__);
2982+ $this->gdimg_source = $gdimg_exif_temp;
2983+ $this->source_width = $this->exif_thumbnail_width;
2984+ $this->source_height = $this->exif_thumbnail_height;
2985+ $this->thumbnailCropW = $this->source_width;
2986+ $this->thumbnailCropH = $this->source_height;
2987+ return true;
2988+
2989+ } else {
2990+ $this->DebugMessage('$this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false) failed', __FILE__, __LINE__);
2991+ }
2992+
2993+ break;
2994+ }
2995+
2996+ if (!$this->gdimg_source) {
2997+ $this->DebugMessage('$this->gdimg_source is still empty', __FILE__, __LINE__);
2998+
2999+ if ($this->ImageMagickThumbnailToGD()) {
3000+
3001+ // excellent, we have a thumbnailed source image
3002+ $this->DebugMessage('ImageMagickThumbnailToGD() succeeded', __FILE__, __LINE__);
3003+
3004+ } else {
3005+
3006+ $this->DebugMessage('ImageMagickThumbnailToGD() failed', __FILE__, __LINE__);
3007+
3008+ $imageHeader = '';
3009+ $gd_info = gd_info();
3010+ $GDreadSupport = false;
3011+ switch (@$this->getimagesizeinfo[2]) {
3012+ case 1:
3013+ $imageHeader = 'Content-Type: image/gif';
3014+ $GDreadSupport = (bool) @$gd_info['GIF Read Support'];
3015+ break;
3016+ case 2:
3017+ $imageHeader = 'Content-Type: image/jpeg';
3018+ $GDreadSupport = (bool) @$gd_info['JPG Support'];
3019+ break;
3020+ case 3:
3021+ $imageHeader = 'Content-Type: image/png';
3022+ $GDreadSupport = (bool) @$gd_info['PNG Support'];
3023+ break;
3024+ }
3025+ if ($imageHeader) {
3026+ // cannot create image for whatever reason (maybe ImageCreateFromJPEG et al are not available?)
3027+ // and ImageMagick is not available either, no choice but to output original (not resized/modified) data and exit
3028+ if ($this->config_error_die_on_source_failure) {
3029+ $errormessage = 'All attempts to create GD image source failed.';
3030+ if (ini_get('safe_mode')) {
3031+ $errormessage .= ' Safe Mode enabled, therefore ImageMagick is unavailable.';
3032+ }
3033+ if (!$this->ImageMagickVersion()) {
3034+ $errormessage .= ' ImageMagick is not installed (it is highly recommended that you install it).';
3035+ }
3036+ if ($this->SourceImageIsTooLarge($this->getimagesizeinfo[0], $this->getimagesizeinfo[1])) {
3037+ $errormessage .= ' Source image is too large ('.$this->getimagesizeinfo[0].'x'.$this->getimagesizeinfo[1].' = '.number_format($this->getimagesizeinfo[0] * $this->getimagesizeinfo[1] / 1000000, 1).'Mpx, max='.number_format($this->config_max_source_pixels / 1000000, 1).'Mpx) for GD creation (either install ImageMagick or increase PHP memory_limit to at least '.ceil(5 * $this->getimagesizeinfo[0] * $this->getimagesizeinfo[1] / 1000000).'M).';
3038+ } elseif (!$GDreadSupport) {
3039+ $errormessage .= ' GD does not have read support for "'.$imageHeader.'".';
3040+ } else {
3041+ $errormessage .= ' Source image probably corrupt.';
3042+ }
3043+ $this->ErrorImage($errormessage);
3044+
3045+ } else {
3046+ $this->DebugMessage('All attempts to create GD image source failed ('.(ini_get('safe_mode') ? 'Safe Mode enabled, ImageMagick unavailable and source image probably too large for GD': ($GDreadSupport ? 'source image probably corrupt' : 'GD does not have read support for "'.$imageHeader.'"')).'), cannot generate thumbnail');
3047+ //$this->DebugMessage('All attempts to create GD image source failed ('.($GDreadSupport ? 'source image probably corrupt' : 'GD does not have read support for "'.$imageHeader.'"').'), outputing raw image', __FILE__, __LINE__);
3048+ //if (!$this->phpThumbDebug) {
3049+ // header($imageHeader);
3050+ // echo $this->rawImageData;
3051+ // exit;
3052+ //}
3053+ return false;
3054+ }
3055+ }
3056+
3057+ //switch (substr($this->rawImageData, 0, 2)) {
3058+ // case 'BM':
3059+ switch (@$this->getimagesizeinfo[2]) {
3060+ case 6:
3061+ ob_start();
3062+ if (!@include_once(dirname(__FILE__).'/phpthumb.bmp.php')) {
3063+ ob_end_clean();
3064+ return $this->ErrorImage('include_once('.dirname(__FILE__).'/phpthumb.bmp.php) failed');
3065+ }
3066+ ob_end_clean();
3067+ if ($fp = @fopen($this->sourceFilename, 'rb')) {
3068+ $this->rawImageData = '';
3069+ while (!feof($fp)) {
3070+ $this->rawImageData .= fread($fp, 32768);
3071+ }
3072+ fclose($fp);
3073+ }
3074+ $phpthumb_bmp = new phpthumb_bmp();
3075+ if ($this->gdimg_source = $phpthumb_bmp->phpthumb_bmp2gd($this->rawImageData, (phpthumb_functions::gd_version() >= 2.0))) {
3076+ $this->DebugMessage('$phpthumb_bmp->phpthumb_bmp2gd() succeeded', __FILE__, __LINE__);
3077+ break;
3078+ }
3079+ return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on BMP source conversion' : 'phpthumb_bmp2gd() failed');
3080+ break;
3081+ //}
3082+ //switch (substr($this->rawImageData, 0, 4)) {
3083+ // case 'II'."\x2A\x00":
3084+ // case 'MM'."\x00\x2A":
3085+ case 7:
3086+ case 8:
3087+ return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on TIFF source conversion' : 'ImageMagick is unavailable and phpThumb() does not support TIFF source images without it');
3088+ break;
3089+
3090+ //case "\xD7\xCD\xC6\x9A":
3091+ // return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on WMF source conversion' : 'ImageMagick is unavailable and phpThumb() does not support WMF source images without it');
3092+ // break;
3093+ }
3094+
3095+ if (!$this->gdimg_source) {
3096+ $HeaderFourBytes = '';
3097+ if ($fp = @fopen($this->sourceFilename, 'rb')) {
3098+ $HeaderFourBytes = fread($fp, 4);
3099+ fclose($fp);
3100+ }
3101+ if ($HeaderFourBytes == "\xD7\xCD\xC6\x9A") {
3102+ return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on WMF source conversion' : 'ImageMagick is unavailable and phpThumb() does not support WMF source images without it');
3103+ } elseif ($HeaderFourBytes == '%PDF') { //0x25504446
3104+ return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick and GhostScript are both required for PDF source images; GhostScript may not be properly configured' : 'ImageMagick and/or GhostScript are unavailable and phpThumb() does not support PDF source images without them');
3105+ }
3106+ return $this->ErrorImage('Unknown image type identified by "'.substr($HeaderFourBytes, 0, 4).'" ('.phpthumb_functions::HexCharDisplay(substr($HeaderFourBytes, 0, 4)).') in SourceImageToGD()['.__LINE__.']');
3107+ }
3108+
3109+ }
3110+ }
3111+
3112+ if (!$this->gdimg_source) {
3113+ if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) {
3114+ $this->DebugMessage('All other attempts failed, but successfully using EXIF thumbnail as source image', __FILE__, __LINE__);
3115+ $this->gdimg_source = $gdimg_exif_temp;
3116+ // override allow-enlarging setting if EXIF thumbnail is the only source available
3117+ // otherwise thumbnails larger than the EXIF thumbnail will be created at EXIF size
3118+ $this->aoe = true;
3119+ return true;
3120+ }
3121+ return false;
3122+ }
3123+
3124+ $this->source_width = ImageSX($this->gdimg_source);
3125+ $this->source_height = ImageSY($this->gdimg_source);
3126+ return true;
3127+ }
3128+
3129+
3130+ function phpThumbDebugVarDump($var) {
3131+ if (is_null($var)) {
3132+ return 'NULL';
3133+ } elseif (is_bool($var)) {
3134+ return ($var ? 'TRUE' : 'FALSE');
3135+ } elseif (is_string($var)) {
3136+ return 'string('.strlen($var).')'.str_repeat(' ', max(0, 3 - strlen(strlen($var)))).' "'.$var.'"';
3137+ } elseif (is_int($var)) {
3138+ return 'integer '.$var;
3139+ } elseif (is_float($var)) {
3140+ return 'float '.$var;
3141+ } elseif (is_array($var)) {
3142+ ob_start();
3143+ var_dump($var);
3144+ $vardumpoutput = ob_get_contents();
3145+ ob_end_clean();
3146+ return strtr($vardumpoutput, "\n\r\t", ' ');
3147+ }
3148+ return gettype($var);
3149+ }
3150+
3151+ function phpThumbDebug() {
3152+ if ($this->config_disable_debug) {
3153+ return $this->ErrorImage('phpThumbDebug disabled');
3154+ }
3155+
3156+ $FunctionsExistance = array('exif_thumbnail', 'gd_info', 'image_type_to_mime_type', 'ImageCopyResampled', 'ImageCopyResized', 'ImageCreate', 'ImageCreateFromString', 'ImageCreateTrueColor', 'ImageIsTrueColor', 'ImageRotate', 'ImageTypes', 'version_compare', 'ImageCreateFromGIF', 'ImageCreateFromJPEG', 'ImageCreateFromPNG', 'ImageCreateFromWBMP', 'ImageCreateFromXBM', 'ImageCreateFromXPM', 'ImageCreateFromString', 'ImageCreateFromGD', 'ImageCreateFromGD2', 'ImageCreateFromGD2Part', 'ImageJPEG', 'ImageGIF', 'ImagePNG', 'ImageWBMP');
3157+ $ParameterNames = array('src', 'new', 'w', 'h', 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'far', 'bg', 'bc', 'file', 'goto', 'err', 'xto', 'ra', 'ar', 'aoe', 'iar', 'maxb');
3158+ $ConfigVariableNames = array('document_root', 'temp_directory', 'output_format', 'output_maxwidth', 'output_maxheight', 'error_message_image_default', 'error_bgcolor', 'error_textcolor', 'error_fontsize', 'error_die_on_error', 'error_silent_die_on_error', 'error_die_on_source_failure', 'nohotlink_enabled', 'nohotlink_valid_domains', 'nohotlink_erase_image', 'nohotlink_text_message', 'nooffsitelink_enabled', 'nooffsitelink_valid_domains', 'nooffsitelink_require_refer', 'nooffsitelink_erase_image', 'nooffsitelink_text_message', 'high_security_enabled', 'allow_src_above_docroot', 'allow_src_above_phpthumb', 'allow_parameter_file', 'allow_parameter_goto', 'max_source_pixels', 'use_exif_thumbnail_for_speed', 'border_hexcolor', 'background_hexcolor', 'ttf_directory', 'disable_pathinfo_parsing', 'disable_imagecopyresampled');
3159+ $OtherVariableNames = array('phpThumbDebug', 'thumbnailQuality', 'thumbnailFormat', 'gdimg_output', 'gdimg_source', 'sourceFilename', 'source_width', 'source_height', 'thumbnailCropX', 'thumbnailCropY', 'thumbnailCropW', 'thumbnailCropH', 'exif_thumbnail_width', 'exif_thumbnail_height', 'exif_thumbnail_type', 'thumbnail_width', 'thumbnail_height', 'thumbnail_image_width', 'thumbnail_image_height');
3160+
3161+ $DebugOutput = array();
3162+ $DebugOutput[] = 'phpThumb() version = '.$this->phpthumb_version;
3163+ $DebugOutput[] = 'phpversion() = '.@phpversion();
3164+ $DebugOutput[] = 'PHP_OS = '.PHP_OS;
3165+ $DebugOutput[] = '__FILE__ = '.__FILE__;
3166+ $DebugOutput[] = 'realpath(.) = '.@realpath('.');
3167+ $DebugOutput[] = '$_SERVER[PHP_SELF] = '.@$_SERVER['PHP_SELF'];
3168+ $DebugOutput[] = '$_SERVER[HOST_NAME] = '.@$_SERVER['HOST_NAME'];
3169+ $DebugOutput[] = '$_SERVER[HTTP_REFERER] = '.@$_SERVER['HTTP_REFERER'];
3170+ $DebugOutput[] = '$_SERVER[QUERY_STRING] = '.@$_SERVER['QUERY_STRING'];
3171+ $DebugOutput[] = '$_SERVER[PATH_INFO] = '.@$_SERVER['PATH_INFO'];
3172+ $DebugOutput[] = '$_SERVER[DOCUMENT_ROOT] = '.@$_SERVER['DOCUMENT_ROOT'];
3173+ $DebugOutput[] = 'getenv(DOCUMENT_ROOT) = '.@getenv('DOCUMENT_ROOT');
3174+ $DebugOutput[] = '';
3175+
3176+ $DebugOutput[] = 'get_magic_quotes_gpc() = '.$this->phpThumbDebugVarDump(@get_magic_quotes_gpc());
3177+ $DebugOutput[] = 'get_magic_quotes_runtime() = '.$this->phpThumbDebugVarDump(@get_magic_quotes_runtime());
3178+ $DebugOutput[] = 'error_reporting() = '.$this->phpThumbDebugVarDump(error_reporting());
3179+ $DebugOutput[] = 'ini_get(error_reporting) = '.$this->phpThumbDebugVarDump(@ini_get('error_reporting'));
3180+ $DebugOutput[] = 'ini_get(display_errors) = '.$this->phpThumbDebugVarDump(@ini_get('display_errors'));
3181+ $DebugOutput[] = 'ini_get(allow_url_fopen) = '.$this->phpThumbDebugVarDump(@ini_get('allow_url_fopen'));
3182+ $DebugOutput[] = 'ini_get(disable_functions) = '.$this->phpThumbDebugVarDump(@ini_get('disable_functions'));
3183+ $DebugOutput[] = 'ini_get(safe_mode) = '.$this->phpThumbDebugVarDump(@ini_get('safe_mode'));
3184+ $DebugOutput[] = 'ini_get(open_basedir) = '.$this->phpThumbDebugVarDump(@ini_get('open_basedir'));
3185+ $DebugOutput[] = 'ini_get(max_execution_time) = '.$this->phpThumbDebugVarDump(@ini_get('max_execution_time'));
3186+ $DebugOutput[] = 'ini_get(memory_limit) = '.$this->phpThumbDebugVarDump(@ini_get('memory_limit'));
3187+ $DebugOutput[] = 'get_cfg_var(memory_limit) = '.$this->phpThumbDebugVarDump(@get_cfg_var('memory_limit'));
3188+ $DebugOutput[] = 'memory_get_usage() = '.(function_exists('memory_get_usage') ? $this->phpThumbDebugVarDump(@memory_get_usage()) : 'n/a');
3189+ $DebugOutput[] = '';
3190+
3191+ $DebugOutput[] = '$this->config_prefer_imagemagick = '.$this->phpThumbDebugVarDump($this->config_prefer_imagemagick);
3192+ $DebugOutput[] = '$this->config_imagemagick_path = '.$this->phpThumbDebugVarDump($this->config_imagemagick_path);
3193+ $DebugOutput[] = '$this->ImageMagickWhichConvert() = '.$this->ImageMagickWhichConvert();
3194+ $IMpathUsed = ($this->config_imagemagick_path ? $this->config_imagemagick_path : $this->ImageMagickWhichConvert());
3195+ $DebugOutput[] = '[actual ImageMagick path used] = '.$this->phpThumbDebugVarDump($IMpathUsed);
3196+ $DebugOutput[] = 'file_exists([actual ImageMagick path used]) = '.$this->phpThumbDebugVarDump(@file_exists($IMpathUsed));
3197+ $DebugOutput[] = 'ImageMagickVersion(false) = '.$this->ImageMagickVersion(false);
3198+ $DebugOutput[] = 'ImageMagickVersion(true) = '.$this->ImageMagickVersion(true);
3199+ $DebugOutput[] = '';
3200+
3201+ $DebugOutput[] = '$this->config_cache_directory = '.$this->phpThumbDebugVarDump($this->config_cache_directory);
3202+ $DebugOutput[] = '$this->config_cache_directory_depth = '.$this->phpThumbDebugVarDump($this->config_cache_directory_depth);
3203+ $DebugOutput[] = '$this->config_cache_disable_warning = '.$this->phpThumbDebugVarDump($this->config_cache_disable_warning);
3204+ $DebugOutput[] = '$this->config_cache_maxage = '.$this->phpThumbDebugVarDump($this->config_cache_maxage);
3205+ $DebugOutput[] = '$this->config_cache_maxsize = '.$this->phpThumbDebugVarDump($this->config_cache_maxsize);
3206+ $DebugOutput[] = '$this->config_cache_maxfiles = '.$this->phpThumbDebugVarDump($this->config_cache_maxfiles);
3207+ $DebugOutput[] = '$this->config_cache_force_passthru = '.$this->phpThumbDebugVarDump($this->config_cache_force_passthru);
3208+ $DebugOutput[] = '$this->cache_filename = '.$this->phpThumbDebugVarDump($this->cache_filename);
3209+ $DebugOutput[] = 'is_readable($this->config_cache_directory) = '.$this->phpThumbDebugVarDump(@is_readable($this->config_cache_directory));
3210+ $DebugOutput[] = 'is_writable($this->config_cache_directory) = '.$this->phpThumbDebugVarDump(@is_writable($this->config_cache_directory));
3211+ $DebugOutput[] = 'is_readable($this->cache_filename) = '.$this->phpThumbDebugVarDump(@is_readable($this->cache_filename));
3212+ $DebugOutput[] = 'is_writable($this->cache_filename) = '.(@file_exists($this->cache_filename) ? $this->phpThumbDebugVarDump(@is_writable($this->cache_filename)) : 'n/a');
3213+ $DebugOutput[] = '';
3214+
3215+ foreach ($ConfigVariableNames as $dummy => $varname) {
3216+ $varname = 'config_'.$varname;
3217+ $value = $this->$varname;
3218+ $DebugOutput[] = '$this->'.str_pad($varname, 37, ' ', STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
3219+ }
3220+ $DebugOutput[] = '';
3221+ foreach ($OtherVariableNames as $dummy => $varname) {
3222+ $value = $this->$varname;
3223+ $DebugOutput[] = '$this->'.str_pad($varname, 27, ' ', STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
3224+ }
3225+ $DebugOutput[] = 'strlen($this->rawImageData) = '.strlen(@$this->rawImageData);
3226+ $DebugOutput[] = 'strlen($this->exif_thumbnail_data) = '.strlen(@$this->exif_thumbnail_data);
3227+ $DebugOutput[] = '';
3228+
3229+ foreach ($ParameterNames as $dummy => $varname) {
3230+ $value = $this->$varname;
3231+ $DebugOutput[] = '$this->'.str_pad($varname, 4, ' ', STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
3232+ }
3233+ $DebugOutput[] = '';
3234+
3235+ foreach ($FunctionsExistance as $dummy => $functionname) {
3236+ $DebugOutput[] = 'builtin_function_exists('.$functionname.')'.str_repeat(' ', 23 - strlen($functionname)).' = '.$this->phpThumbDebugVarDump(phpthumb_functions::builtin_function_exists($functionname));
3237+ }
3238+ $DebugOutput[] = '';
3239+
3240+ $gd_info = gd_info();
3241+ foreach ($gd_info as $key => $value) {
3242+ $DebugOutput[] = 'gd_info.'.str_pad($key, 34, ' ', STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
3243+ }
3244+ $DebugOutput[] = '';
3245+
3246+ $exif_info = phpthumb_functions::exif_info();
3247+ foreach ($exif_info as $key => $value) {
3248+ $DebugOutput[] = 'exif_info.'.str_pad($key, 26, ' ', STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
3249+ }
3250+ $DebugOutput[] = '';
3251+
3252+ if ($ApacheLookupURIarray = phpthumb_functions::ApacheLookupURIarray(dirname(@$_SERVER['PHP_SELF']))) {
3253+ foreach ($ApacheLookupURIarray as $key => $value) {
3254+ $DebugOutput[] = 'ApacheLookupURIarray.'.str_pad($key, 15, ' ', STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
3255+ }
3256+ } else {
3257+ $DebugOutput[] = 'ApacheLookupURIarray() -- FAILED';
3258+ }
3259+ $DebugOutput[] = '';
3260+
3261+ if (isset($_GET) && is_array($_GET)) {
3262+ foreach ($_GET as $key => $value) {
3263+ $DebugOutput[] = '$_GET['.$key.']'.str_repeat(' ', 30 - strlen($key)).'= '.$this->phpThumbDebugVarDump($value);
3264+ }
3265+ }
3266+ if (isset($_POST) && is_array($_POST)) {
3267+ foreach ($_POST as $key => $value) {
3268+ $DebugOutput[] = '$_POST['.$key.']'.str_repeat(' ', 29 - strlen($key)).'= '.$this->phpThumbDebugVarDump($value);
3269+ }
3270+ }
3271+ $DebugOutput[] = '';
3272+
3273+ $DebugOutput[] = '$this->debugmessages:';
3274+ foreach ($this->debugmessages as $dummy => $errorstring) {
3275+ $DebugOutput[] = ' * '.$errorstring;
3276+ }
3277+ $DebugOutput[] = '';
3278+
3279+ $DebugOutput[] = '$this->debugtiming:';
3280+ foreach ($this->debugtiming as $timestamp => $timingstring) {
3281+ $DebugOutput[] = ' * '.$timestamp.' '.$timingstring;
3282+ }
3283+ $DebugOutput[] = ' * Total processing time: '.number_format(max(array_keys($this->debugtiming)) - min(array_keys($this->debugtiming)), 6);
3284+
3285+ return $this->ErrorImage(implode("\n", $DebugOutput), 700, 500, true);
3286+ }
3287+
3288+ function ErrorImage($text, $width=0, $height=0, $forcedisplay=false) {
3289+ $width = ($width ? $width : $this->config_error_image_width);
3290+ $height = ($height ? $height : $this->config_error_image_height);
3291+
3292+ $text = 'phpThumb() v'.$this->phpthumb_version."\n\n".$text;
3293+ if ($this->config_disable_debug) {
3294+ $text = 'Error messages disabled';
3295+ }
3296+
3297+ $this->DebugMessage($text, __FILE__, __LINE__);
3298+ if ($this->phpThumbDebug && !$forcedisplay) {
3299+ return false;
3300+ }
3301+ if (!$this->config_error_die_on_error && !$forcedisplay) {
3302+ $this->fatalerror = $text;
3303+ return false;
3304+ }
3305+ if ($this->config_error_silent_die_on_error) {
3306+ exit;
3307+ }
3308+ if ($this->err || $this->config_error_message_image_default) {
3309+ // Show generic custom error image instead of error message
3310+ // for use on production sites where you don't want debug messages
3311+ if ($this->err == 'showerror') {
3312+ // fall through and actually show error message even if default error image is set
3313+ } else {
3314+ header('Location: '.($this->err ? $this->err : $this->config_error_message_image_default));
3315+ exit;
3316+ }
3317+ }
3318+ $this->setOutputFormat();
3319+ if (!$this->thumbnailFormat || (phpthumb_functions::gd_version() < 1)) {
3320+ $this->thumbnailFormat = 'text';
3321+ }
3322+ if (@$this->thumbnailFormat == 'text') {
3323+ // bypass all GD functions and output text error message
3324+ die('<pre>'.$text.'</pre>');
3325+ }
3326+
3327+ $FontWidth = ImageFontWidth($this->config_error_fontsize);
3328+ $FontHeight = ImageFontHeight($this->config_error_fontsize);
3329+
3330+ $LinesOfText = explode("\n", @wordwrap($text, floor($width / $FontWidth), "\n", true));
3331+ $height = max($height, count($LinesOfText) * $FontHeight);
3332+
3333+ $headers_file = '';
3334+ $headers_line = '';
3335+ if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=') && headers_sent($headers_file, $headers_line)) {
3336+
3337+ echo "\n".'**Headers already sent in file "'.$headers_file.'" on line "'.$headers_line.'", dumping error message as text:**<br><pre>'."\n\n".$text."\n".'</pre>';
3338+
3339+ } elseif (headers_sent()) {
3340+
3341+ echo "\n".'**Headers already sent, dumping error message as text:**<br><pre>'."\n\n".$text."\n".'</pre>';
3342+
3343+ } elseif ($gdimg_error = ImageCreate($width, $height)) {
3344+
3345+ $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_bgcolor, true);
3346+ $text_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_textcolor, true);
3347+ ImageFilledRectangle($gdimg_error, 0, 0, $width, $height, $background_color);
3348+ $lineYoffset = 0;
3349+ foreach ($LinesOfText as $dummy => $line) {
3350+ ImageString($gdimg_error, $this->config_error_fontsize, 2, $lineYoffset, $line, $text_color);
3351+ $lineYoffset += $FontHeight;
3352+ }
3353+ if (function_exists('ImageTypes')) {
3354+ $imagetypes = ImageTypes();
3355+ if ($imagetypes & IMG_PNG) {
3356+ header('Content-Type: image/png');
3357+ ImagePNG($gdimg_error);
3358+ } elseif ($imagetypes & IMG_GIF) {
3359+ header('Content-Type: image/gif');
3360+ ImageGIF($gdimg_error);
3361+ } elseif ($imagetypes & IMG_JPG) {
3362+ header('Content-Type: image/jpeg');
3363+ ImageJPEG($gdimg_error);
3364+ } elseif ($imagetypes & IMG_WBMP) {
3365+ header('Content-Type: image/vnd.wap.wbmp');
3366+ ImageWBMP($gdimg_error);
3367+ }
3368+ }
3369+ ImageDestroy($gdimg_error);
3370+
3371+ }
3372+ if (!headers_sent()) {
3373+ echo "\n".'**Failed to send graphical error image, dumping error message as text:**<br>'."\n\n".$text;
3374+ }
3375+ exit;
3376+ return true;
3377+ }
3378+
3379+ function ImageCreateFromStringReplacement(&$RawImageData, $DieOnErrors=false) {
3380+ // there are serious bugs in the non-bundled versions of GD which may cause
3381+ // PHP to segfault when calling ImageCreateFromString() - avoid if at all possible
3382+ // when not using a bundled version of GD2
3383+ if (!phpthumb_functions::gd_version()) {
3384+ if ($DieOnErrors) {
3385+ if (!headers_sent()) {
3386+ // base64-encoded error image in GIF format
3387+ $ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7';
3388+ header('Content-Type: image/gif');
3389+ echo base64_decode($ERROR_NOGD);
3390+ } else {
3391+ echo '*** ERROR: No PHP-GD support available ***';
3392+ }
3393+ exit;
3394+ } else {
3395+ $this->DebugMessage('ImageCreateFromStringReplacement() failed: gd_version says "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
3396+ return false;
3397+ }
3398+ }
3399+ if (phpthumb_functions::gd_is_bundled()) {
3400+ $this->DebugMessage('ImageCreateFromStringReplacement() calling built-in ImageCreateFromString()', __FILE__, __LINE__);
3401+ return @ImageCreateFromString($RawImageData);
3402+ }
3403+ if (ini_get('safe_mode')) {
3404+ $this->DebugMessage('ImageCreateFromStringReplacement() failed: cannot create temp file in SAFE_MODE', __FILE__, __LINE__);
3405+ return false;
3406+ }
3407+
3408+ switch (substr($RawImageData, 0, 3)) {
3409+ case 'GIF':
3410+ $ICFSreplacementFunctionName = 'ImageCreateFromGIF';
3411+ break;
3412+ case "\xFF\xD8\xFF":
3413+ $ICFSreplacementFunctionName = 'ImageCreateFromJPEG';
3414+ break;
3415+ case "\x89".'PN':
3416+ $ICFSreplacementFunctionName = 'ImageCreateFromPNG';
3417+ break;
3418+ default:
3419+ $this->DebugMessage('ImageCreateFromStringReplacement() failed: unknown fileformat signature "'.phpthumb_functions::HexCharDisplay(substr($RawImageData, 0, 3)).'"', __FILE__, __LINE__);
3420+ return false;
3421+ break;
3422+ }
3423+ if ($tempnam = $this->phpThumb_tempnam()) {
3424+ if ($fp_tempnam = @fopen($tempnam, 'wb')) {
3425+ fwrite($fp_tempnam, $RawImageData);
3426+ fclose($fp_tempnam);
3427+ if (($ICFSreplacementFunctionName == 'ImageCreateFromGIF') && !function_exists($ICFSreplacementFunctionName)) {
3428+
3429+ // Need to create from GIF file, but ImageCreateFromGIF does not exist
3430+ ob_start();
3431+ if (!@include_once(dirname(__FILE__).'/phpthumb.gif.php')) {
3432+ $ErrorMessage = 'Failed to include required file "'.dirname(__FILE__).'/phpthumb.gif.php" in '.__FILE__.' on line '.__LINE__;
3433+ $this->DebugMessage($ErrorMessage, __FILE__, __LINE__);
3434+ }
3435+ ob_end_clean();
3436+ // gif_loadFileToGDimageResource() cannot read from raw data, write to file first
3437+ if ($tempfilename = $this->phpThumb_tempnam()) {
3438+ if ($fp_tempfile = @fopen($tempfilename, 'wb')) {
3439+ fwrite($fp_tempfile, $RawImageData);
3440+ fclose($fp_tempfile);
3441+ $gdimg_source = gif_loadFileToGDimageResource($tempfilename);
3442+ $this->DebugMessage('gif_loadFileToGDimageResource('.$tempfilename.') completed', __FILE__, __LINE__);
3443+ unlink($tempfilename);
3444+ return $gdimg_source;
3445+ break;
3446+ } else {
3447+ $ErrorMessage = 'Failed to open tempfile in '.__FILE__.' on line '.__LINE__;
3448+ $this->DebugMessage($ErrorMessage, __FILE__, __LINE__);
3449+ }
3450+ } else {
3451+ $ErrorMessage = 'Failed to open generate tempfile name in '.__FILE__.' on line '.__LINE__;
3452+ $this->DebugMessage($ErrorMessage, __FILE__, __LINE__);
3453+ }
3454+
3455+ } elseif (function_exists($ICFSreplacementFunctionName) && ($gdimg_source = @$ICFSreplacementFunctionName($tempnam))) {
3456+
3457+ // great
3458+ $this->DebugMessage($ICFSreplacementFunctionName.'('.$tempnam.') succeeded', __FILE__, __LINE__);
3459+ unlink($tempnam);
3460+ return $gdimg_source;
3461+
3462+ } else {
3463+
3464+ // GD functions not available, or failed to create image
3465+ $this->DebugMessage($ICFSreplacementFunctionName.'('.$tempnam.') '.(function_exists($ICFSreplacementFunctionName) ? 'failed' : 'does not exist'), __FILE__, __LINE__);
3466+ if (isset($_GET['phpThumbDebug'])) {
3467+ $this->phpThumbDebug();
3468+ }
3469+
3470+ }
3471+ } else {
3472+ $ErrorMessage = 'Failed to fopen('.$tempnam.', "wb") in '.__FILE__.' on line '.__LINE__."\n".'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php';
3473+ $this->DebugMessage($ErrorMessage, __FILE__, __LINE__);
3474+ }
3475+ @unlink($tempnam);
3476+ } else {
3477+ $ErrorMessage = 'Failed to generate phpThumb_tempnam() in '.__FILE__.' on line '.__LINE__."\n".'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php';
3478+ }
3479+ if ($DieOnErrors && $ErrorMessage) {
3480+ return $this->ErrorImage($ErrorMessage);
3481+ }
3482+ return false;
3483+ }
3484+
3485+ function ImageResizeFunction(&$dst_im, &$src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH) {
3486+ $this->DebugMessage('ImageResizeFunction($o, $s, '.$dstX.', '.$dstY.', '.$srcX.', '.$srcY.', '.$dstW.', '.$dstH.', '.$srcW.', '.$srcH.')', __FILE__, __LINE__);
3487+ if (phpthumb_functions::gd_version() >= 2.0) {
3488+ if ($this->config_disable_imagecopyresampled) {
3489+ return phpthumb_functions::ImageCopyResampleBicubic($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
3490+ }
3491+ return ImageCopyResampled($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
3492+ }
3493+ return ImageCopyResized($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
3494+ }
3495+
3496+ function phpThumb_tempnam() {
3497+ $tempnam = realpath(tempnam($this->config_temp_directory, 'pThumb'));
3498+ $this->DebugMessage('phpThumb_tempnam() returning "'.$tempnam.'"', __FILE__, __LINE__);
3499+ return $tempnam;
3500+ }
3501+
3502+ function DebugMessage($message, $file='', $line='') {
3503+ $this->debugmessages[] = $message.($file ? ' in file "'.(basename($file) ? basename($file) : $file).'"' : '').($line ? ' on line '.$line : '');
3504+ return true;
3505+ }
3506+
3507+ function DebugTimingMessage($message, $file='', $line='', $timestamp=0) {
3508+ if (!$timestamp) {
3509+ $timestamp = array_sum(explode(' ', microtime()));
3510+ }
3511+ $this->debugtiming[number_format($timestamp, 6, '.', '')] = ': '.$message.($file ? ' in file "'.(basename($file) ? basename($file) : $file).'"' : '').($line ? ' on line '.$line : '');
3512+ return true;
3513+ }
3514+
3515+}
3516+
3517+?>
--- /dev/null
+++ b/trunk/NP_TrimImage/sharedlibs/phpthumb/phpthumb.filters.php
@@ -0,0 +1,1359 @@
1+<?php
2+//////////////////////////////////////////////////////////////
3+/// phpThumb() by James Heinrich <info@silisoftware.com> //
4+// available at http://phpthumb.sourceforge.net ///
5+//////////////////////////////////////////////////////////////
6+/// //
7+// phpthumb.filters.php - image processing filter functions //
8+// ///
9+//////////////////////////////////////////////////////////////
10+
11+class phpthumb_filters {
12+
13+ var $phpThumbObject = null;
14+
15+ function phpthumb_filters() {
16+ return true;
17+ }
18+
19+ function ApplyMask(&$gdimg_mask, &$gdimg_image) {
20+ if (phpthumb_functions::gd_version() < 2) {
21+ $this->DebugMessage('Skipping ApplyMask() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
22+ return false;
23+ }
24+ if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
25+
26+ $this->DebugMessage('Using alpha ApplyMask() technique', __FILE__, __LINE__);
27+ if ($gdimg_mask_resized = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg_image), ImageSY($gdimg_image))) {
28+
29+ ImageCopyResampled($gdimg_mask_resized, $gdimg_mask, 0, 0, 0, 0, ImageSX($gdimg_image), ImageSY($gdimg_image), ImageSX($gdimg_mask), ImageSY($gdimg_mask));
30+ if ($gdimg_mask_blendtemp = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg_image), ImageSY($gdimg_image))) {
31+
32+ $color_background = ImageColorAllocate($gdimg_mask_blendtemp, 0, 0, 0);
33+ ImageFilledRectangle($gdimg_mask_blendtemp, 0, 0, ImageSX($gdimg_mask_blendtemp), ImageSY($gdimg_mask_blendtemp), $color_background);
34+ ImageAlphaBlending($gdimg_mask_blendtemp, false);
35+ ImageSaveAlpha($gdimg_mask_blendtemp, true);
36+ for ($x = 0; $x < ImageSX($gdimg_image); $x++) {
37+ for ($y = 0; $y < ImageSY($gdimg_image); $y++) {
38+ //$RealPixel = phpthumb_functions::GetPixelColor($gdimg_mask_blendtemp, $x, $y);
39+ $RealPixel = phpthumb_functions::GetPixelColor($gdimg_image, $x, $y);
40+ $MaskPixel = phpthumb_functions::GrayscalePixel(phpthumb_functions::GetPixelColor($gdimg_mask_resized, $x, $y));
41+ $MaskAlpha = 127 - (floor($MaskPixel['red'] / 2) * (1 - ($RealPixel['alpha'] / 127)));
42+ $newcolor = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg_mask_blendtemp, $RealPixel['red'], $RealPixel['green'], $RealPixel['blue'], $MaskAlpha);
43+ ImageSetPixel($gdimg_mask_blendtemp, $x, $y, $newcolor);
44+ }
45+ }
46+ ImageAlphaBlending($gdimg_image, false);
47+ ImageSaveAlpha($gdimg_image, true);
48+ ImageCopy($gdimg_image, $gdimg_mask_blendtemp, 0, 0, 0, 0, ImageSX($gdimg_mask_blendtemp), ImageSY($gdimg_mask_blendtemp));
49+ ImageDestroy($gdimg_mask_blendtemp);
50+
51+ } else {
52+ $this->DebugMessage('ImageCreateFunction() failed', __FILE__, __LINE__);
53+ }
54+ ImageDestroy($gdimg_mask_resized);
55+
56+ } else {
57+ $this->DebugMessage('ImageCreateFunction() failed', __FILE__, __LINE__);
58+ }
59+
60+ } else {
61+ // alpha merging requires PHP v4.3.2+
62+ $this->DebugMessage('Skipping ApplyMask() technique because PHP is v"'.phpversion().'"', __FILE__, __LINE__);
63+ }
64+ return true;
65+ }
66+
67+
68+ function Bevel(&$gdimg, $width, $hexcolor1, $hexcolor2) {
69+ $width = ($width ? $width : 5);
70+ $hexcolor1 = ($hexcolor1 ? $hexcolor1 : 'FFFFFF');
71+ $hexcolor2 = ($hexcolor2 ? $hexcolor2 : '000000');
72+
73+ ImageAlphaBlending($gdimg, true);
74+ for ($i = 0; $i < $width; $i++) {
75+ $alpha = round(($i / $width) * 127);
76+ $color1[$i] = phpthumb_functions::ImageHexColorAllocate($gdimg, $hexcolor1, false, $alpha);
77+ $color2[$i] = phpthumb_functions::ImageHexColorAllocate($gdimg, $hexcolor2, false, $alpha);
78+
79+ ImageLine($gdimg, $i, $i, $i, ImageSY($gdimg) - $i, $color1[$i]); // left
80+ ImageLine($gdimg, $i, $i, ImageSX($gdimg) - $i, $i, $color1[$i]); // top
81+ ImageLine($gdimg, ImageSX($gdimg) - $i, ImageSY($gdimg) - $i, ImageSX($gdimg) - $i, $i, $color2[$i]); // right
82+ ImageLine($gdimg, ImageSX($gdimg) - $i, ImageSY($gdimg) - $i, $i, ImageSY($gdimg) - $i, $color2[$i]); // bottom
83+ }
84+ return true;
85+ }
86+
87+
88+ function Blur(&$gdimg, $radius=0.5) {
89+ // Taken from Torstein H?si's phpUnsharpMask (see phpthumb.unsharp.php)
90+
91+ $radius = round(max(0, min($radius, 50)) * 2);
92+ if (!$radius) {
93+ return false;
94+ }
95+
96+ $w = ImageSX($gdimg);
97+ $h = ImageSY($gdimg);
98+ if ($imgBlur = ImageCreateTrueColor($w, $h)) {
99+ // Gaussian blur matrix:
100+ // 1 2 1
101+ // 2 4 2
102+ // 1 2 1
103+
104+ // Move copies of the image around one pixel at the time and merge them with weight
105+ // according to the matrix. The same matrix is simply repeated for higher radii.
106+ for ($i = 0; $i < $radius; $i++) {
107+ ImageCopy ($imgBlur, $gdimg, 0, 0, 1, 1, $w - 1, $h - 1); // up left
108+ ImageCopyMerge($imgBlur, $gdimg, 1, 1, 0, 0, $w, $h, 50.00000); // down right
109+ ImageCopyMerge($imgBlur, $gdimg, 0, 1, 1, 0, $w - 1, $h, 33.33333); // down left
110+ ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 1, $w, $h - 1, 25.00000); // up right
111+ ImageCopyMerge($imgBlur, $gdimg, 0, 0, 1, 0, $w - 1, $h, 33.33333); // left
112+ ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 0, $w, $h, 25.00000); // right
113+ ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 1, $w, $h - 1, 20.00000); // up
114+ ImageCopyMerge($imgBlur, $gdimg, 0, 1, 0, 0, $w, $h, 16.666667); // down
115+ ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 0, $w, $h, 50.000000); // center
116+ ImageCopy ($gdimg, $imgBlur, 0, 0, 0, 0, $w, $h);
117+ }
118+ return true;
119+ }
120+ return false;
121+ }
122+
123+
124+ function BlurGaussian(&$gdimg) {
125+ if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
126+ if (ImageFilter($gdimg, IMG_FILTER_GAUSSIAN_BLUR)) {
127+ return true;
128+ }
129+ $this->DebugMessage('FAILED: ImageFilter($gdimg, IMG_FILTER_GAUSSIAN_BLUR)', __FILE__, __LINE__);
130+ // fall through and try it the hard way
131+ }
132+ $this->DebugMessage('FAILED: phpthumb_filters::BlurGaussian($gdimg) [using phpthumb_filters::Blur() instead]', __FILE__, __LINE__);
133+ return phpthumb_filters::Blur($gdimg, 0.5);
134+ }
135+
136+
137+ function BlurSelective(&$gdimg) {
138+ if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
139+ if (ImageFilter($gdimg, IMG_FILTER_SELECTIVE_BLUR)) {
140+ return true;
141+ }
142+ $this->DebugMessage('FAILED: ImageFilter($gdimg, IMG_FILTER_SELECTIVE_BLUR)', __FILE__, __LINE__);
143+ // fall through and try it the hard way
144+ }
145+ // currently not implemented "the hard way"
146+ $this->DebugMessage('FAILED: phpthumb_filters::BlurSelective($gdimg) [function not implemented]', __FILE__, __LINE__);
147+ return false;
148+ }
149+
150+
151+ function Brightness(&$gdimg, $amount=0) {
152+ if ($amount == 0) {
153+ return true;
154+ }
155+ $amount = max(-255, min(255, $amount));
156+
157+ if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
158+ if (ImageFilter($gdimg, IMG_FILTER_BRIGHTNESS, $amount)) {
159+ return true;
160+ }
161+ $this->DebugMessage('FAILED: ImageFilter($gdimg, IMG_FILTER_BRIGHTNESS, '.$amount.')', __FILE__, __LINE__);
162+ // fall through and try it the hard way
163+ }
164+
165+ $scaling = (255 - abs($amount)) / 255;
166+ $baseamount = (($amount > 0) ? $amount : 0);
167+ for ($x = 0; $x < ImageSX($gdimg); $x++) {
168+ for ($y = 0; $y < ImageSY($gdimg); $y++) {
169+ $OriginalPixel = phpthumb_functions::GetPixelColor($gdimg, $x, $y);
170+ foreach ($OriginalPixel as $key => $value) {
171+ $NewPixel[$key] = round($baseamount + ($OriginalPixel[$key] * $scaling));
172+ }
173+ $newColor = ImageColorAllocate($gdimg, $NewPixel['red'], $NewPixel['green'], $NewPixel['blue']);
174+ ImageSetPixel($gdimg, $x, $y, $newColor);
175+ }
176+ }
177+ return true;
178+ }
179+
180+
181+ function Contrast(&$gdimg, $amount=0) {
182+ if ($amount == 0) {
183+ return true;
184+ }
185+ $amount = max(-255, min(255, $amount));
186+
187+ if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
188+ if (ImageFilter($gdimg, IMG_FILTER_CONTRAST, $amount)) {
189+ return true;
190+ }
191+ $this->DebugMessage('FAILED: ImageFilter($gdimg, IMG_FILTER_CONTRAST, '.$amount.')', __FILE__, __LINE__);
192+ // fall through and try it the hard way
193+ }
194+
195+ if ($amount > 0) {
196+ $scaling = 1 + ($amount / 255);
197+ } else {
198+ $scaling = (255 - abs($amount)) / 255;
199+ }
200+ for ($x = 0; $x < ImageSX($gdimg); $x++) {
201+ for ($y = 0; $y < ImageSY($gdimg); $y++) {
202+ $OriginalPixel = phpthumb_functions::GetPixelColor($gdimg, $x, $y);
203+ foreach ($OriginalPixel as $key => $value) {
204+ $NewPixel[$key] = min(255, max(0, round($OriginalPixel[$key] * $scaling)));
205+ }
206+ $newColor = ImageColorAllocate($gdimg, $NewPixel['red'], $NewPixel['green'], $NewPixel['blue']);
207+ ImageSetPixel($gdimg, $x, $y, $newColor);
208+ }
209+ }
210+ }
211+
212+
213+ function Colorize(&$gdimg, $amount, $targetColor) {
214+ $amount = (is_numeric($amount) ? $amount : 25);
215+ $targetColor = (phpthumb_functions::IsHexColor($targetColor) ? $targetColor : 'gray');
216+
217+ if ($amount == 0) {
218+ return true;
219+ }
220+
221+ if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
222+ if ($targetColor == 'gray') {
223+ $targetColor = '808080';
224+ }
225+ $r = substr($targetColor, 0, 2);
226+ $g = substr($targetColor, 2, 2);
227+ $b = substr($targetColor, 4, 2);
228+ if (ImageFilter($gdimg, IMG_FILTER_COLORIZE, $r, $g, $b)) {
229+ return true;
230+ }
231+ $this->DebugMessage('FAILED: ImageFilter($gdimg, IMG_FILTER_COLORIZE)', __FILE__, __LINE__);
232+ // fall through and try it the hard way
233+ }
234+
235+ // overridden below for grayscale
236+ if ($targetColor != 'gray') {
237+ $TargetPixel['red'] = hexdec(substr($targetColor, 0, 2));
238+ $TargetPixel['green'] = hexdec(substr($targetColor, 2, 2));
239+ $TargetPixel['blue'] = hexdec(substr($targetColor, 4, 2));
240+ }
241+
242+ for ($x = 0; $x < ImageSX($gdimg); $x++) {
243+ for ($y = 0; $y < ImageSY($gdimg); $y++) {
244+ $OriginalPixel = phpthumb_functions::GetPixelColor($gdimg, $x, $y);
245+ if ($targetColor == 'gray') {
246+ $TargetPixel = phpthumb_functions::GrayscalePixel($OriginalPixel);
247+ }
248+ foreach ($TargetPixel as $key => $value) {
249+ $NewPixel[$key] = round(max(0, min(255, ($OriginalPixel[$key] * ((100 - $amount) / 100)) + ($TargetPixel[$key] * ($amount / 100)))));
250+ }
251+ //$newColor = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg, $NewPixel['red'], $NewPixel['green'], $NewPixel['blue'], $OriginalPixel['alpha']);
252+ $newColor = ImageColorAllocate($gdimg, $NewPixel['red'], $NewPixel['green'], $NewPixel['blue']);
253+ ImageSetPixel($gdimg, $x, $y, $newColor);
254+ }
255+ }
256+ return true;
257+ }
258+
259+
260+ function Crop(&$gdimg, $left=0, $right=0, $top=0, $bottom=0) {
261+ if (!$left && !$right && !$top && !$bottom) {
262+ return true;
263+ }
264+ $oldW = ImageSX($gdimg);
265+ $oldH = ImageSY($gdimg);
266+ if (($left > 0) && ($left < 1)) { $left = round($left * $oldW); }
267+ if (($right > 0) && ($right < 1)) { $right = round($right * $oldW); }
268+ if (($top > 0) && ($top < 1)) { $top = round($top * $oldH); }
269+ if (($bottom > 0) && ($bottom < 1)) { $bottom = round($bottom * $oldH); }
270+ $right = min($oldW - $left - 1, $right);
271+ $bottom = min($oldH - $top - 1, $bottom);
272+ $newW = $oldW - $left - $right;
273+ $newH = $oldH - $top - $bottom;
274+
275+ if ($imgCropped = ImageCreateTrueColor($newW, $newH)) {
276+ ImageCopy($imgCropped, $gdimg, 0, 0, $left, $top, $newW, $newH);
277+ if ($gdimg = ImageCreateTrueColor($newW, $newH)) {
278+ ImageCopy($gdimg, $imgCropped, 0, 0, 0, 0, $newW, $newH);
279+ ImageDestroy($imgCropped);
280+ return true;
281+ }
282+ ImageDestroy($imgCropped);
283+ }
284+ return false;
285+ }
286+
287+
288+ function Desaturate(&$gdimg, $amount, $color='') {
289+ if ($amount == 0) {
290+ return true;
291+ }
292+ return phpthumb_filters::Colorize($gdimg, $amount, (phpthumb_functions::IsHexColor($color) ? $color : 'gray'));
293+ }
294+
295+
296+ function DropShadow(&$gdimg, $distance, $width, $hexcolor, $angle, $fade) {
297+ if (phpthumb_functions::gd_version() < 2) {
298+ return false;
299+ }
300+ $distance = ($distance ? $distance : 10);
301+ $width = ($width ? $width : 10);
302+ $hexcolor = ($hexcolor ? $hexcolor : '000000');
303+ $angle = ($angle ? $angle : 225);
304+ $fade = ($fade ? $fade : 1);
305+
306+ $width_shadow = cos(deg2rad($angle)) * ($distance + $width);
307+ $height_shadow = sin(deg2rad($angle)) * ($distance + $width);
308+
309+ $scaling = min(ImageSX($gdimg) / (ImageSX($gdimg) + abs($width_shadow)), ImageSY($gdimg) / (ImageSY($gdimg) + abs($height_shadow)));
310+
311+ for ($i = 0; $i < $width; $i++) {
312+ $WidthAlpha[$i] = (abs(($width / 2) - $i) / $width) * $fade;
313+ $Offset['x'] = cos(deg2rad($angle)) * ($distance + $i);
314+ $Offset['y'] = sin(deg2rad($angle)) * ($distance + $i);
315+ }
316+
317+ $tempImageWidth = ImageSX($gdimg) + abs($Offset['x']);
318+ $tempImageHeight = ImageSY($gdimg) + abs($Offset['y']);
319+
320+ if ($gdimg_dropshadow_temp = phpthumb_functions::ImageCreateFunction($tempImageWidth, $tempImageHeight)) {
321+
322+ ImageAlphaBlending($gdimg_dropshadow_temp, false);
323+ ImageSaveAlpha($gdimg_dropshadow_temp, true);
324+ $transparent1 = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg_dropshadow_temp, 0, 0, 0, 127);
325+ ImageFill($gdimg_dropshadow_temp, 0, 0, $transparent1);
326+
327+ for ($x = 0; $x < ImageSX($gdimg); $x++) {
328+ for ($y = 0; $y < ImageSY($gdimg); $y++) {
329+ $PixelMap[$x][$y] = phpthumb_functions::GetPixelColor($gdimg, $x, $y);
330+ }
331+ }
332+ for ($x = 0; $x < $tempImageWidth; $x++) {
333+ for ($y = 0; $y < $tempImageHeight; $y++) {
334+ //for ($i = 0; $i < $width; $i++) {
335+ for ($i = 0; $i < 1; $i++) {
336+ if (!isset($PixelMap[$x][$y]['alpha']) || ($PixelMap[$x][$y]['alpha'] > 0)) {
337+ if (isset($PixelMap[$x + $Offset['x']][$y + $Offset['y']]['alpha']) && ($PixelMap[$x + $Offset['x']][$y + $Offset['y']]['alpha'] < 127)) {
338+ $thisColor = phpthumb_functions::ImageHexColorAllocate($gdimg, $hexcolor, false, $PixelMap[$x + $Offset['x']][$y + $Offset['y']]['alpha']);
339+ ImageSetPixel($gdimg_dropshadow_temp, $x, $y, $thisColor);
340+ }
341+ }
342+ }
343+ }
344+ }
345+
346+ ImageAlphaBlending($gdimg_dropshadow_temp, true);
347+ for ($x = 0; $x < ImageSX($gdimg); $x++) {
348+ for ($y = 0; $y < ImageSY($gdimg); $y++) {
349+ if ($PixelMap[$x][$y]['alpha'] < 127) {
350+ $thisColor = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg_dropshadow_temp, $PixelMap[$x][$y]['red'], $PixelMap[$x][$y]['green'], $PixelMap[$x][$y]['blue'], $PixelMap[$x][$y]['alpha']);
351+ ImageSetPixel($gdimg_dropshadow_temp, $x, $y, $thisColor);
352+ }
353+ }
354+ }
355+
356+ ImageSaveAlpha($gdimg, true);
357+ ImageAlphaBlending($gdimg, false);
358+ //$this->is_alpha = true;
359+ $transparent2 = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg, 0, 0, 0, 127);
360+ ImageFilledRectangle($gdimg, 0, 0, ImageSX($gdimg), ImageSY($gdimg), $transparent2);
361+ ImageCopyResampled($gdimg, $gdimg_dropshadow_temp, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg), ImageSX($gdimg_dropshadow_temp), ImageSY($gdimg_dropshadow_temp));
362+
363+ ImageDestroy($gdimg_dropshadow_temp);
364+ }
365+ return true;
366+ }
367+
368+
369+ function EdgeDetect(&$gdimg) {
370+ if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
371+ if (ImageFilter($gdimg, IMG_FILTER_EDGEDETECT)) {
372+ return true;
373+ }
374+ $this->DebugMessage('FAILED: ImageFilter($gdimg, IMG_FILTER_EDGEDETECT)', __FILE__, __LINE__);
375+ // fall through and try it the hard way
376+ }
377+ // currently not implemented "the hard way"
378+ $this->DebugMessage('FAILED: phpthumb_filters::EdgeDetect($gdimg) [function not implemented]', __FILE__, __LINE__);
379+ return false;
380+ }
381+
382+
383+ function Elipse($gdimg) {
384+ if (phpthumb_functions::gd_version() < 2) {
385+ return false;
386+ }
387+ // generate mask at twice desired resolution and downsample afterwards for easy antialiasing
388+ if ($gdimg_elipsemask_double = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg) * 2, ImageSY($gdimg) * 2)) {
389+ if ($gdimg_elipsemask = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg), ImageSY($gdimg))) {
390+
391+ $color_transparent = ImageColorAllocate($gdimg_elipsemask_double, 255, 255, 255);
392+ ImageFilledEllipse($gdimg_elipsemask_double, ImageSX($gdimg), ImageSY($gdimg), (ImageSX($gdimg) - 1) * 2, (ImageSY($gdimg) - 1) * 2, $color_transparent);
393+ ImageCopyResampled($gdimg_elipsemask, $gdimg_elipsemask_double, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg), ImageSX($gdimg) * 2, ImageSY($gdimg) * 2);
394+
395+ phpthumb_filters::ApplyMask($gdimg_elipsemask, $gdimg);
396+ ImageDestroy($gdimg_elipsemask);
397+ return true;
398+
399+ } else {
400+ $this->DebugMessage('$gdimg_elipsemask = phpthumb_functions::ImageCreateFunction() failed', __FILE__, __LINE__);
401+ }
402+ ImageDestroy($gdimg_elipsemask_double);
403+ } else {
404+ $this->DebugMessage('$gdimg_elipsemask_double = phpthumb_functions::ImageCreateFunction() failed', __FILE__, __LINE__);
405+ }
406+ return false;
407+ }
408+
409+
410+ function Emboss(&$gdimg) {
411+ if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
412+ if (ImageFilter($gdimg, IMG_FILTER_EMBOSS)) {
413+ return true;
414+ }
415+ $this->DebugMessage('FAILED: ImageFilter($gdimg, IMG_FILTER_EMBOSS)', __FILE__, __LINE__);
416+ // fall through and try it the hard way
417+ }
418+ // currently not implemented "the hard way"
419+ $this->DebugMessage('FAILED: phpthumb_filters::Emboss($gdimg) [function not implemented]', __FILE__, __LINE__);
420+ return false;
421+ }
422+
423+
424+ function Flip(&$gdimg, $x=false, $y=false) {
425+ if (!$x && !$y) {
426+ return false;
427+ }
428+ if ($tempImage = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg), ImageSY($gdimg))) {
429+ if ($x) {
430+ ImageCopy($tempImage, $gdimg, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg));
431+ for ($x = 0; $x < ImageSX($gdimg); $x++) {
432+ ImageCopy($gdimg, $tempImage, ImageSX($gdimg) - 1 - $x, 0, $x, 0, 1, ImageSY($gdimg));
433+ }
434+ }
435+ if ($y) {
436+ ImageCopy($tempImage, $gdimg, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg));
437+ for ($y = 0; $y < ImageSY($gdimg); $y++) {
438+ ImageCopy($gdimg, $tempImage, 0, ImageSY($gdimg) - 1 - $y, 0, $y, ImageSX($gdimg), 1);
439+ }
440+ }
441+ ImageDestroy($tempImage);
442+ }
443+ return true;
444+ }
445+
446+
447+ function Frame(&$gdimg, $frame_width, $edge_width, $hexcolor_frame, $hexcolor1, $hexcolor2) {
448+ $frame_width = ($frame_width ? $frame_width : 5);
449+ $edge_width = ($edge_width ? $edge_width : 1);
450+ $hexcolor_frame = ($hexcolor_frame ? $hexcolor_frame : 'CCCCCC');
451+ $hexcolor1 = ($hexcolor1 ? $hexcolor1 : 'FFFFFF');
452+ $hexcolor2 = ($hexcolor2 ? $hexcolor2 : '000000');
453+
454+ $color_frame = phpthumb_functions::ImageHexColorAllocate($gdimg, $hexcolor_frame);
455+ $color1 = phpthumb_functions::ImageHexColorAllocate($gdimg, $hexcolor1);
456+ $color2 = phpthumb_functions::ImageHexColorAllocate($gdimg, $hexcolor2);
457+ for ($i = 0; $i < $edge_width; $i++) {
458+ // outer bevel
459+ ImageLine($gdimg, $i, $i, $i, ImageSY($gdimg) - $i, $color1); // left
460+ ImageLine($gdimg, $i, $i, ImageSX($gdimg) - $i, $i, $color1); // top
461+ ImageLine($gdimg, ImageSX($gdimg) - $i, ImageSY($gdimg) - $i, ImageSX($gdimg) - $i, $i, $color2); // right
462+ ImageLine($gdimg, ImageSX($gdimg) - $i, ImageSY($gdimg) - $i, $i, ImageSY($gdimg) - $i, $color2); // bottom
463+ }
464+ for ($i = 0; $i < $frame_width; $i++) {
465+ // actual frame
466+ ImageRectangle($gdimg, $edge_width + $i, $edge_width + $i, ImageSX($gdimg) - $edge_width - $i, ImageSY($gdimg) - $edge_width - $i, $color_frame);
467+ }
468+ for ($i = 0; $i < $edge_width; $i++) {
469+ // inner bevel
470+ ImageLine($gdimg, $frame_width + $edge_width + $i, $frame_width + $edge_width + $i, $frame_width + $edge_width + $i, ImageSY($gdimg) - $frame_width - $edge_width - $i, $color2); // left
471+ ImageLine($gdimg, $frame_width + $edge_width + $i, $frame_width + $edge_width + $i, ImageSX($gdimg) - $frame_width - $edge_width - $i, $frame_width + $edge_width + $i, $color2); // top
472+ ImageLine($gdimg, ImageSX($gdimg) - $frame_width - $edge_width - $i, ImageSY($gdimg) - $frame_width - $edge_width - $i, ImageSX($gdimg) - $frame_width - $edge_width - $i, $frame_width + $edge_width + $i, $color1); // right
473+ ImageLine($gdimg, ImageSX($gdimg) - $frame_width - $edge_width - $i, ImageSY($gdimg) - $frame_width - $edge_width - $i, $frame_width + $edge_width + $i, ImageSY($gdimg) - $frame_width - $edge_width - $i, $color1); // bottom
474+ }
475+ return true;
476+ }
477+
478+
479+ function Gamma(&$gdimg, $amount) {
480+ if (number_format($amount, 4) == '1.0000') {
481+ return true;
482+ }
483+ return ImageGammaCorrect($gdimg, 1.0, $amount);
484+ }
485+
486+
487+ function Grayscale(&$gdimg) {
488+ if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
489+ if (ImageFilter($gdimg, IMG_FILTER_GRAYSCALE)) {
490+ return true;
491+ }
492+ $this->DebugMessage('FAILED: ImageFilter($gdimg, IMG_FILTER_GRAYSCALE)', __FILE__, __LINE__);
493+ // fall through and try it the hard way
494+ }
495+ return phpthumb_filters::Colorize($gdimg, 100, 'gray');
496+ }
497+
498+
499+ function HistogramAnalysis(&$gdimg, $calculateGray=false) {
500+ $ImageSX = ImageSX($gdimg);
501+ $ImageSY = ImageSY($gdimg);
502+ for ($x = 0; $x < $ImageSX; $x++) {
503+ for ($y = 0; $y < $ImageSY; $y++) {
504+ $OriginalPixel = phpthumb_functions::GetPixelColor($gdimg, $x, $y);
505+ @$Analysis['red'][$OriginalPixel['red']]++;
506+ @$Analysis['green'][$OriginalPixel['green']]++;
507+ @$Analysis['blue'][$OriginalPixel['blue']]++;
508+ @$Analysis['alpha'][$OriginalPixel['alpha']]++;
509+ if ($calculateGray) {
510+ $GrayPixel = phpthumb_functions::GrayscalePixel($OriginalPixel);
511+ @$Analysis['gray'][$GrayPixel['red']]++;
512+ }
513+ }
514+ }
515+ $keys = array('red', 'green', 'blue', 'alpha');
516+ if ($calculateGray) {
517+ $keys[] = 'gray';
518+ }
519+ foreach ($keys as $dummy => $key) {
520+ ksort($Analysis[$key]);
521+ }
522+ return $Analysis;
523+ }
524+
525+
526+ function HistogramStretch(&$gdimg, $band='*', $min=-1, $max=-1) {
527+ // equivalent of "Auto Contrast" in Adobe Photoshop
528+
529+ $Analysis = phpthumb_filters::HistogramAnalysis($gdimg, true);
530+ $keys = array('r'=>'red', 'g'=>'green', 'b'=>'blue', 'a'=>'alpha', '*'=>'gray');
531+ if (!isset($keys[$band])) {
532+ return false;
533+ }
534+ $key = $keys[$band];
535+
536+ // If the absolute brightest and darkest pixels are used then one random
537+ // pixel in the image could throw off the whole system. Instead, count up/down
538+ // from the limit and allow 0.1% of brightest/darkest pixels to be clipped to min/max
539+ $clip_threshold = ImageSX($gdimg) * ImageSX($gdimg) * 0.001;
540+ if ($min >= 0) {
541+ $range_min = min($min, 255);
542+ } else {
543+ $countsum = 0;
544+ for ($i = 0; $i <= 255; $i++) {
545+ $countsum += @$Analysis[$key][$i];
546+ if ($countsum >= $clip_threshold) {
547+ $range_min = $i - 1;
548+ break;
549+ }
550+ }
551+ $range_min = max($range_min, 0);
552+ }
553+ if ($max >= 0) {
554+ $range_max = max($max, 255);
555+ } else {
556+ $countsum = 0;
557+ $threshold = ImageSX($gdimg) * ImageSX($gdimg) * 0.001; // 0.1% of brightest and darkest pixels can be clipped
558+ for ($i = 255; $i >= 0; $i--) {