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

首頁 > 語言 > PHP > 正文

php 圖片等比例縮放

2024-09-04 11:44:18
字體:
來源:轉載
供稿:網友

php 圖片等比例縮放代碼是一款根據用戶上傳的圖片來指定比例大小的圖片,原理很簡單就是算出圖片大小進等比例就行了,第二款生成小圖是固定圖片大小,但是如何圖片小于設定的圖片就填白,這是一個好方法.

php 圖片等比例縮放實例代碼如下:

  1. <?php 
  2. header("content-type:image/jpeg"); 
  3. $filename = hsdir.'/mljntc2p.jpg'
  4. $im = imagecreatefromjpeg($filename); 
  5. $h=imagesy($im);//獲得目標圖片高度 
  6. $new_img_width  = 257; 
  7. $new_img_height = 522; 
  8.  
  9. $newim = imagecreate($new_img_width$new_img_height); 
  10. $white = imagecolorallocate($newim, 255,255,255); //設置背景顏色 
  11. imagecopyresized($newim$im, 0, 0, 0, 0, $new_img_width$new_img_height$new_img_width$new_img_height); 
  12. imagefilledrectangle($newim,0,$h,$new_img_width,$new_img_height,$white); 
  13. //填充  目標圖片高度作為起駛y坐標 以指定截取寬高為結束坐標 
  14. imagejpeg($newim); 
  15. imagedestroy($newim); 
  16. imagedestroy($im); 
  17. ?> 
  18. 代碼二: 
  19. <?php 
  20. header("content-type:image/jpeg"); 
  21. $filename = 'myface.jpg'
  22. $im = imagecreatefromjpeg($filename); 
  23. $new_img_width  = 80; 
  24. $new_img_height = 150; 
  25. $newim = imagecreate($new_img_width$new_img_height); 
  26. $white = imagecolorallocate($newim, 255,255,255); //設置背景顏色 
  27. imagecopyresized($newim$im, 0, 0, 0, 0, $new_img_width$new_img_height$new_img_width$new_img_height); 
  28. imagejpeg($newim);//開源代碼Vevb.com 
  29. imagedestroy($newim); 
  30. imagedestroy($im); 
  31. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 建瓯市| 北票市| 五寨县| 于田县| 金寨县| 石河子市| 基隆市| 海口市| 武安市| 禹城市| 边坝县| 邯郸市| 会宁县| 慈利县| 永丰县| 肃南| 句容市| 进贤县| 兴化市| 民勤县| 衡南县| 阿鲁科尔沁旗| 阜新市| 澄城县| 洞头县| 绵阳市| 高青县| 峨眉山市| 连江县| 米易县| 大姚县| 巨鹿县| 华阴市| 潢川县| 余江县| 容城县| 德兴市| 贵定县| 响水县| 越西县| 长阳|