w3cschool php 调整图片尺寸,PHP_php修改上传图片尺寸的方法,本文实例讲述了php修改上传图 - phpStudy...
php修改上傳圖片尺寸的方法
本文實例講述了php修改上傳圖片尺寸的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=600;
$newheight=($height/$width)*600;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "images/". $_FILES['uploadfile']['name'];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
// NOTE: PHP will clean up the temp file it created when the request
// has completed.
?>
希望本文所述對大家的php程序設計有所幫助。相關閱讀:
java實現(xiàn)檢測是否字符串中包含中文
.net泛型通用函數(shù)的特殊問題的解決方法
Win10如何使用禁用cleartype以清晰地顯示屏幕內容
ASP.NET中DropDownList和ListBox實現(xiàn)兩級聯(lián)動功能
JS實現(xiàn)獲取當前URL和來源URL的方法
Android自定義控件之自定義屬性(二)
jQuery 的全選(全非選)即取得被選中的值使用介紹
jQuery中triggerHandler()方法用法實例
win7系統(tǒng)無法啟動power服務提示錯誤2系統(tǒng)找不到指定文件的解決方法
linux系統(tǒng)掛載以及卸載USB接口的設備的解決辦法
C#探秘系列(一)——ToDictionary,ToLookup
jQuery實現(xiàn)帶動畫效果的二級下拉導航方法
window.open打開窗口被攔截的快速解決方法
修改Laravel5.3中的路由文件與路徑
總結
以上是生活随笔為你收集整理的w3cschool php 调整图片尺寸,PHP_php修改上传图片尺寸的方法,本文实例讲述了php修改上传图 - phpStudy...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为Mate50系列手机壳曝光:Pro版
- 下一篇: iPhone 14还没上市就砍单10%