xepan/php-image

PHP的GD库包装器,用于简单图像处理,源自kus/php-image

dev-master 2016-03-19 13:18 UTC

This package is not auto-updated.

Last update: 2024-09-26 00:21:31 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();

Overlay and text

链式操作

	(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();

400x400 400x200 200x400 100x100

多行文本框,具有自动换行和自动字体缩放以适应边界

	$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();

Multiline auto fit text

文本框自动适应文本(可变字体大小)

	$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许可证的双重许可。

特此授予任何获取本软件及其相关文档文件(“软件”)副本的任何人无限制地处理软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向提供软件的人员授权这样做,但受以下条件约束

上述版权声明和本许可声明应包含在软件的所有副本或实质性部分中。

本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和非侵权性保证。在任何情况下,作者或版权所有者不应对任何索赔、损害或其他责任负责,无论这些责任是因合同、侵权或其他方式而产生的,与软件或软件的使用或其他方式有关。