kus / php-image
PHP的GD库包装器,用于轻松进行图像处理
dev-master
2023-03-27 09:16 UTC
Requires
- php: >=5.3.0
- ext-gd: *
This package is not auto-updated.
Last update: 2024-09-14 11:02:58 UTC
README
它做什么?
PHP的GD库包装器,用于轻松进行图像处理,包括调整大小、裁剪和叠加图像以保留透明度,使用描边和透明度书写文本以及绘制形状。
安装
将PHP文件放在您的服务器上,并在脚本中包含它或通过composer
下载:require: "kus/php-image": "dev-master"
。
使用方法
示例
$bg = './img/benji.jpg'; $overlay = './img/paw.png'; $image = new PHPImage(); $image->setDimensionsFromImage($bg); $image->draw($bg); $image->draw($overlay, '50%', '75%'); $image->rectangle(40, 40, 120, 80, array(0, 0, 0), 0.5); $image->setFont('./font/arial.ttf'); $image->setTextColor(array(255, 255, 255)); $image->setStrokeWidth(1); $image->setStrokeColor(array(0, 0, 0)); $image->text('Hello World!', array('fontSize' => 12, 'x' => 50, 'y' => 50)); $image->text('This is a big sentence with width 200px', array( 'fontSize' => 60, // Desired starting font size 'x' => 300, 'y' => 0, 'width' => 200, 'height' => 50, 'alignHorizontal' => 'center', 'alignVertical' => 'center', 'debug' => true )); $image->text('This is a big sentence', array( 'fontSize' => 60, // Desired starting font size 'x' => 300, 'y' => 200, 'width' => 200, 'height' => 50, 'alignHorizontal' => 'center', 'alignVertical' => 'center', 'debug' => true )); $image->textBox('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', array('width' => 100, 'fontSize' => 8, 'x' => 50, 'y' => 70)); $image->rectangle(40, 140, 170, 160, array(0, 0, 0), 0.5); $image->textBox('Auto wrap and scale font size to multiline text box width and height bounds. Vestibulum venenatis risus scelerisque enim faucibus, ac pretium massa condimentum. Curabitur faucibus mi at convallis viverra. Integer nec finibus ligula, id hendrerit felis.', array( 'width' => 150, 'height' => 140, 'fontSize' => 16, // Desired starting font size 'x' => 50, 'y' => 150 )); $image->show();
链式操作
(new PHPImage('./img/benji.jpg'))->resize(200, 200, 'C', true)->show();
可选裁剪和放大批处理调整大小
$image = new PHPImage('./img/benji.jpg'); $image->batchResize('examples/thumb_%dx%d.jpg', array( array(400, 400, true, true), array(200, 400, true, true), array(400, 200, true, true), array(100, 100, true, true), )); $image->resize(100, 100, true, true)->show();
多行文本框,具有自动换行和自动字体缩放以适应边界
$image = new PHPImage(400, 400); $image->rectangle(0, 0, 100, 200, array(0, 0, 0), 0.5); $image->setFont('./font/arial.ttf'); $image->setTextColor(array(255, 255, 255)); $image->setStrokeWidth(1); $image->setStrokeColor(array(0, 0, 0)); $image->textBox('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam molestie tortor quam, at congue nibh imperdiet dapibus.', array( 'width' => 100, 'height' => 100, 'fontSize' => 16, // Desired starting font size 'x' => 50, 'y' => 200 )); $image->show();
文本框自动适应文本(可变字体大小)
$image = new PHPImage(400, 400); $image->setFont('./font/arial.ttf'); $image->setTextColor(array(255, 255, 255)); $image->text('This is a big sentence', array( 'fontSize' => 60, // Desired starting font size 'x' => 0, 'y' => 0, 'width' => 400, 'height' => 200, 'alignHorizontal' => 'center', 'alignVertical' => 'center', 'debug' => true )); $image->text('BIG', array( 'fontSize' => 120, // Desired starting font size 'x' => 0, 'y' => 200, 'width' => 400, 'height' => 200, 'alignHorizontal' => 'center', 'alignVertical' => 'center', 'debug' => true )); $image->show();
版权
版权(c)2015 Blake Kus blakek.us
本插件受MIT和GPL版本2许可证的双重许可。
特此授予任何获得本软件及其相关文档文件(“软件”)副本的任何人免费使用软件的权利,不受任何限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本的权利,并允许向软件提供的人士行使这些权利,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和无侵犯性的保证。在任何情况下,作者或版权所有者不应对任何索赔、损害或其他责任负责,无论该索赔、损害或其他责任是基于合同、侵权或其他方式,是否因软件或其使用或其他原因而产生。