PageRenderTime 33ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/pear/smarty/plugins/function.thumb.php

https://github.com/myszor/sew
PHP | 584 lines | 407 code | 69 blank | 108 comment | 130 complexity | c27952e897c83a5e0a3e785e947b9f41 MD5 | raw file
  1. <?php
  2. /*
  3. * Smarty plugin "Thumb"
  4. * Purpose: creates cached thumbnails
  5. * Home: http://www.cerdmann.com/thumb/
  6. * Copyright (C) 2005 Christoph Erdmann
  7. *
  8. * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
  13. * -------------------------------------------------------------
  14. * Author: Christoph Erdmann (CE)
  15. * Internet: http://www.cerdmann.com
  16. *
  17. * Author: Benjamin Fleckenstein (BF)
  18. * Internet: http://www.benjaminfleckenstein.de
  19. *
  20. * Author: Marcus Gueldenmeister (MG)
  21. * Internet: http://www.gueldenmeister.de/marcus/
  22. *
  23. * Author: Andreas Bösch (AB)
  24. * Changelog:
  25. * 2005-10-31 Fixed some small bugs (CE)
  26. * 2005-10-09 Rewrote crop-function (CE)
  27. * 2005-10-08 Decreased processing time by prescaling linear and cleaned code (CE)
  28. * 2005-07-13 Set crop=true as standard (CE)
  29. * 2005-07-12 Added crop parameter. Original code by "djneoform at gmail dot com" (AB)
  30. * 2005-07-02 Found a stupid mistake. Should be faster now (CE)
  31. * 2005-06-02 Added file_exists(SOURCE)-trigger (CE)
  32. * 2005-06-02 Added extrapolate parameter (CE)
  33. * 2005-06-12 Bugfix alt/title (MG)
  34. * 2005-06-10 Bugfix (MG)
  35. * 2005-06-02 Added window parameter (MG)
  36. * 2005-06-02 Made grey banner configurable, added possibility to keep format in thumbs
  37. made cache path changeable (BF & MG)
  38. * 2004-12-01 New link, hint, quality and type parameter (CE)
  39. * 2004-12-02 Intergrated UnsharpMask (CE)
  40. * -------------------------------------------------------------
  41. */
  42. /*
  43. * Modyfikacje pluginu:
  44. * Dodatkowe parametry:
  45. * img="bool" - jeśli true, zwraca sam relatywny adres pliku z obrazkiem. Polecany do używania z link="false". Domyślnie wynosi false.
  46. * square="bool" - jeśli true, obrazk przed przeskalowaniem jest nakładany na kwadrat o wybranym kolorze. Domyślnie wynosi false. Bok kwadratu jest równy długości najdłuższej krawędzi obrazka.
  47. * square_color="html_color" - kolor kwadratu, na który nakładany jest obrazek przed skalowaniem. Format koloru -sześcioznakowy kod html(bez #). Domyślnie ffffff.
  48. * Możliwe jest uzyskanie przeźroczystosci, wartość square_color musi wynosić wtedy "transparent".
  49. * square_margin="int" - margines, jaki będzie dodany do krawędzi kwadratu. Domyślnie 0.
  50. */
  51. function smarty_function_thumb($params, &$smarty)
  52. {
  53. // Start time measurement
  54. if (isset($params['dev']))
  55. {
  56. if (!function_exists('getmicrotime'))
  57. {
  58. function getmicrotime()
  59. {
  60. list($usec, $sec) = explode(" ", microtime());
  61. return ((float)$usec + (float)$sec);
  62. }
  63. }
  64. $time['start'] = getmicrotime();
  65. }
  66. // Funktion zum Schärfen
  67. if (!function_exists('UnsharpMask'))
  68. {
  69. // Unsharp mask algorithm by Torstein Hřnsi 2003 (thoensi_at_netcom_dot_no)
  70. // Christoph Erdmann: changed it a little, cause i could not reproduce the darker blurred image, now it is up to 15% faster with same results
  71. function UnsharpMask($img, $amount, $radius, $threshold)
  72. {
  73. // Attempt to calibrate the parameters to Photoshop:
  74. if ($amount > 500)
  75. $amount = 500;
  76. $amount = $amount * 0.016;
  77. if ($radius > 50)
  78. $radius = 50;
  79. $radius = $radius * 2;
  80. if ($threshold > 255)
  81. $threshold = 255;
  82. $radius = abs(round($radius)); // Only integers make sense.
  83. if ($radius == 0)
  84. {
  85. return $img;
  86. imagedestroy($img);
  87. break;
  88. }
  89. $w = imagesx($img);
  90. $h = imagesy($img);
  91. $imgCanvas = $img;
  92. $imgCanvas2 = $img;
  93. $imgBlur = imagecreatetruecolor($w, $h);
  94. imagealphablending($imgBlur, false);
  95. $transparent = imagecolorallocatealpha($imgBlur, 255, 255, 255, 127);
  96. imagefilledrectangle($imgBlur, 0, 0, $w, $h, $transparent);
  97. // Gaussian blur matrix:
  98. // 1 2 1
  99. // 2 4 2
  100. // 1 2 1
  101. // Move copies of the image around one pixel at the time and merge them with weight
  102. // according to the matrix. The same matrix is simply repeated for higher radii.
  103. for ($i = 0; $i < $radius; $i++)
  104. {
  105. imagecopy ($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1); // up left
  106. imagecopymerge ($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50); // down right
  107. imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333); // down left
  108. imagecopymerge ($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25); // up right
  109. imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333); // left
  110. imagecopymerge ($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25); // right
  111. imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20 ); // up
  112. imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667); // down
  113. imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50); // center
  114. }
  115. $imgCanvas = $imgBlur;
  116. // Calculate the difference between the blurred pixels and the original
  117. // and set the pixels
  118. for ($x = 0; $x < $w; $x++)
  119. {
  120. // each row
  121. for ($y = 0; $y < $h; $y++)
  122. {
  123. // each pixel
  124. $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
  125. $aOrig = (($rgbOrig >> 24) & 0xFF);
  126. $rOrig = (($rgbOrig >> 16) & 0xFF);
  127. $gOrig = (($rgbOrig >> 8) & 0xFF);
  128. $bOrig = ($rgbOrig & 0xFF);
  129. $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
  130. $aBlur = (($rgbBlur >> 24) & 0xFF);
  131. $rBlur = (($rgbBlur >> 16) & 0xFF);
  132. $gBlur = (($rgbBlur >> 8) & 0xFF);
  133. $bBlur = ($rgbBlur & 0xFF);
  134. // When the masked pixels differ less from the original
  135. // than the threshold specifies, they are set to their original value.
  136. $aNew = (abs($aOrig - $aBlur) >= $threshold) ? max(0, min(127, ($amount * ($aOrig - $aBlur)) + $aOrig)) : $aOrig;
  137. $rNew = (abs($rOrig - $rBlur) >= $threshold) ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig;
  138. $gNew = (abs($gOrig - $gBlur) >= $threshold) ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig;
  139. $bNew = (abs($bOrig - $bBlur) >= $threshold) ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig;
  140. if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew))
  141. {
  142. $pixCol = imagecolorallocatealpha($img, $rNew, $gNew, $bNew, $aNew);
  143. ImageSetPixel($img, $x, $y, $pixCol);
  144. }
  145. }
  146. }
  147. return $img;
  148. }
  149. }
  150. $_CONFIG['types'] = array('', '.gif', '.jpg', '.png');
  151. ### Übergebene Parameter auswerten und verifizieren
  152. if (empty($params['cache']))
  153. $_CONFIG['cache'] = '/cache/images/';
  154. else
  155. $_CONFIG['cache'] = $params['cache'];
  156. $params['origfile'] = !empty($params['file']) ? $params['file'] : '';
  157. if (!empty($params['file']) && !@file_exists($params['file']) && $params['file'][0] == '/')
  158. {
  159. $params['file'] = $_SERVER['DOCUMENT_ROOT'] . $params['file'];
  160. }
  161. if (empty($params['file']))
  162. {
  163. $smarty->_trigger_fatal_error("thumb: parameter 'file' cannot be empty and must exist");
  164. return;
  165. }
  166. if (!file_exists($params['file']))
  167. {
  168. //$smarty->_trigger_fatal_error("thumb: parameter 'file' must exist");
  169. return '';
  170. }
  171. if (empty($params['greyscale'])) $params['greyscale']=false;
  172. if (empty($params['square'])) $params['square']=false;
  173. if (empty($params['square_margin'])) $params['square_margin']=0;
  174. if (empty($params['square_color'])) $params['square_color']='ffffff';
  175. if (empty($params['sharpen'])) $params['sharpen'] = false;
  176. if (empty($params['html'])) $params['html'] = '';
  177. if (!isset($params['alt'])) $params['alt'] = '';
  178. if (empty($params['shortside'])) $params['shortside'] = false;
  179. if (empty($params['longside'])) $params['longside'] = false;
  180. if (empty($params['img'])) $params['img'] = false;
  181. if (empty($params['link'])) $params['link'] = true;
  182. if (empty($params['rel'])) $params['rel'] = '';
  183. if (empty($params['title'])) $params['title'] = '';
  184. if (empty($params['window'])) $params['window'] = false;
  185. if (empty($params['hint'])) $params['hint'] = true;
  186. if (empty($params['extrapolate'])) $params['extrapolate'] = true;
  187. if (empty($params['dev'])) $params['dev'] = false;
  188. if (empty($params['crop'])) $params['crop'] = true;
  189. if (empty($params['width']) AND empty($params['height'])
  190. AND empty($params['longside']) AND empty($params['shortside'])) $params['width'] = 100;
  191. if (empty($params['overlay_position'])) $params['overlay_position'] = 9;
  192. ### Info über Source (SRC) holen
  193. $temp = getimagesize($params['file']);
  194. $_SRC['file'] = $params['file'];
  195. $_SRC['origfile'] = $params['origfile'];
  196. $_SRC['width'] = $temp[0];
  197. $_SRC['height'] = $temp[1];
  198. $_SRC['width_oryg'] = $temp[0];
  199. $_SRC['height_oryg'] = $temp[1];
  200. $_SRC['type'] = $temp[2]; // 1=GIF, 2=JPG, 3=PNG, SWF=4
  201. $_SRC['string'] = $temp[3];
  202. $_SRC['filename'] = basename($params['file']);
  203. $_SRC['modified'] = filemtime($params['file']);
  204. $_SRC['longest_edge']=($temp[0]>$temp[1]?$temp[0]:$temp[1]);
  205. $_SRC['shorter_edge']=($temp[0]<$temp[1]?$temp[0]:$temp[1]);
  206. $_SRC['longest_edge']= $_SRC['longest_edge']+$params['square_margin']*2; //bo margines to margines - z dwoch stron ma być
  207. if ($params['square']==true){
  208. $_SRC['width'] = $_SRC['longest_edge'];
  209. $_SRC['height'] = $_SRC['longest_edge'];
  210. }
  211. if ($params['square_color']=='transparent') $params['type']=3;
  212. // Hash erstellen
  213. $_SRC['hash'] = md5($_SRC['file'].$_SRC['modified'].implode('',$params));
  214. ### Infos über Destination (DST) errechnen
  215. if (is_numeric($params['width'])) $_DST['width'] = $params['width'];
  216. else $_DST['width'] = round($params['height']/($_SRC['height']/$_SRC['width']));
  217. if (is_numeric($params['height'])) $_DST['height'] = $params['height'];
  218. else $_DST['height'] = round($params['width']/($_SRC['width']/$_SRC['height']));
  219. // Das Größenverhältnis soll erhalten bleiben egal ob das Bild hoch oder querformatig ist.
  220. if (is_numeric($params['longside']))
  221. {
  222. if ($_SRC['width'] < $_SRC['height'])
  223. {
  224. $_DST['height'] = $params['longside'];
  225. $_DST['width'] = round($params['longside']/($_SRC['height']/$_SRC['width']));
  226. }
  227. else
  228. {
  229. $_DST['width'] = $params['longside'];
  230. $_DST['height'] = round($params['longside']/($_SRC['width']/$_SRC['height']));
  231. }
  232. }
  233. elseif (is_numeric($params['shortside']))
  234. {
  235. if ($_SRC['width'] < $_SRC['height'])
  236. {
  237. $_DST['width'] = $params['shortside'];
  238. $_DST['height'] = round($params['shortside']/($_SRC['width']/$_SRC['height']));
  239. }
  240. else
  241. {
  242. $_DST['height'] = $params['shortside'];
  243. $_DST['width'] = round($params['shortside']/($_SRC['height']/$_SRC['width']));
  244. }
  245. }
  246. // Soll beschnitten werden? (Standard)
  247. if($params['crop'])
  248. {
  249. $width_ratio = $_SRC['width']/$_DST['width'];
  250. $height_ratio = $_SRC['height']/$_DST['height'];
  251. // Es muss an der Breite beschnitten werden
  252. if ($width_ratio > $height_ratio)
  253. {
  254. $_DST['offset_w'] = round(($_SRC['width']-$_DST['width']*$height_ratio)/2);
  255. $_SRC['width'] = round($_DST['width']*$height_ratio);
  256. }
  257. // es muss an der Höhe beschnitten werden
  258. elseif ($width_ratio < $height_ratio)
  259. {
  260. $_DST['offset_h'] = round(($_SRC['height']-$_DST['height']*$width_ratio)/2);
  261. $_SRC['height'] = round($_DST['height']*$width_ratio);
  262. }
  263. }
  264. // Wenn das Ursprungsbild kleiner als das Ziel-Bild ist, soll nicht hochskaliert werden und die neu berechneten Werte werden wieder überschrieben
  265. if ($params['extrapolate'] == 'false' && $_DST['height'] > $_SRC['height'] && $_DST['width'] > $_SRC['width'])
  266. {
  267. $_DST['width'] = $_SRC['width'];
  268. $_DST['height'] = $_SRC['height'];
  269. }
  270. if (!empty($params['type'])) $_DST['type'] = $params['type'];
  271. else $_DST['type'] = $_SRC['type'];
  272. $_DST['file'] = $_CONFIG['cache'].$_SRC['hash'].$_CONFIG['types'][$_DST['type']];
  273. $_DST['string'] = 'width="'.$_DST['width'].'" height="'.$_DST['height'].'"';
  274. // Gibts evtl. einen Rahmen
  275. if (!empty($params['frame']))
  276. {
  277. if (!@file_exists($params['frame']) && $params['frame'][0] == '/')
  278. {
  279. $params['frame'] = $_SERVER['DOCUMENT_ROOT'] . $params['frame'];
  280. }
  281. // schauen obs gültig ist
  282. $imagesize = getimagesize($params['frame']);
  283. if ($imagesize[0] != $imagesize[1] OR $imagesize[0]%3 OR !file_exists($params['frame'])) { $smarty->_trigger_fatal_error("thumb: wrong dimensions of 'frame'-image or width and height is not a multiplier of 3"); return; }
  284. // Blockgröße brauche ich schon hier, falls ein gecachtes Bild wiedergegeben werden soll
  285. $frame_blocksize = $imagesize[0]/3;
  286. $_DST['string'] = 'width="'.($_DST['width']+2*$frame_blocksize).'" height="'.($_DST['height']+2*$frame_blocksize).'"';
  287. }
  288. ### Rückgabe-Strings erstellen
  289. $_RETURN['img'] = '<img src="'.$_DST['file'].'" '.$params['html'].' alt="'.$params['alt'].'" '.$_DST['string'].' />';
  290. if ($params['link'] == "true")
  291. {
  292. if (empty($params['linkurl']))
  293. $params['linkurl'] = $_SRC['origfile'];
  294. if ($params['window'] == "true")
  295. $returner = '<a href="' . $params['linkurl'] . '" rel="' . $params['rel'] . '" title="' . $params['title'] . '" target="_blank">' . $_RETURN['img'].'</a>';
  296. else
  297. $returner = '<a href="' . $params['linkurl'] . '" rel="' . $params['rel'] . '" title="' . $params['title'] . '">' . $_RETURN['img'] . '</a>';
  298. }
  299. else
  300. {
  301. $returner = $_RETURN['img'];
  302. }
  303. if (file_exists($SITE_ROOT . $_DST['file']) AND !$params['dev'])
  304. {
  305. if (($params['img']=='true'))
  306. {
  307. $returner = $SITE_ROOT . $_DST['file'];
  308. }
  309. if (!empty($params['assign']))
  310. {
  311. $smarty->assign($params['assign'], $returner);
  312. return;
  313. }
  314. else
  315. {
  316. return $returner;
  317. }
  318. }
  319. ### ansonsten weitermachen
  320. // SRC einlesen
  321. if ($_SRC['type'] == 1) $_SRC['image'] = imagecreatefromgif($_SRC['file']);
  322. if ($_SRC['type'] == 2) $_SRC['image'] = imagecreatefromjpeg($_SRC['file']);
  323. if ($_SRC['type'] == 3) $_SRC['image'] = imagecreatefrompng($_SRC['file']);
  324. //square
  325. if ($params['square']==true)
  326. {
  327. $_TMP['square']=imagecreatetruecolor($_SRC['longest_edge'], $_SRC['longest_edge']);
  328. if ($params['square_color']!=='transparent')
  329. {
  330. $color=imagecolorallocatealpha($_TMP['square'],hexdec('0x' . $params['square_color']{0} . $params['square_color']{1}), hexdec('0x' . $params['square_color']{2} . $params['square_color']{3}), hexdec('0x' . $params['square_color']{4} . $params['square_color']{5}), 0);
  331. }
  332. else
  333. {
  334. $color=imagecolorallocatealpha($_TMP['square'], 0, 0, 0, 127);
  335. }
  336. imagefill($_TMP['square'], 0, 0, $color);
  337. $shorter_edge=(($_SRC['shorter_edge']==($_SRC['width_oryg']))?'width_oryg':'height_oryg');
  338. $coordinate=($_SRC['longest_edge']-$_SRC['shorter_edge'])/2;
  339. if ($shorter_edge=='width_oryg')
  340. {
  341. // echo"szer";
  342. imagecopy($_TMP['square'], $_SRC['image'], $coordinate, $params['square_margin'],0, 0, $_SRC['width_oryg'],$_SRC['height_oryg']);
  343. }
  344. elseif ($shorter_edge=='height_oryg')
  345. {
  346. // echo"wys";
  347. imagecopy($_TMP['square'], $_SRC['image'], $params['square_margin'], $coordinate, 0, 0, $_SRC['width_oryg'],$_SRC['height_oryg']);
  348. }
  349. else
  350. {
  351. imagecopy($_TMP['square'], $_SRC['image'], $params['square_margin'], $params['square_margin'], 0, 0, $_SRC['width_oryg'],$_SRC['height_oryg']);
  352. }
  353. $_SRC['image']=$_TMP['square'];
  354. unset($_TMP['square']);
  355. }
  356. // Wenn das Bild sehr groß ist, zuerst linear auf vierfache Zielgröße herunterskalieren und $_SRC überschreiben
  357. if ($_DST['width']*4 < $_SRC['width'] AND $_DST['height']*4 < $_SRC['height'])
  358. {
  359. // Multiplikator der Zielgröße
  360. $_TMP['width'] = round($_DST['width']*4);
  361. $_TMP['height'] = round($_DST['height']*4);
  362. $_TMP['image'] = imagecreatetruecolor($_TMP['width'], $_TMP['height']);
  363. imagealphablending($_TMP['image'], false);
  364. $transparent = imagecolorallocatealpha($_TMP['image'], 255, 255, 255, 127);
  365. imagefilledrectangle($_TMP['image'], 0, 0, $_TMP['width'], $_TMP['height'], $transparent);
  366. imagecopyresized($_TMP['image'], $_SRC['image'], 0, 0, $_DST['offset_w'], $_DST['offset_h'], $_TMP['width'], $_TMP['height'], $_SRC['width'], $_SRC['height']);
  367. $_SRC['image'] = $_TMP['image'];
  368. $_SRC['width'] = $_TMP['width'];
  369. $_SRC['height'] = $_TMP['height'];
  370. // Wenn vorskaliert wird, darf ja nicht nochmal ein bestimmter Bereich ausgeschnitten werden
  371. $_DST['offset_w'] = 0;
  372. $_DST['offset_h'] = 0;
  373. unset($_TMP['image']);
  374. }
  375. // DST erstellen
  376. $_DST['image'] = imagecreatetruecolor($_DST['width'], $_DST['height']);
  377. imagealphablending($_DST['image'], false);
  378. imagesavealpha($_DST['image'], true);
  379. $transparent = imagecolorallocatealpha($_DST['image'], 255, 255, 255, 127);
  380. imagefilledrectangle($_DST['image'], 0, 0, $_DST['width'], $_DST['height'], $transparent);
  381. imagecopyresampled($_DST['image'], $_SRC['image'], 0, 0, $_DST['offset_w'], $_DST['offset_h'], $_DST['width'], $_DST['height'], $_SRC['width'], $_SRC['height']);
  382. if ($params['sharpen'] != "false") $_DST['image'] = UnsharpMask($_DST['image'],80,.5,3);
  383. // Soll eine Lupe eingefügt werden?
  384. if ($params['hint'] == "true" AND $params['link'] == "true")
  385. {
  386. //Soll der weiße Balken wirklich hinzugefügt werden?
  387. if ($params['addgreytohint'] != 'false')
  388. {
  389. $trans = imagecolorallocatealpha($_DST['image'], 255, 255, 255, 25);
  390. imagefilledrectangle($_DST['image'], 0, $_DST['height']-9, $_DST['width'], $_DST['height'], $trans);
  391. }
  392. $magnifier = imagecreatefromstring(gzuncompress(base64_decode("eJzrDPBz5+WS4mJgYOD19HAJAtLcIMzBBiRXrilXA1IsxU6eIRxAUMOR0gHkcxZ4RBYD1QiBMOOlu3V/gIISJa4RJc5FqYklmfl5CiGZuakMBoZ6hkZ6RgYGJs77ex2BalRBaoLz00rKE4tSGXwTk4vyc1NTMhMV3DKLUsvzi7KLFXwjFEAa2svWnGdgYPTydHEMqZhTOsE++1CAyNHzm2NZjgau+dAmXlAwoatQmOld3t/NPxlLMvY7sovPzXHf7re05BPzjpQTMkZTPjm1HlHkv6clYWK43Zt16rcDjdZ/3j2cd7qD4/HHH3GaprFrw0QZDHicORXl2JsPsveVTDz//L3N+WpxJ5Hff+10Tjdd2/Vi17vea79Om5w9zzyne9GLnWGrN8atby/ayXPOsu2w4quvVtxNCVVz5nAf3nDpZckBCedpqSc28WTOWnT7rZNXZSlPvFybie9EFc6y3bIMCn3JAoJ+kyyfn9qWq+LZ9Las26Jv482cDRE6Ci0B6gVbo2oj9KabzD8vyMK4ZMqMs2kSvW4chz88SXNzmeGjtj1QZK9M3HHL8L7HITX3t19//VVY8CYDg9Kvy2vDXu+6mGGxNOiltMPsjn/t9eJr0ja/FOdi5TyQ9Lz3fOqstOr99/dnro2vZ1jy76D/vYivPsBoYPB09XNZ55TQBAAJjs5s</body>")));
  393. imagealphablending($_DST['image'], true);
  394. imagecopy($_DST['image'], $magnifier, $_DST['width']-15, $_DST['height']-14, 0, 0, 11, 11);
  395. imagedestroy($magnifier);
  396. }
  397. if ($params['greyscale'] == true)
  398. {
  399. $bwimage= imagecreate($_DST['width'], $_DST['height']); //Creates the 256 color palette
  400. $palette = array();
  401. for ($c=0;$c<256;$c++)
  402. {
  403. $palette[$c] = imagecolorallocate($bwimage,$c,$c,$c);
  404. }
  405. //Reads the origonal colors pixel by pixel
  406. for ($y=0;$y<$_DST['height'];$y++)
  407. {
  408. for ($x=0;$x<$_DST['width'];$x++)
  409. {
  410. $rgb = imagecolorat($_DST['image'],$x,$y);
  411. $r = ($rgb >> 16) & 0xFF;
  412. $g = ($rgb >> 8) & 0xFF;
  413. $b = $rgb & 0xFF;
  414. $gs = thumb_yiq($r,$g,$b);
  415. imagesetpixel($bwimage,$x,$y,$palette[$gs]);
  416. }
  417. }
  418. imagedestroy($_DST['image']);
  419. $_DST['image'] = $bwimage;
  420. }
  421. // Soll ein Overlay-Bild hinzugefügt werden
  422. if (!empty($params['overlay']))
  423. {
  424. if (!@file_exists($params['overlay']) && $params['overlay'][0] == '/')
  425. {
  426. $params['overlay'] = $_SERVER['DOCUMENT_ROOT'] . $params['overlay'];
  427. }
  428. // "overlay"-Bild laden
  429. $overlay = imagecreatefrompng($params['overlay']);
  430. $overlay_size = getimagesize($params['overlay']);
  431. // Overlay-Bild an die richtige Stelle kopieren
  432. if ($params['overlay_position'] == '1') imagecopy($_DST['image'], $overlay, 0, 0, 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  433. if ($params['overlay_position'] == '2') imagecopy($_DST['image'], $overlay, $_DST['width']/2-$overlay_size[0]/2, 0, 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  434. if ($params['overlay_position'] == '3') imagecopy($_DST['image'], $overlay, $_DST['width']-$overlay_size[0], 0, 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  435. if ($params['overlay_position'] == '4') imagecopy($_DST['image'], $overlay, 0, $_DST['height']/2-$overlay_size[1]/2, 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  436. if ($params['overlay_position'] == '5') imagecopy($_DST['image'], $overlay, $_DST['width']/2-$overlay_size[0]/2, $_DST['height']/2-$overlay_size[1]/2, 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  437. if ($params['overlay_position'] == '6') imagecopy($_DST['image'], $overlay, $_DST['width']-$overlay_size[0], $_DST['height']/2-$overlay_size[1]/2, 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  438. if ($params['overlay_position'] == '7') imagecopy($_DST['image'], $overlay, 0, $_DST['height']-$overlay_size[1], 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  439. if ($params['overlay_position'] == '8') imagecopy($_DST['image'], $overlay, $_DST['width']/2-$overlay_size[0]/2, $_DST['height']-$overlay_size[1], 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  440. if ($params['overlay_position'] == '9') imagecopy($_DST['image'], $overlay, $_DST['width']-$overlay_size[0], $_DST['height']-$overlay_size[1], 0, 0, $overlay_size[0], $overlay_size[1]); // ecke links oben
  441. }
  442. // Berechnungszeit hinzufügen
  443. if ($params['dev'])
  444. {
  445. // Zeit anhalten
  446. $time['end'] = getmicrotime();
  447. $time = round($time['end'] - $time['start'],2);
  448. // Farben definieren
  449. $white_trans = imagecolorallocatealpha($_DST['image'], 255, 255, 255, 25);
  450. $black = ImageColorAllocate ($_DST['image'], 0, 0, 0);
  451. // Weißer Balken oben
  452. imagefilledrectangle($_DST['image'], 0, 0, $_DST['width'], 10, $white_trans);
  453. // Schrift mit Zeitangabe
  454. imagestring($_DST['image'], 1, 5, 2, 'processing time: '.$time.'s', $black);
  455. }
  456. // Soll ein Rahmen hinzugefügt werden
  457. if (!empty($params['frame']))
  458. {
  459. // "frame"-Bild laden und initialisieren
  460. $frame = imagecreatefrompng($params['frame']);
  461. $frame_blocksize = $imagesize[0]/3;
  462. // Neues Bild erstellen und bisher erzeugtes Bild hereinkopieren
  463. $_FRAME['image'] = imagecreatetruecolor($_DST['width']+2*$frame_blocksize, $_DST['height']+2*$frame_blocksize);
  464. imagecopy($_FRAME['image'], $_DST['image'], $frame_blocksize, $frame_blocksize, 0, 0, $_DST['width'], $_DST['height']);
  465. // Jetzt die ganzen anderen Rahmen herum zeichnen
  466. // die Ecken
  467. imagecopy($_FRAME['image'], $frame, 0, 0, 0, 0, $frame_blocksize, $frame_blocksize); // ecke links oben
  468. imagecopy($_FRAME['image'], $frame, $_DST['width']+$frame_blocksize, 0, 2*$frame_blocksize, 0, $frame_blocksize, $frame_blocksize); // ecke rechts oben
  469. imagecopy($_FRAME['image'], $frame, $_DST['width']+$frame_blocksize, $_DST['height']+$frame_blocksize, 2*$frame_blocksize, 2*$frame_blocksize, $frame_blocksize, $frame_blocksize); // ecke rechts unten
  470. imagecopy($_FRAME['image'], $frame, 0, $_DST['height']+$frame_blocksize, 0, 2*$frame_blocksize, $frame_blocksize, $frame_blocksize); // ecke links unten
  471. // jetzt die Seiten
  472. imagecopyresized($_FRAME['image'], $frame, $frame_blocksize, 0, $frame_blocksize, 0, $_DST['width'], $frame_blocksize, $frame_blocksize, $frame_blocksize); // oben
  473. imagecopyresized($_FRAME['image'], $frame, $_DST['width']+$frame_blocksize, $frame_blocksize, 2*$frame_blocksize, $frame_blocksize, $frame_blocksize, $_DST['height'], $frame_blocksize, $frame_blocksize); // rechts
  474. imagecopyresized($_FRAME['image'], $frame, $frame_blocksize, $_DST['height']+$frame_blocksize, $frame_blocksize, 2*$frame_blocksize, $_DST['width'], $frame_blocksize, $frame_blocksize, $frame_blocksize); // unten
  475. imagecopyresized($_FRAME['image'], $frame, 0, $frame_blocksize, 0, $frame_blocksize, $frame_blocksize, $_DST['height'], $frame_blocksize, $frame_blocksize); // links
  476. $_DST['image'] = $_FRAME['image'];
  477. $_DST['width'] = $_DST['width']+2*$frame_blocksize;
  478. $_DST['height'] = $_DST['height']+2*$frame_blocksize;
  479. $_DST['string2'] = 'width="'.$_DST['width'].'" height="'.$_DST['height'].'"';
  480. $returner = str_replace($_DST['string'], $_DST['string2'], $returner);
  481. }
  482. // Thumbnail abspeichern
  483. if ($_DST['type'] == 1)
  484. {
  485. imagetruecolortopalette($_DST['image'], false, 256);
  486. imagegif($_DST['image'], $_SERVER['DOCUMENT_ROOT'] . $_DST['file']);
  487. }
  488. if ($_DST['type'] == 2)
  489. {
  490. Imageinterlace($_DST['image'], 1);
  491. if (empty($params['quality'])) $params['quality'] = 80;
  492. imagejpeg($_DST['image'], $_SERVER['DOCUMENT_ROOT'] . $_DST['file'], $params['quality']);
  493. }
  494. if ($_DST['type'] == 3)
  495. {
  496. imagepng($_DST['image'], $_SERVER['DOCUMENT_ROOT'] . $_DST['file']);
  497. }
  498. imagedestroy($_DST['image']);
  499. imagedestroy($_SRC['image']);
  500. if (($params['img']=='true'))
  501. {
  502. $returner = $SITE_ROOT . $_DST['file'];
  503. }
  504. if (!empty($params['assign']))
  505. {
  506. $smarty->assign($params['assign'], $returner);
  507. }
  508. else
  509. {
  510. return $returner;
  511. }
  512. }
  513. function thumb_yiq($r,$g,$b) { return (($r*0.299)+($g*0.587)+($b*0.114)); }
  514. ?>