bencagri avatar

Book Cover Creator for DNGO

bencagri

Published: 17 Jun 2018 › Updated: 17 Jun 2018Book Cover Creator for DNGO

Book Cover Creator for DNGO

DNGO Book Cover Creator

This is a package for DNGO Book Cover Image Creator Task

Dngo books is Dngo’s first project that is specifically intended to incentivise people to collectively create multilingual audiobook archives – mainly to serve people with a visual impairment.

Read more on introduction post.

Package Usage;

To use this package, you need to install PHP GD library to server

First install package via composer;

composer require dngo-io/cover-creator

Sample code;

require ("vendor/autoload.php");


use DngoIO\CoverCreator\Generator;

$selectors = [
        'font-size' => 18,  //px
        'font-type' => __DIR__ . '../assets/Roboto-Regular.ttf', //path of ttf file on server
        'text-color' => [61,183,228],
        'left' => 0,
        'top' => 0,
        'background-url' => __DIR__ . '../assets/background.jpg' //path of the png
    ];


try {
    $generator = new Generator("My Text On Image", $selectors);
    $generator->generate();
}catch (\Exception $e) {
    echo $e->getMessage();
}

Available Selector Values

NameValueDescription
font-sizeintegerFont size in px. Only integer values
font-typefileFont file on the server. Exact path and file name.
text-colorarraytext color as RGB
leftintegerMargin Left value of text
topintegerMargin Top value of text
background-urlfileBackgroun file on the server. Exact path and file name. Should be PNG or JPG

Availabile Config Values

the Generator class takes third parameter as configs.

NameValueDescription
auto-centerboolEnable text center on image
angleintegerAngle of the text on image
headerstringdefault value of header when image generated. default is Content-type: image/jpeg

Error Handling

CoverCreator has 2 exceptions.
InvalidFileException is thrown when the background image is not ok.
InvalidTypeException is thrown when any of selector value is not valid.

Pull Request

https://github.com/dngo-io/cover-creator/pull/1

Leave Book Cover Creator for DNGO to:

Written by

Back-end developer

Read more #utopian-io posts


Best Posts From bencagri

We have not curated any of bencagri's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From bencagri