Jak dodac do tej klasy mozliwosc generowania znaku wodnego?
Chodzi mi o jakis sprawdzony skrypt tak aby pasowal do tej klasy

  1. <?php
  2. /**
  3. * class Image2Thumbnail
  4. *  Thumbnail creation with PHP4 and GDLib 2.0.1 !
  5. *
  6. *
  7. *  @author  Andreas Martens <heyn@plautdietsch.de>
  8. *  @author  Patrick Teague <webdude@veslach.com>
  9. * @version 1.0a
  10. *  @date  modified 03/13/2003
  11. *  @modifications - added support for reading gif images - makes jpg thumbnails
  12. * changed several groups of 'if' statements to single 'switch' statements
  13. * commented out original code so modification could be identified.
  14. */
  15.  
  16. class Img2Thumb {
  17. // New modification
  18. /**
  19. * private variables - do not use
  20. *
  21. * @var int $bg_red 0-255 - red color variable for background filler
  22. * @var int $bg_green 0-255 - green color variable for background filler
  23. * @var int $bg_blue 0-255 - blue color variable for background filler
  24. * @var int $maxSize 0-1 - true/false - should thumbnail be filled to max pixels
  25. */
  26. var $bg_red;
  27. var $bg_green;
  28. var $bg_blue;
  29. var $maxSize;
  30.  
  31. /**
  32. *  Constructor - requires following vars:
  33. *
  34. * @param string $filename image path
  35. *
  36. * These are additional vars:
  37. *
  38. * @param int $newxsize new maximum image width
  39. * @param int $newysize new maximum image height
  40. * @param string $fileout output image path
  41. * @param int $thumbMaxSize whether thumbnail should have background fill to make it exactly $newxsize x $ne
    wysize
  42. * @param int $bgred 0-255 - red color variable for background filler
  43. * @param int $bggreen 0-255 - green color variable for background filler
  44. * @param int $bgblue 0-255 - blue color variable for background filler
  45. *
  46. */
  47. function Img2Thumb($filename, $newxsize=60, $newysize=60, $fileout='',
  48. $thumbMaxSize=0, $bgred=0, $bggreen=0, $bgblue=0)
  49. {
  50. global $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_COOKIE_VARS;
  51.  
  52. if (isset($HTTP_COOKIE_VARS))
  53. $httpvars = $HTTP_COOKIE_VARS;
  54. else if (isset($HTTP_POST_VARS))
  55. $httpvars = $HTTP_POST_VARS;
  56.  else if (isset($HTTP_GET_VARS))
  57.  $httpvars = $HTTP_GET_VARS;
  58.  
  59. // New modification - checks color int to be sure within range
  60. if($thumbMaxSize)
  61. {
  62. $this->maxSize = true;
  63. }
  64. else
  65. {
  66. $this->maxSize = false;
  67. }
  68. if($bgred>=|| $bgred<=255)
  69. {
  70. $this->bg_red = $bgred;
  71. }
  72. else
  73. {
  74. $this->bg_red = 0;
  75. }
  76. if($bggreen>=|| $bggreen<=255)
  77. {
  78. $this->bg_green = $bggreen;
  79. }
  80. else
  81. {
  82. $this->bg_green = 0;
  83. }
  84. if($bgblue>=|| $bgblue<=255)
  85. {
  86. $this->bg_blue = $bgblue;
  87. }
  88. else
  89. {
  90. $this->bg_blue = 0;
  91. }
  92.  
  93.  
  94. $this -> NewImgCreate($filename,$newxsize,$newysize,$fileout);
  95. }
  96.  
  97. /**
  98. *
  99. * private function - do not call
  100. *
  101. */
  102. function NewImgCreate($filename,$newxsize,$newysize,$fileout)
  103. {
  104. $type = $this->GetImgType($filename);
  105.  
  106. /* Original code removed in favor of 'switch' statement
  107. if ($type=="png")
  108. {
  109.  $orig_img = imagecreatefrompng($filename);
  110. }
  111. if ($type=="jpg")
  112. {
  113.  $orig_img = imagecreatefromjpeg($filename);
  114. }
  115. */
  116. switch($type)
  117. {
  118. case "gif":
  119. // unfortunately this function does not work on windows
  120. // via the precompiled php installation :(
  121. // it should work on all other systems however.
  122. if( function_exists("imagecreatefromgif") )
  123. {
  124. $orig_img = imagecreatefromgif($filename);
  125. break;
  126. }
  127. else
  128. {
  129. print( "sorry, this server doesn't support <b>imagecreatefromgif()</b>" );
  130. break;
  131. }
  132. case "jpg":
  133. $orig_img = imagecreatefromjpeg($filename);
  134. break;
  135. case "png":
  136. $orig_img = imagecreatefrompng($filename);
  137. break;
  138. }
  139.  
  140. $new_img =$this->NewImgResize($orig_img,$newxsize,$newysize,$filename);
  141.  
  142. if (!empty($fileout))
  143. {
  144.  $this-> NewImgSave($new_img,$fileout,$type);
  145. }
  146. else
  147. {
  148.  $this->NewImgShow($new_img,$type);
  149. }
  150.  
  151. ImageDestroy($new_img);
  152. ImageDestroy($orig_img);
  153. }
  154.  
  155. /**
  156. *
  157. * private function - do not call
  158. * includes function ImageCreateTrueColor and ImageCopyResampled which are availabl
    e only under GD 2.0.1 or higher !
  159. */
  160. function NewImgResize($orig_img,$newxsize,$newysize,$filename)
  161. {
  162. //getimagesize returns array
  163. // [0] = width in pixels
  164. // [1] = height in pixels
  165. // [2] = type
  166. // [3] = img tag "width=xx height=xx" values
  167.  
  168. $orig_size = getimagesize($filename);
  169.  
  170. $maxX = $newxsize;
  171. $maxY = $newysize;
  172.  
  173. if ($orig_size[0]<$orig_size[1])
  174. {
  175. $newxsize = $newysize * ($orig_size[0]/$orig_size[1]);
  176. $adjustX = ($maxX - $newxsize)/2;
  177. $adjustY = 0;
  178. }
  179. else
  180. {
  181. $newysize = $newxsize / ($orig_size[0]/$orig_size[1]);
  182. $adjustX = 0;
  183. $adjustY = ($maxY - $newysize)/2;
  184. }
  185.  
  186. /* Original code removed to allow for maxSize thumbnails
  187. $im_out = ImageCreateTrueColor($newxsize,$newysize);
  188. ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0,
  189. $newxsize, $newysize,$orig_size[0], $orig_size[1]);
  190. */
  191.  
  192. // New modification - creates new image at maxSize
  193. if( $this->maxSize )
  194. {
  195. $im_out = ImageCreateTrueColor($maxX,$maxY);
  196. $bgfill = imagecolorallocate( $im_out, $this->bg_red, $this->bg_green, $this->bg_blue );
  197. imagefill( $im_out, 0,0, $bgfill );
  198. ImageCopyResampled($im_out, $orig_img, $adjustX, $adjustY, 0, 0,
  199. $newxsize, $newysize,$orig_size[0], $orig_size[1]);
  200. }
  201. // Need to image fill just in case image is transparent, don't always want black background
  202. else
  203. {
  204. $im_out = ImageCreateTrueColor($newxsize,$newysize);
  205. $bgfill = imagecolorallocate( $im_out, $this->bg_red, $this->bg_green, $this->bg_blue );
  206. imagefill( $im_out, 0,0, $bgfill );
  207. ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0,
  208. $newxsize, $newysize,$orig_size[0], $orig_size[1]);
  209. }
  210. return $im_out;
  211. }
  212.  
  213. /**
  214. *
  215. * private function - do not call
  216. *
  217. */
  218. function NewImgSave($new_img,$fileout,$type)
  219. {
  220. /* Original code removed in favor of 'switch' statement
  221. if ($type=="png")
  222. {
  223. if (substr($fileout,strlen($fileout)-4,4)!=".png")
  224. $fileout .= ".png";
  225.  return imagepng($new_img,$fileout);
  226. }
  227. if ($type=="jpg")
  228. {
  229. if (substr($fileout,strlen($fileout)-4,4)!=".jpg")
  230. $fileout .= ".jpg";
  231.  return imagejpeg($new_img,$fileout);
  232. }
  233. */
  234. switch($type)
  235. {
  236. case "gif":
  237. if( function_exists("imagegif") )
  238. {
  239. if (substr($fileout,strlen($fileout)-4,4)!=".gif")
  240. $fileout .= ".gif";
  241. return imagegif($new_img,$fileout);
  242. break;
  243. }
  244. else
  245. $this->NewImgSave( $new_img, $fileout, "jpg" );
  246. case "jpg":
  247. if (substr($fileout,strlen($fileout)-4,4)!=".jpg")
  248. $fileout .= ".jpg";
  249. return imagejpeg($new_img,$fileout);
  250. break;
  251. case "png":
  252. if (substr($fileout,strlen($fileout)-4,4)!=".png")
  253. $fileout .= ".png";
  254. return imagepng($new_img,$fileout);
  255. break;
  256. }
  257. }
  258.  
  259. /**
  260. *
  261. * private function - do not call
  262. *
  263. */
  264. function NewImgShow($new_img,$type)
  265. {
  266. /* Original code removed in favor of 'switch' statement
  267. if ($type=="png")
  268. {
  269. header ("Content-type: image/png");
  270.  return imagepng($new_img);
  271. }
  272. if ($type=="jpg")
  273. {
  274. header ("Content-type: image/jpeg");
  275.  return imagejpeg($new_img);
  276. }
  277. */
  278. switch($type)
  279. {
  280. case "gif":
  281. if( function_exists("imagegif") )
  282. {
  283. header ("Content-type: image/gif");
  284. return imagegif($new_img);
  285. break;
  286. }
  287. else
  288. $this->NewImgShow( $new_img, "jpg" );
  289. case "jpg":
  290. header ("Content-type: image/jpeg");
  291. return imagejpeg($new_img);
  292. break;
  293. case "png":
  294. header ("Content-type: image/png");
  295. return imagepng($new_img);
  296. break;
  297. }
  298. }
  299.  
  300. /**
  301. *
  302. * private function - do not call
  303. *
  304. *  1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF,
  305. *  5 = PSD, 6 = BMP,
  306. *  7 = TIFF(intel byte order),
  307. *  8 = TIFF(motorola byte order),
  308. *  9 = JPC, 10 = JP2, 11 = JPX,
  309. *  12 = JB2, 13 = SWC, 14 = IFF
  310. */
  311. function GetImgType($filename)
  312. {
  313. $size = getimagesize($filename);
  314. /* Original code removed in favor of 'switch' statement
  315. if($size[2]==2)
  316. return "jpg";
  317. elseif($size[2]==3)
  318. return "png";
  319. */
  320. switch($size[2])
  321. {
  322. case 1:
  323. return "gif";
  324. break;
  325. case 2:
  326. return "jpg";
  327. break;
  328. case 3:
  329. return "png";
  330. break;
  331. }
  332. }
  333.  
  334. }
  335. ?>