源文件,目标文件,目标宽,目标高,是否允许剪裁。 如果目标写入null直接二进制输出。不生成文件。 无 function img2thumb($src_img, $dst_img, $width = 64, $height = 64, $nocut = 0) {/*if(!is_file($src_img)) return false;*/if(!($width*$height)) re
源文件,目标文件,目标宽,目标高,是否允许剪裁。
如果目标写入 null 直接二进制输出。不生成文件。
function img2thumb($src_img, $dst_img, $width = 64, $height = 64, $nocut = 0) { /* if(!is_file($src_img)) return false; */ if(!($width*$height)) return false; $ext = strtolower(substr(strrchr($src_img, '.'),1)); if(!$ext) return false; $otfunc = 'image' . ($ext == 'jpg' ? 'jpeg' : $ext); if(!function_exists($otfunc)) return false; $srcinfo = getimagesize($src_img); if(!$srcinfo) return false; $src_w = $srcinfo[0]; $src_h = $srcinfo[1]; $type = strtolower(substr(image_type_to_extension($srcinfo[2]), 1)); $openfunc = 'imagecreatefrom' . ($type == 'jpg' ? 'jpeg' : $type); if(!function_exists($openfunc)) return false; $createfunc = 'imagecreate'; $buildfunc = 'imagecopyresized'; $x=$y=0; $src_t = $src_w / $src_h; if($src_t > $width / $height) { $dst_w = $width; $dst_h = $width / $src_t; $nocut && $y = ($height - $dst_h)/2; } else { $dst_w = $src_t * $height; $dst_h = $height; $nocut && $x = ($width - $dst_w)/2; } $src = $openfunc($src_img); $dst = $createfunc($nocut ? $width :$dst_w, $nocut ? $height :$dst_h); $white = imagecolorallocate($dst, 255, 255, 255); $buildfunc($dst, $src, $x, $y, 0, 0, $dst_w, $dst_h, $src_w, $src_h); $otfunc($dst, $dst_img); imagedestroy($dst); imagedestroy($src); return true; }
<?php // 更新,增加参数 $watermark, 如果这个文件是可用的,将作为水印加在图片上,$wmpct透明度. function img2thumb($src_img, $dst_img, $width=64, $height=64, $nocut=0, $watermark=null, $wmpct=50) { /* if(!is_file($src_img)) return false; */ if(!($width*$height)) return false; $ext = strtolower(substr(strrchr($src_img, '.'),1)); if(!$ext) return false; $otfunc = 'image' . ($ext == 'jpg' ? 'jpeg' : $ext); if(!function_exists($otfunc)) return false; $srcinfo = getimagesize($src_img); if(!$srcinfo) return false; $src_w = $srcinfo[0]; $src_h = $srcinfo[1]; $type = strtolower(substr(image_type_to_extension($srcinfo[2]), 1)); $openfunc = 'imagecreatefrom' . ($type == 'jpg' ? 'jpeg' : $type); if(!function_exists($openfunc)) return false; $wmfunc = ''; if($watermark) { $wminfo=getimagesize($watermark); if($wminfo) { $wm_w = $wminfo[0]; $wm_h = $wminfo[1]; $wmtype = strtolower(substr(image_type_to_extension($wminfo[2]), 1)); $wmfunc = 'imagecreatefrom' . ($wmtype == 'jpg' ? 'jpeg' : $wmtype); if(function_exists($wmfunc)) { } } } $createfunc = 'imagecreate'; $buildfunc = 'imagecopyresized'; $x=$y=0; $src_t = $src_w / $src_h; if($src_t > $width / $height) { $dst_w = $width; $dst_h = $width / $src_t; $nocut && $y = ($height - $dst_h)/2; } else { $dst_w = $src_t * $height; $dst_h = $height; $nocut && $x = ($width - $dst_w)/2; } if(!$dst_img) { header ( "Content-type: " . image_type_to_mime_type( IMAGETYPE_JPEG )); } $src = $openfunc($src_img); $dst = $createfunc($nocut ? $width :$dst_w, $nocut ? $height :$dst_h); $white = imagecolorallocate($dst, 255, 255, 255); $buildfunc($dst, $src, $x, $y, 0, 0, $dst_w, $dst_h, $src_w, $src_h); imagedestroy($src); // 水印 if($wmfunc && function_exists($wmfunc)) { $wm = $wmfunc($watermark); imagecopymergegray($dst, $wm, $x+$dst_w-$wm_w, $y+$dst_h-$wm_h, 0, 0, $wm_w, $wm_h, $wmpct); imagedestroy($wm); } $otfunc($dst, $dst_img); imagedestroy($dst); return true; }
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
<🎜>:种植花园 - 完整的突变指南
3 周前ByDDD
<🎜>:泡泡胶模拟器无穷大 - 如何获取和使用皇家钥匙
3 周前By尊渡假赌尊渡假赌尊渡假赌
如何修复KB5055612无法在Windows 10中安装?
3 周前ByDDD
北端:融合系统,解释
3 周前By尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

记事本++7.3.1
好用且免费的代码编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。