源文件,目标文件,目标宽,目标高,是否允许剪裁。 如果目标写入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; }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
