php修改上传图片尺寸的方法
程序员文章站
2022-03-14 14:08:26
本文实例讲述了php修改上传图片尺寸的方法。分享给大家供大家参考。具体实现方法如下:
本文实例讲述了php修改上传图片尺寸的方法。分享给大家供大家参考。具体实现方法如下:
<?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程序设计有所帮助。
上一篇: 肚脐竟藏1400种细菌!到底能不能抠?答案是......
下一篇: 鼻窦炎怎么调养比较好
推荐阅读
-
centos 5.6 升级php到5.3的方法_PHP
-
php将字符串随机分割成不同长度数组的方法
-
php随机获取金山词霸每日一句的方法,金山词霸每日一句_PHP教程
-
PHP用身份证号获取星座和生肖的方法
-
php类中的$this,static,final,const,self这几个关键字使用方法_php实例
-
php获取URL中带#号等特殊符号参数的解决方法
-
PHP setcookie指定domain参数后,在IE下设置cookie失效的解决方法
-
浅析PHP函数ereg()的具体使用方法
-
PHP 出现乱码和Sessions验证问题的解决方法!_PHP
-
PHP访问Google Search API的方法,googleapi