https://github.com/dngo-io/cover-creator
Write texts on images with php
https://github.com/dngo-io/cover-creator
image-manipulation image-processing image-text php textview
Last synced: 5 months ago
JSON representation
Write texts on images with php
- Host: GitHub
- URL: https://github.com/dngo-io/cover-creator
- Owner: dngo-io
- License: mit
- Created: 2018-06-17T09:56:03.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-23T09:24:36.000Z (almost 8 years ago)
- Last Synced: 2025-05-07T17:17:00.960Z (about 1 year ago)
- Topics: image-manipulation, image-processing, image-text, php, textview
- Language: PHP
- Homepage:
- Size: 313 KB
- Stars: 3
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### DNGO Book Cover Creator
Usage;
First install package via composer;
```
composer require dngo-io/cover-creator
```
Sample code;
> To use this package, you need to install [PHP GD](http://php.net/manual/en/book.image.php) library to server
```php
require ("vendor/autoload.php");
use DngoIO\CoverCreator\Generator;
$text1 = [
'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
];
$text2 = [
'font-size' => 12, //px
'font-type' => __DIR__ . '../assets/Roboto-Italic.ttf', //path of ttf file on server
'text-color' => [61,183,228],
'left' => 50,
'top' => 30,
];
$config = [
'auto-center' => true,
'angle' => 0,
'header' => 'Content-type: image/jpeg',
];
try {
$generator = new Generator();
$generator->setConfig($config); //or new Generator($config)
$generator->addLine('My First Text', $text1);
$generator->addLine('Second ine Text', $text2);
$generator->generate();
}catch (\Exception $e) {
echo $e->getMessage();
}
```
#### Available Selector Values
| Name | Value | Description |
|-------|---------|---------------|
| font-size | integer | Font size in px. Only integer values |
| font-type | file | Font file on the server. Exact path and file name. |
| text-color | array | text color as RGB |
| left | integer | Margin Left value of text |
| top | integer | Margin Top value of text |
| wrap (optional) | integer | Integer value to wrap text. If disables *auto-center* selector. |
### Availabile Config Values
the ``Generator`` class takes third parameter as configs.
| Name | Value | Description |
|------|--------|-------------|
| auto-center | bool | Enable text center on image |
| angle | integer |Angle of the text on image |
| header | string | default value of header when image generated. default is ``Content-type: image/jpeg`` |
| background-url | file | Background file on the server. Exact path and file name. Should be PNG or JPG |
```
Important: If you wrap the line, auto-center is forced to false.
```
### 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.