Rumah > pembangunan bahagian belakang > tutorial php > php缩略图代码,实现满窗格等比例缩小

php缩略图代码,实现满窗格等比例缩小

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-07-25 08:58:51
asal
919 orang telah melayarinya
  1. /**
  2. * 等比例缩小的缩略图
  3. * edit bbs.it-home.org
  4. */
  5. function thumbs($FileName,$SaveTo,$SetW,$SetH){
  6. $IMGInfo= getimagesize($FileName);
  7. if(!$IMGInfo) return false;
  8. if($IMGInfo[mime]== "image/pjpeg" || $IMGInfo[mime]=="image/jpeg"){
  9. $ThisPhoto= imagecreatefromjpeg($FileName);
  10. }elseif($IMGInfo[mime]== "image/x-png" || $IMGInfo[mime]== "image/png"){
  11. $ThisPhoto= imagecreatefrompng($FileName);
  12. }elseif($IMGInfo[mime]== "image/gif"){
  13. $ThisPhoto=imagecreatefromgif($FileName);
  14. }
  15. $width=$IMGInfo[0];
  16. $height=$IMGInfo[1];
  17. $scalc = max($width/$SetW,$height/$SetH);
  18. $nw = intval($width/$scalc);
  19. $nh = intval($height/$scalc);
  20. echo "缩略大小:w$nw,h$nh
    ";
  21. if($SetW-$nw == 1){$nw = $SetW;}
  22. if($SetH-$nh == 1){$nh = $SetH;}
  23. echo "+修正1像素: w$nw,h$nh
    ";
  24. //补宽
  25. if($SetW-$nw > 0){
  26. $nh = $nh +(($nh/$nw) * ($SetW-$nw));
  27. echo "*需补宽".($SetW-$nw).",陪补高".(($nh/$nw) * ($SetW-$nw))."
    ";
  28. $nw = $SetW;
  29. }
  30. //补高
  31. if($SetH-$nh > 0){
  32. $nw = $nw + (($nw/$nh) * ($SetH-$nh));
  33. echo "*需补高".($SetH-$nh).",陪补宽". (($nw/$nh) * ($SetH-$nh)) ."
    ";
  34. $nh = $SetH;
  35. }
  36. $nw = intval($nw);
  37. $nh = intval($nh);
  38. echo "+修正大小:w$nw,h$nh
    ";
  39. $px = ($SetW - $nw)/2;
  40. $py = ($SetH - $nh)/2;
  41. echo "窗口大小:w$SetW,h$SetH
    ";
  42. echo "+偏移修正:x$px,y$py
    ";
  43. $NewPhoto=imagecreatetruecolor($SetW,$SetH);
  44. imagecopyresized($NewPhoto,$ThisPhoto,$px,$py,0,0,$nw,$nh,$width,$height);
  45. ImageJpeg ($NewPhoto,$SaveTo);
  46. return true;
  47. }
  48. thumbs('a.jpg','newa.jpg',150,70);
  49. ?>
复制代码

2,css代码部

复制代码

3,html页面中的图片地址

  1. php缩略图代码,实现满窗格等比例缩小
  2. php缩略图代码,实现满窗格等比例缩小
复制代码


Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan