Witam
Powie mi ktoś dlaczego ta funkcja do zmniejszania obrazków je ucina?
  1. /**
  2.  * easy image resize function
  3.  * @param $file - file name to resize
  4.  * @param $string - The image data, as a string
  5.  * @param $width - new image width
  6.  * @param $height - new image height
  7.  * @param $proportional - keep image proportional, default is no
  8.  * @param $output - name of the new file (include path if needed)
  9.  * @param $delete_original - if true the original image will be deleted
  10.  * @param $use_linux_commands - if set to true will use "rm" to delete the image, if false will use PHP unlink
  11.  * @param $quality - enter 1-100 (100 is best quality) default is 100
  12.  * @return boolean|resource
  13.  */
  14. function smart_resize_image($file,
  15. $string = null,
  16. $width = 0,
  17. $height = 0,
  18. $proportional = false,
  19. $output = 'file',
  20. $delete_original = true,
  21. $use_linux_commands = false,
  22. $quality = 100
  23. ) {
  24.  
  25. if ( $height <= 0 && $width <= 0 ) return false;
  26. if ( $file === null && $string === null ) return false;
  27.  
  28. # Setting defaults and meta
  29. $info = $file !== null ? getimagesize($file) : getimagesizefromstring($string);
  30. $image = '';
  31. $final_width = 0;
  32. $final_height = 0;
  33. list($width_old, $height_old) = $info;
  34. $cropHeight = $cropWidth = 0;
  35.  
  36. # Calculating proportionality
  37. if ($proportional) {
  38. if ($width == 0) $factor = $height/$height_old;
  39. elseif ($height == 0) $factor = $width/$width_old;
  40. else $factor = min( $width / $width_old, $height / $height_old );
  41.  
  42. $final_width = round( $width_old * $factor );
  43. $final_height = round( $height_old * $factor );
  44. }
  45. else {
  46. $final_width = ( $width <= 0 ) ? $width_old : $width;
  47. $final_height = ( $height <= 0 ) ? $height_old : $height;
  48. $widthX = $width_old / $width;
  49. $heightX = $height_old / $height;
  50.  
  51. $x = min($widthX, $heightX);
  52. $cropWidth = ($width_old - $width * $x) / 2;
  53. $cropHeight = ($height_old - $height * $x) / 2;
  54. }
  55.  
  56. # Loading image to memory according to type
  57. switch ( $info[2] ) {
  58. case IMAGETYPE_JPEG: $file !== null ? $image = imagecreatefromjpeg($file) : $image = imagecreatefromstring($string); break;
  59. case IMAGETYPE_GIF: $file !== null ? $image = imagecreatefromgif($file) : $image = imagecreatefromstring($string); break;
  60. case IMAGETYPE_PNG: $file !== null ? $image = imagecreatefrompng($file) : $image = imagecreatefromstring($string); break;
  61. default: return false;
  62. }
  63.  
  64.  
  65. # This is the resizing/resampling/transparency-preserving magic
  66. $image_resized = imagecreatetruecolor( $final_width, $final_height );
  67. if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) {
  68. $transparency = imagecolortransparent($image);
  69. $palletsize = imagecolorstotal($image);
  70.  
  71. if ($transparency >= 0 && $transparency < $palletsize) {
  72. $transparent_color = imagecolorsforindex($image, $transparency);
  73. $transparency = imagecolorallocate($image_resized, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
  74. imagefill($image_resized, 0, 0, $transparency);
  75. imagecolortransparent($image_resized, $transparency);
  76. }
  77. elseif ($info[2] == IMAGETYPE_PNG) {
  78. imagealphablending($image_resized, false);
  79. $color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
  80. imagefill($image_resized, 0, 0, $color);
  81. imagesavealpha($image_resized, true);
  82. }
  83. }
  84. imagecopyresampled($image_resized, $image, 0, 0, $cropWidth, $cropHeight, $final_width, $final_height, $width_old - 2 * $cropWidth, $height_old - 2 * $cropHeight);
  85.  
  86.  
  87. # Taking care of original, if needed
  88. if ( $delete_original ) {
  89. if ( $use_linux_commands ) exec('rm '.$file);
  90. else @unlink($file);
  91. }
  92.  
  93. # Preparing a method of providing result
  94. switch ( strtolower($output) ) {
  95. case 'browser':
  96. $mime = image_type_to_mime_type($info[2]);
  97. header("Content-type: $mime");
  98. $output = NULL;
  99. break;
  100. case 'file':
  101. $output = $file;
  102. break;
  103. case 'return':
  104. return $image_resized;
  105. break;
  106. default:
  107. break;
  108. }
  109.  
  110. # Writing image according to type to the output destination and image quality
  111. switch ( $info[2] ) {
  112. case IMAGETYPE_GIF: imagegif($image_resized, $output); break;
  113. case IMAGETYPE_JPEG: imagejpeg($image_resized, $output, $quality); break;
  114. case IMAGETYPE_PNG:
  115. $quality = 9 - (int)((0.9*$quality)/10.0);
  116. imagepng($image_resized, $output, $quality);
  117. break;
  118. default: return false;
  119. }
  120.  
  121. return true;
  122. }

ucięte zdjęcie http://kafar.nazwa.pl/wrzucfote.pl/getobra...en=23QA7tAezRVP