floor12/imagenator

PHP library for generate image with a article title to use it in OpenGraph.

dev-master 2020-04-20 08:36 UTC

This package is auto-updated.

Last update: 2024-12-20 19:44:00 UTC


README

Build Status Scrutinizer Code Quality

Этот файл доступен на русском языке.

Description

PHP library for generate image with a article title to use it in OpenGraph. It takes PNG image is a background and put text on it. The text position, size, font, color and other parameters. In addition, the library correctly processes "hanging prepositions": it wrap words shorter than 3 letters to the next line, if it exists.

For example:

FileInputWidget

FileInputWidget

Installation

Add this library to your project

$ composer require floor12/imagenator

or add this to the require section of your composer.json.

"floor12/imagenator": "dev-master"

Using

Pass background PNG file path to the class constructor:

use floor12\imagenator\Imagenator;

$imagenator = new Imagenator('/project/images/image.png');

Then, you can setup any of additional parameters using some setters:

$imagenator
    ->setColor('FF04AB')                    // Font color in HEX format;
    ->setFont('/fonts/SomeFont.ttf')        // Path to custom font;
    ->setFontSize(3)                        // Font size in percent of image height;
    ->setPadding(5)                         // Horizontal padding in percent of image width;
    ->setMarginTopInPercents(50)            // Margin from top image edge in percent of image height;
    ->setRowHeight(7)                       // Row height in percent of image height;
    ->setText('This is an article title.'); // Text to put over the image;

After that, you can generate result PNG image:

$imagenator->generate('/resultImage.png');