hanaddi / pena
使用PHP GD简化将文档作为图片编写的流程。
1.0.7
2024-06-16 06:18 UTC
Requires
- php: >=7.4.0
- ext-gd: *
Requires (Dev)
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: 9.6.19
This package is auto-updated.
Last update: 2024-09-21 00:34:32 UTC
README
使用PHP GD简化将文档作为图片编写的流程。
安装
您可以使用 Composer 将此库添加到您的项目中。
composer require hanaddi/pena
示例
编写简单段落
use Hanaddi\Pena; $doc = new Pena([400, 300], ['margin' => 10]); $text = "eget nulla facilisi etiam dignissim diam quis enim lobortis scelerisque fermentum dui faucibus in ornare " . "quam viverra orci sagittis eu volutpat odio facilisis mauris sit amet massa vitae tortor condimentum"; $doc->write($text, ["align" => "center", "lspace" => 1.5]) ->lineSpace() ->write($text, ["color" => [255, 0, 0], "lspace" => 1.5]) ->lineSpace() ->write($text, ["align" => "justify", "lspace" => 1.5, "bgcolor" => [0, 255, 255]]); // Output as image header('Content-Type: image/png'); imagepng($doc->document); imagedestroy($doc->document);
结果
创建表格
use Hanaddi\Pena; $doc = new Pena([300, 150], ['margin' => 10]); $doc->tableNew( [ 'columns' => 2, 'width' => 280, 'cellwidth' => [1, 3], 'padding' => 10, ]) ->tableRow( [['text' => 'No.'], ['text' => 'Name']], ['bgcolor' => [250, 200, 0], 'align' => 'center'] ) ->tableRow([['text' => '1.'], ['text' => 'Alpha']]) ->tableRow([['text' => '2.'], ['text' => 'Beta']]) ->tableRow([['text' => '3.'], ['text' => 'Charlie']]) ->tableDraw(); // Output as image header('Content-Type: image/png'); imagepng($doc->document); imagedestroy($doc->document);
结果