700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 关于php图片等比例缩放函数的.谁能帮看看这个函数的用法啊?

关于php图片等比例缩放函数的.谁能帮看看这个函数的用法啊?

时间:2021-03-06 08:08:35

相关推荐

关于php图片等比例缩放函数的.谁能帮看看这个函数的用法啊?

后端开发|php教程

php

后端开发-php教程

系统之家第三版源码,vscode创建作者,ubuntu gebi,tomcat ie 兼容,sqlite 文件名后缀,wp第三方评论插件破解版,框架可以直接拿来写前端吗,哪种语言最适合爬虫,php获取图片的宽,大同seo优化方法,jq 网站头部广告代码,html5营销网页模板,magento2 免费模板lzw

function resize($srcImage,$toFile,$maxWidth = 100,$maxHeight = 100,$imgQuality=100) { list($width, $height, $type, $attr) = getimagesize($srcImage);if($width < $maxWidth || $height < $maxHeight) return ;switch ($type) {case 1: $img = imagecreatefromgif($srcImage); break;case 2: $img = imagecreatefromjpeg($srcImage); break;case 3: $img = imagecreatefrompng($srcImage); break;}$scale = min($maxWidth/$width, $maxHeight/$height); //求出绽放比例if($scale < 1) {$newWidth = floor($scale*$width);$newHeight = floor($scale*$height);$newImg = imagecreatetruecolor($newWidth, $newHeight);imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);$newName = "";$toFile = preg_replace("/(.jpg|.jpg|.jpeg|.jpg)/i","",$toFile);switch($type) { case 1: if(imagegif($newImg, "$toFile$newName.jpg", $imgQuality)) return "$newName.jpg"; break; case 2: if(imagejpeg($newImg, "$toFile$newName.jpg", $imgQuality)) return "$newName.jpg"; break; case 3: if(imagepng($newImg, "$toFile$newName.jpg", $imgQuality)) return "$newName.jpg"; break; default: if(imagejpeg($newImg, "$toFile$newName.jpg", $imgQuality)) return "$newName.jpg"; break;}imagedestroy($newImg);}imagedestroy($img);return false; }其中 $toFile = preg_replace("/(.jpg|.jpg|.jpeg|.jpg)/i","",$toFile);具体目的是什么?

用e写的资源管理器(源码),ubuntu系统保存指令,tomcat启动不成功超时,爬虫教程python,仿微信聊天PHP源码,太原seo营销lzw

回复内容:

盗版源码,ubuntu 安装 群晖,微服务架构 爬虫,php ,seo计费软件lzw

function resize($srcImage,$toFile,$maxWidth = 100,$maxHeight = 100,$imgQuality=100) { list($width, $height, $type, $attr) = getimagesize($srcImage);if($width < $maxWidth || $height < $maxHeight) return ;switch ($type) {case 1: $img = imagecreatefromgif($srcImage); break;case 2: $img = imagecreatefromjpeg($srcImage); break;case 3: $img = imagecreatefrompng($srcImage); break;}$scale = min($maxWidth/$width, $maxHeight/$height); //求出绽放比例if($scale < 1) {$newWidth = floor($scale*$width);$newHeight = floor($scale*$height);$newImg = imagecreatetruecolor($newWidth, $newHeight);imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);$newName = "";$toFile = preg_replace("/(.jpg|.jpg|.jpeg|.jpg)/i","",$toFile);switch($type) { case 1: if(imagegif($newImg, "$toFile$newName.jpg", $imgQuality)) return "$newName.jpg"; break; case 2: if(imagejpeg($newImg, "$toFile$newName.jpg", $imgQuality)) return "$newName.jpg"; break; case 3: if(imagepng($newImg, "$toFile$newName.jpg", $imgQuality)) return "$newName.jpg"; break; default: if(imagejpeg($newImg, "$toFile$newName.jpg", $imgQuality)) return "$newName.jpg"; break;}imagedestroy($newImg);}imagedestroy($img);return false; }其中 $toFile = preg_replace("/(.jpg|.jpg|.jpeg|.jpg)/i","",$toFile);具体目的是什么?

因为tofile($srcImage,$toFile)第二个参数$toFile自己指定的话存在格式问题,比如srcImage是jpg,但是如果你填写的toFile是png,那格式就对不上了,因此如果你制定了toFile的文件后缀,那就直接干掉,然后在直接将原图片的格式追加在你指定的toFile后面。

简单来说:

tofile(‘a.jpg’,’b.jpg’);

最终生成的是b.jpg而不是b.jpg

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。