thumb.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. defined('InShopNC') or exit('Access Invalid!');
  3. function get_height($image) {
  4. $size = getimagesize($image);
  5. $height = $size[1];
  6. return $height;
  7. }
  8. function get_width($image) {
  9. $size = getimagesize($image);
  10. $width = $size[0];
  11. return $width;
  12. }
  13. function resize_thumb($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
  14. $newImageWidth = ceil($width * $scale);
  15. $newImageHeight = ceil($height * $scale);
  16. if (C('thumb.cut_type') == 'im'){
  17. $exec_str = rtrim(C('thumb.impath'),'/').'/convert -quality 100 -crop '.$width.'x'.$height.'+'.$start_width.'+'.$start_height.' -resize '.$newImageWidth.'x'.$newImageHeight.' '.$image.' '.$thumb_image_name;
  18. exec($exec_str);
  19. }else{
  20. list($imagewidth, $imageheight, $imageType) = getimagesize($image);
  21. $imageType = image_type_to_mime_type($imageType);
  22. $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
  23. $white = imagecolorallocate($newImage, 255, 255, 255);
  24. imagefill($newImage, 0, 0, $white);
  25. switch($imageType) {
  26. case "image/gif":
  27. $source=imagecreatefromgif($image);
  28. break;
  29. case "image/pjpeg":
  30. case "image/jpeg":
  31. case "image/jpg":
  32. $source=imagecreatefromjpeg($image);
  33. break;
  34. case "image/png":
  35. case "image/x-png":
  36. $source=imagecreatefrompng($image);
  37. break;
  38. }
  39. $dst_w = $dst_h = 0;
  40. if ($newImageWidth > $width) {
  41. $dst_w = ($newImageWidth - $width)/2;
  42. }
  43. if ($newImageHeight > $height) {
  44. $dst_h = ($newImageHeight - $height)/2;
  45. }
  46. if ($dst_w > 0) {
  47. imagecopyresampled($newImage,$source,$dst_w,$dst_h,$start_width,$start_height,$width,$height,$width,$height);
  48. } else {
  49. imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
  50. }
  51. switch($imageType) {
  52. case "image/gif":
  53. imagegif($newImage,$thumb_image_name);
  54. break;
  55. case "image/pjpeg":
  56. case "image/jpeg":
  57. case "image/jpg":
  58. imagejpeg($newImage,$thumb_image_name,100);
  59. break;
  60. case "image/png":
  61. case "image/x-png":
  62. imagepng($newImage,$thumb_image_name);
  63. break;
  64. }
  65. }
  66. return $thumb_image_name;
  67. }
  68. ?>