1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > PHP 生成图片缩略图函数

PHP 生成图片缩略图函数

时间:2021-01-18 13:39:09

相关推荐

PHP 生成图片缩略图函数

后端开发|php教程

生成,图片,函数,缩略图,php

后端开发-php教程

各位小盆友使用前记得打开 GD 库的支持哦,附上代码。

在线制作 php源码,VScode合并分支插件,nexus装ubuntu,tomcat 编译文件,检索 爬虫,php 设置代理,怎么seo排名在线咨询,网站特效 鼠标过字放大,whmcs手机版模板lzw

<?php/** * 生成缩略图函数(支持图片格式:gif、jpeg、png和bmp) * @author ruxing.li * @param string $src源图片路径 * @param int $width 缩略图宽度(只指定高度时进行等比缩放) * @param int $width 缩略图高度(只指定宽度时进行等比缩放) * @param string $filename 保存路径(不指定时直接输出到浏览器) * @return bool */function mkThumbnail($src, $width = null, $height = null, $filename = null) { if (!isset($width) && !isset($height)) return false; if (isset($width) && $width <= 0) return false; if (isset($height) && $height <= 0) return false; $size = getimagesize($src); if (!$size) return false; list($src_w, $src_h, $src_type) = $size; $src_mime = $size[mime]; switch($src_type) { case 1 : $img_type = gif; break; case 2 : $img_type = jpeg; break; case 3 : $img_type = png; break; case 15 : $img_type = wbmp; break; default : return false; } if (!isset($width)) $width = $src_w * ($height / $src_h); if (!isset($height)) $height = $src_h * ($width / $src_w); $imagecreatefunc = imagecreatefrom . $img_type; $src_img = $imagecreatefunc($src); $dest_img = imagecreatetruecolor($width, $height); imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $width, $height, $src_w, $src_h); $imagefunc = image . $img_type; if ($filename) { $imagefunc($dest_img, $filename); } else { header(Content-Type: . $src_mime); $imagefunc($dest_img); } imagedestroy($src_img); imagedestroy($dest_img); return true;}$result = mkThumbnail(./IMG_3324.JPG, 147, 147);

声明:本文出自 CSDN,转载请注明出处!

cctv源码百度网盘,ubuntu永久激活方法,tomcat安装了怎么找,python爬虫老师,php开发的商城系统,seo龙头lzw

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