php-quickorm / image-resize
一个由PHP实现的可调整图片大小并添加水印的库
v1.0
2019-02-15 15:35 UTC
This package is auto-updated.
Last update: 2024-09-16 05:16:45 UTC
README
这是什么
这是一个由PHP实现的库,用于 智能调整图片大小 并添加水印。
这个库可以帮助你根据定义的宽度和高度调整图片大小,并智能裁剪以确保长度与宽度的比例,同时添加水印。
要求
- PHP 5 +
- PHP GD
- composer
请确保您已安装php-gd,并建议使用以下命令安装:
apt install php7.0-gd或apt install php5-gd。
安装
以下是两种安装方法:
-
使用composer
composer require php-quickorm/image-resize -
或下载
ImageResize.php到您的项目,并通过require "ImageResize.php";导入它。
用法
调整大小
// Resize the firework.jpg to 800x600 $a = new ImageResize(realpath('firework.jpg'),800,600); // Save to firework2.png; $a->save("firework.png"); // or send as HTTP response $a->render();
水印
// Resize the firework.jpg to 800x600 $a = new ImageResize(realpath('firework.jpg'),800,600); /* * Add text to image * The font size is 1 - 5 and the position only supports bottom-left, bottom-right, top-left, top-right */ // use font size 5, color #ffffff and place at bottom-right with margin 10px $a->addTextMark("Author:Rytia", 5, "#ffffff", "right", "bottom",10); // use font size 4, color #ccccc and place at bottom-left with margin 15px $a->addTextMark("Blog:www.zzfly.net", 4, "#cccccc", "left", "bottom",15); /* * Add water mark to image * The position only supports bottom-left, bottom-right, top-left, top-right */ $a->addImageMark(realpath('mark.jpg'),100,80,"right","bottom",50); // Save to firework2.png; $a->save("firework.png"); // or send as HTTP response $a->render();