00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00055
00056
00057
00058 error_reporting (E_ALL ^ E_NOTICE);
00059
00060
00061
00062
00063
00064
00065 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
00066 define('TYPO3_MODE','BE');
00067 define('PATH_thisScript',str_replace('
00068
00069 define('PATH_site', ereg_replace('[^/]*.[^/]*$','',PATH_thisScript));
00070 define('PATH_typo3conf', PATH_site.'typo3conf/');
00071 define('PATH_t3lib', PATH_site.'t3lib/');
00072 define('TYPO3_mainDir', 'typo3/');
00073
00074
00075
00076
00077 require(PATH_t3lib.'class.t3lib_div.php');
00078 require(PATH_t3lib.'class.t3lib_extmgm.php');
00079
00080 require(PATH_t3lib.'config_default.php');
00081 if (!defined ('TYPO3_db')) die ('The configuration file was not included.');
00082 if (!$TYPO3_CONF_VARS['GFX']['image_processing']) die ('ImageProcessing was disabled!');
00083
00084 require(PATH_t3lib.'class.t3lib_db.php');
00085 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00114 class SC_t3lib_thumbs {
00115 var $include_once=array();
00116
00117 var $outdir = 'typo3temp/';
00118 var $output = '';
00119 var $sizeDefault='56x56';
00120
00121 var $imageList;
00122 var $input;
00123
00124
00125 var $file;
00126 var $size;
00127
00128
00135 function init() {
00136 global $TYPO3_CONF_VARS;
00137
00138
00139 $this->file = t3lib_div::_GP('file');
00140 $this->size = t3lib_div::_GP('size');
00141
00142
00143 $this->imageList = $TYPO3_CONF_VARS['GFX']['imagefile_ext'];
00144
00145
00146 if (substr($this->file,0,3)=='../') {
00147 $this->input = PATH_site.ereg_replace('^\.\./','',$this->file);
00148 } else {
00149 $this->input = $this->file;
00150 }
00151
00152
00153
00154 if (!t3lib_div::isAllowedAbsPath($this->input)) {
00155 $this->input='';
00156 }
00157 }
00158
00165 function main() {
00166 global $TYPO3_CONF_VARS;
00167
00168
00169 if ($this->input && @file_exists($this->input)) {
00170
00171
00172 if (ereg('(.*)\.([^\.]*$)',$this->input,$reg)) {
00173 $ext=strtolower($reg[2]);
00174 $ext=($ext=='jpeg')?'jpg':$ext;
00175 if ($ext=='ttf') {
00176 $this->fontGif($this->input);
00177 } elseif (!t3lib_div::inList($this->imageList, $ext)) {
00178 $this->errorGif('Not imagefile!',$ext,$this->input);
00179 }
00180 } else {
00181 $this->errorGif('Not imagefile!','No ext!',$this->input);
00182 }
00183
00184
00185 $this->size = $this->size ? $this->size : $this->sizeDefault;
00186
00187
00188 $sizeParts = explode('x', $this->size.'x'.$this->size);
00189 $sizeParts = array(t3lib_div::intInRange($sizeParts[0],1,1000),t3lib_div::intInRange($sizeParts[1],1,1000));
00190 $this->size = implode('x',$sizeParts);
00191 $sizeMax = max($sizeParts);
00192
00193
00194 $mtime = filemtime($this->input);
00195 $outpath = PATH_site.$this->outdir;
00196
00197
00198
00199 $thmMode = t3lib_div::intInRange($TYPO3_CONF_VARS['GFX']['thumbnails_png'],0);
00200 $outext = ($ext!='jpg' || ($thmMode & 2)) ? ($thmMode & 1 ? 'png' : 'gif') : 'jpg';
00201
00202 $outfile = 'tmb_'.substr(md5($this->input.$mtime.$this->size),0,10).'.'.$outext;
00203 $this->output = $outpath.$outfile;
00204
00205 if ($TYPO3_CONF_VARS['GFX']['im']) {
00206
00207 if (!@file_exists($this->output)) {
00208
00209
00210
00211
00212 if ($outext=='jpg') {
00213 $colors = '';
00214 } else {
00215 $colors = ($sizeMax>56)?'-colors 64':'-colors 16';
00216 }
00217 $cmd = ($TYPO3_CONF_VARS['GFX']['im_path_lzw'] ? $TYPO3_CONF_VARS['GFX']['im_path_lzw'] : $TYPO3_CONF_VARS['GFX']['im_path']).
00218 'convert -sample '.$this->size.' '.$colors.' '.$this->wrapFileName($this->input.'[0]').' '.$this->wrapFileName($this->output);
00219
00220
00221 exec($cmd);
00222 if (!@file_exists($this->output)) {
00223 $this->errorGif('No thumb','generated!',$this->input);
00224 }
00225 }
00226
00227 if($fd = @fopen($this->output,'rb')) {
00228 Header('Content-type: image/'.$outext);
00229 while (!feof($fd)) {
00230 echo fread( $fd, 10000 );
00231 }
00232 fclose( $fd );
00233 } else {
00234 $this->errorGif('Read problem!','',$this->output);
00235 }
00236 } else exit;
00237 } else {
00238 $this->errorGif('No valid','inputfile!',$this->input);
00239 }
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00268 function errorGif($l1,$l2,$l3) {
00269 global $TYPO3_CONF_VARS;
00270
00271 if (!$TYPO3_CONF_VARS['GFX']['gdlib']) die($l1.' '.$l2.' '.$l3);
00272
00273
00274 if ($TYPO3_CONF_VARS['GFX']['gdlib_png']) {
00275 Header('Content-type: image/png');
00276 $im = imagecreatefrompng(PATH_t3lib.'gfx/notfound_thumb.png');
00277 } else {
00278 Header('Content-type: image/gif');
00279 $im = imagecreatefromgif(PATH_t3lib.'gfx/notfound_thumb.gif');
00280 }
00281
00282 $white = ImageColorAllocate($im, 0,0,0);
00283 $black = ImageColorAllocate($im, 255,255,0);
00284
00285
00286 $x=0;
00287 $font=0;
00288 if ($l1) {
00289 imagefilledrectangle($im, $x, 9, 56, 16, $black);
00290 ImageString($im,$font,$x,9,$l1,$white);
00291 }
00292 if ($l2) {
00293 imagefilledrectangle($im, $x, 19, 56, 26, $black);
00294 ImageString($im,$font,$x,19,$l2,$white);
00295 }
00296 if ($l3) {
00297 imagefilledrectangle($im, $x, 29, 56, 36, $black);
00298 ImageString($im,$font,$x,29,substr($l3,-14),$white);
00299 }
00300
00301
00302 if ($TYPO3_CONF_VARS['GFX']['gdlib_png']) {
00303 imagePng($im);
00304 } else {
00305 imageGif($im);
00306 }
00307 imagedestroy($im);
00308 exit;
00309 }
00310
00320 function fontGif($font) {
00321 global $TYPO3_CONF_VARS;
00322
00323 if (!$TYPO3_CONF_VARS['GFX']['gdlib']) die('');
00324
00325
00326 $im = ImageCreate(250,76);
00327 $white = ImageColorAllocate($im, 255,255,255);
00328 $col = ImageColorAllocate($im, 0,0,0);
00329
00330
00331 $string = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzÆæØøÅåÄäÖöÜüß';
00332 $x=13;
00333
00334
00335 imagestring ($im, 1, 0, 2, '10', $col);
00336 imagestring ($im, 1, 0, 15, '12', $col);
00337 imagestring ($im, 1, 0, 30, '14', $col);
00338 imagestring ($im, 1, 0, 47, '18', $col);
00339 imagestring ($im, 1, 0, 68, '24', $col);
00340
00341
00342 imagettftext ($im, t3lib_div::freetypeDpiComp(10), 0, $x, 8, $col, $font, $string);
00343 imagettftext ($im, t3lib_div::freetypeDpiComp(12), 0, $x, 21, $col, $font, $string);
00344 imagettftext ($im, t3lib_div::freetypeDpiComp(14), 0, $x, 36, $col, $font, $string);
00345 imagettftext ($im, t3lib_div::freetypeDpiComp(18), 0, $x, 53, $col, $font, $string);
00346 imagettftext ($im, t3lib_div::freetypeDpiComp(24), 0, $x, 74, $col, $font, $string);
00347
00348
00349 if ($TYPO3_CONF_VARS['GFX']['gdlib_png']) {
00350 Header('Content-type: image/png');
00351 imagePng($im);
00352 } else {
00353 Header('Content-type: image/gif');
00354 imageGif($im);
00355 }
00356 imagedestroy($im);
00357 exit;
00358 }
00359
00367 function wrapFileName($inputName) {
00368 if (strstr($inputName,' ')) {
00369 $inputName='"'.$inputName.'"';
00370 }
00371 return $inputName;
00372 }
00373 }
00374
00375
00376 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/thumbs.php']) {
00377 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/thumbs.php']);
00378 }
00379
00380
00381
00382
00383
00384 $SOBE = t3lib_div::makeInstance('SC_t3lib_thumbs');
00385 $SOBE->init();
00386 $SOBE->main();
00387 ?>