hanaddi / pena
Simplify the process of writing document as an image using 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: 2025-06-21 02:10:11 UTC
README
Simplify the process of writing document as an image using PHP GD.
Installation
You can add this library to your project using Composer:
composer require hanaddi/pena
Example
Writing simple paragraphs:
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);
Result:
Make a table:
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);
Result: