国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php實現圖片按比例截取的方法

2024-09-04 11:44:40
字體:
來源:轉載
供稿:網友
  1. filename ='img/test.jpg' 
  2. $all_type=array
  3. "jpg" =>array("create"=>"ImageCreateFromjpeg","output"=>"imagejpeg" ,"exn"=>".jpg"), 
  4. "gif" =>array("create"=>"ImageCreateFromGIF","output"=>"imagegif" ,"exn"=>".gif"), 
  5. "jpeg" =>array("create"=>"ImageCreateFromjpeg","output"=>"imagejpeg" ,"exn"=>".jpg"), 
  6. "png" =>array("create"=>"imagecreatefrompng","output"=>"imagepng" ,"exn"=>".png"), 
  7. "wbmp" =>array("create"=>"imagecreatefromwbmp","output"=>"image2wbmp","exn"=>".wbmp"
  8. ); 
  9. $imgtype=getimagesize($filename); 
  10. $width=$imgtype[0]; 
  11. $height=$imgtype[1]; 
  12. $type=str_replace('image/','',$imgtype['mime']); 
  13. $func_create=$all_type[$type]['create']; 
  14. $func_output=$all_type[$type]['output']; 
  15. $x=$y=0; 
  16. if(($width* 100)>($height* 120)) 
  17. $newwidth=ceil($height* 120/100); 
  18. $newheight=$height
  19. $x= ($width-$newwidth)/2; 
  20. elseif(($width* 100)<($height* 120)) 
  21. $newheight=ceil($width* 100/120); 
  22. $newwidth=$width
  23. $y= ($height-$newheight)/2; 
  24. else 
  25. $newheight=$height
  26. $newwidth=$width
  27. // Load 
  28. $thumb= imagecreatetruecolor($newwidth,$newheight); 
  29. $source=$func_create($filename); 
  30. // Resize 
  31. imagecopyresized($thumb,$source, 0, 0, 0, 0,$newwidth,$newheight,$newwidth,$newheight); 
  32. // Output 
  33. $func_output($thumb,'a.jpeg'); 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海林市| 康保县| 房产| 花垣县| 晋城| 密云县| 邵阳市| 彭泽县| 临漳县| 定安县| 获嘉县| 行唐县| 银川市| 灌云县| 东莞市| 启东市| 蓬莱市| 买车| 称多县| 依安县| 嘉荫县| 龙胜| 雷波县| 蒲江县| 通榆县| 乐至县| 霞浦县| 盖州市| 镇坪县| 东乡县| 汝州市| 新野县| 内乡县| 丹寨县| 沾益县| 五指山市| 鄂伦春自治旗| 酒泉市| 大新县| 寻乌县| 康乐县|