idg / idg
文档图像生成器
v1.2
2018-01-26 11:32 UTC
Requires
- php: >=5.6.0
- ext-imagick: *
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-29 05:01:09 UTC
README
快速简单的文档图像生成器。这是一个 Imagick 的包装器,您可以使用它来创建这样的图像
参见:examples/index.php特性
- 任意元素数量和结构
- 支持
padding、margin、border、background和rotation - 可以创建自定义元素
- 计算属性
- 简单的标记(如 html)
- 可以通过 Imagick 方法自定义画布
- 比 html->pdf->image 更快、更优化
要求
PHP 5.6+,需要 Imagick 扩展。
安装
composer require idg/idg
使用方法
<?php require_once __DIR__ . '/vendor/autoload.php'; // font for example $fontRegular = 'RobotoCondensed-Regular.ttf'; $idg = new \Idg\Idg(1000, 3000, null, new ImagickPixel('#fff')); $idg->beginDocument(40, 30, 40, 30); $idg->beginRow(); $idg->beginColumn(300); $idg->image('test_image.jpg'); $idg->beginBlock()->setLeft(20); $idg->text('Figure 1. Dolore eu fugiat nulla pariatur.') ->setFont($fontRegular)->setFontSize(14)->setTextColor('#555'); $idg->endBlock(); $idg->endColumn(); $idg->beginColumn(600); $idg->text('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.') ->setFont($fontRegular); $idg->endColumn(); $idg->endRow(); $idg->endDocument(); $idg->compose(); header('Content-Type: image/' . $idg->getCanvas()->getImageFormat()); print $idg->getImageBlob();
结果
参见:examples/columns.php方法
Idg
Element
元素负责其显示
主要方法
元素属性
填充
边距
边框
背景
旋转
旋转是继承的。
文本(扩展 Element)
填充、边距、边框和背景渐变
参见:examples/properties.php计算属性
// ..... $idg->beginBlock(); $idg->text('Text in block.') ->setMargin(10, 20, 20, 20); $idg->endBlock(); $idg->beginBlock()->setStaticHeight(function(\Idg\Elements\Element $element) { return $element->getPrevSibling()->getHeight(); }); $idg->text('Block with height like prev.') ->setMargin(10, 20, 20, 20); $idg->endBlock(); // .....参见:examples/computed_properties.php
自定义元素
参见:examples/custom_element.php自定义元素必须是 Element(或子类)的实例
/** * Custom element with green background * Class GreenBlock */ class GreenBlock extends \Idg\Elements\Element { /** * @inheritdoc */ function afterRender() { $draw = new \ImagickDraw(); $strokeColor = new \ImagickPixel('green'); $fillColor = new \ImagickPixel('green'); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); $draw->setFillOpacity(0.1); $draw->setStrokeOpacity(1); $draw->setStrokeWidth(2); $draw->rectangle($this->getLeftOffset(), $this->getTopOffset(), $this->getLeftOffset() + $this->getWidth(), $this->getTopOffset() + $this->getHeight()); $this->getIdg()->getCanvas()->drawImage($draw); } } $customBlock = new GreenBlock(); // ..... $idg->beginElement($customBlock)->setTop(20)->setPaddingBottom(25); // ..... $idg->endElement(); // .....
为了更多定制,您可以使用标准的 Imagick 方法
$idg->compose(); $idg->getCanvas()->gaussianBlurImage(10, 20);
捐赠
PayPal: nikitchenko.sergey@yandex.ru
Yandex.Money: 410011704835851