floor12/imagenator

用于生成图像的PHP库,用于在OpenGraph中使用,其中包含文章标题。

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

This package is auto-updated.

Last update: 2024-09-20 19:08:45 UTC


README

Build Status Scrutinizer Code Quality

此文件可用俄语阅读

描述

PHP库用于生成图像,其中包含文章标题,可用于OpenGraph。它以PNG图像为背景,并在其上放置文本。文本的位置、大小、字体、颜色和其他参数。此外,该库正确处理“悬挂介词”:如果存在,它会将小于3个字母的单词换行。

例如

FileInputWidget

FileInputWidget

安装

将此库添加到您的项目中

$ composer require floor12/imagenator

或将以下内容添加到您的composer.json文件中的require部分。

"floor12/imagenator": "dev-master"

使用

将背景PNG文件路径传递给类的构造函数

use floor12\imagenator\Imagenator;

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

然后,您可以使用一些设置器设置任何其他附加参数

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

之后,您可以生成结果PNG图像

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