php修改上傳圖片尺寸的方法
更新時(shí)間:2015年04月14日 14:57:42 作者:不吃皮蛋
這篇文章主要介紹了php修改上傳圖片尺寸的方法,涉及php操作圖片的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了php修改上傳圖片尺寸的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
<?php // 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程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP里面把16進(jìn)制的圖片數(shù)據(jù)顯示在html的img標(biāo)簽上(實(shí)現(xiàn)方法)
下面小編就為大家?guī)硪黄狿HP里面把16進(jìn)制的圖片數(shù)據(jù)顯示在html的img標(biāo)簽上(實(shí)現(xiàn)方法)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05php實(shí)現(xiàn)在多維數(shù)組中查找特定value的方法
這篇文章主要介紹了php實(shí)現(xiàn)在多維數(shù)組中查找特定value的方法,實(shí)例分析了php實(shí)現(xiàn)多維數(shù)組的遍歷及unset刪除的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07使用JSON實(shí)現(xiàn)數(shù)據(jù)的跨域傳輸?shù)膒hp代碼
某網(wǎng)站后臺用php腳本得到一個(gè)JSON格式的數(shù)據(jù),交給前臺javascript進(jìn)行處理,使用JSON實(shí)現(xiàn)數(shù)據(jù)的跨域調(diào)用2011-12-12php park、unpark、ord 函數(shù)使用方法(二進(jìn)制流接口應(yīng)用實(shí)例)
在工作中,我也逐漸了解到park,unpark,ord對于二進(jìn)制字節(jié)處理的強(qiáng)大。 下面我逐一介紹它們。2010-10-10