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

首頁 > 開發(fā) > PHP > 正文

php修改上傳圖片尺寸的方法

2024-05-04 23:34:15
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php修改上傳圖片尺寸的方法,涉及php操作圖片的技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了php修改上傳圖片尺寸的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

 

 
  1. <?php 
  2. // This is the temporary file created by PHP 
  3. $uploadedfile = $_FILES['uploadfile']['tmp_name']; 
  4. // Create an Image from it so we can do the resize 
  5. $src = imagecreatefromjpeg($uploadedfile); 
  6. // Capture the original size of the uploaded image 
  7. list($width,$height)=getimagesize($uploadedfile); 
  8. // For our purposes, I have resized the image to be 
  9. // 600 pixels wide, and maintain the original aspect 
  10. // ratio. This prevents the image from being "stretched" 
  11. // or "squashed". If you prefer some max width other than 
  12. // 600, simply change the $newwidth variable 
  13. $newwidth=600; 
  14. $newheight=($height/$width)*600; 
  15. $tmp=imagecreatetruecolor($newwidth,$newheight); 
  16. // this line actually does the image resizing, copying from the original 
  17. // image into the $tmp image 
  18. imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 
  19. // now write the resized image to disk. I have assumed that you want the 
  20. // resized, uploaded image file to reside in the ./images subdirectory. 
  21. $filename = "images/"$_FILES['uploadfile']['name']; 
  22. imagejpeg($tmp,$filename,100); 
  23. imagedestroy($src); 
  24. imagedestroy($tmp); 
  25. // NOTE: PHP will clean up the temp file it created when the request 
  26. // has completed. 
  27. ?> 

希望本文所述對大家的php程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 汝阳县| 潢川县| 无极县| 江安县| 西丰县| 兰坪| 临桂县| 西乌珠穆沁旗| 闽清县| 崇左市| 安平县| 合阳县| 光泽县| 武夷山市| 滕州市| 英山县| 黄山市| 翼城县| 岫岩| 封开县| 扎兰屯市| 邢台市| 黎城县| 南京市| 娄底市| 迁安市| 高雄市| 柘荣县| 仙游县| 兰溪市| 大埔县| 淄博市| 北海市| 剑河县| 曲麻莱县| 鄯善县| 祁门县| 梁平县| 永新县| 任丘市| 福泉市|