Witam,

Proszę o sprawdzenie poniżeszej funkcji. Tworzy ona miniaturki ale jest chyba jakiś błąd.
Czasami ucina zdjęcia i chyba nia potrafi rozpoznać formatu.

  1. <?
  2.  
  3. /* Proporcjonalne pomniejszanie zdjec */
  4. function resizepics($pics, $newwidth, $newheight, $new){
  5. $x1 = $newwidth;
  6. $x2 = $newheight;
  7.  list($width, $height) = getimagesize($pics);
  8.  if($width > $height && $newheight < $height){
  9.  $newheight = $height / ($width / $newwidth);
  10.  } else if ($width < $height && $newwidth < $width) {
  11. $newwidth = $width / ($height / $newheight);  
  12.  } else {
  13.  $newwidth = $width;
  14.  $newheight = $height;
  15. }
  16.  $source = imagecreatefromjpeg($pics);
  17. if(preg_match("/.jpg/i", "$pics")){
  18. unset($source);
  19.  $source = imagecreatefromjpeg($pics);
  20. }
  21. if(preg_match("/.jpeg/i", "$pics")){
  22. unset($source);
  23.  $source = imagecreatefromjpeg($pics);
  24. }
  25. if(preg_match("/.jpeg/i", "$pics")){
  26. unset($source);
  27.  $source = Imagecreatefromjpeg($pics);
  28. }
  29. if(preg_match("/.png/i", "$pics")){
  30. unset($source);
  31.  $source = imagecreatefrompng($pics);
  32. }
  33. if(preg_match("/.gif/i", "$pics")){
  34. unset($source);
  35.  $source = imagecreatefromgif($pics);
  36. }
  37. $thumb = imagecreatetruecolor($x1, $x2);
  38. $white = imagecolorallocate($thumb,255,255,255);
  39. $x = ($x1 - $newwidth) / 2;
  40. $y = ($x2 - $newheight) / 2;
  41. imagefill($thumb, 1, 1, $white);
  42. imagecopyresampled($thumb, $source, $x, $y, 0, 0, $newwidth, $newheight, $width, $height);
  43. imagejpeg($thumb, $new);
  44. if(preg_match("/.jpg/i", "$pics")){
  45.  imagejpeg($thumb, $new);
  46. }
  47. if(preg_match("/.jpeg/i", "$pics")){
  48.  imagejpeg($thumb, $new);
  49. }
  50. if(preg_match("/.jpeg/i", "$pics")){
  51.  imagejpeg($thumb, $new);
  52. }
  53. if(preg_match("/.png/i", "$pics")){
  54.  imagepng($thumb, $new);
  55. }
  56. if(preg_match("/.gif/i", "$pics")){
  57.  imagegif($thumb, $new);
  58. }
  59. }
  60.  
  61. ?>


Bardzo dziękuję za pomoc