PHPackages                             erikaheidi/gdaisy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. erikaheidi/gdaisy

ActiveLibrary[Image &amp; Media](/categories/media)

erikaheidi/gdaisy
=================

php-gd templating system

0.3.1(3y ago)80247.7k8MITPHPPHP ^8.1

Since Jun 9Pushed 3y ago2 watchersCompare

[ Source](https://github.com/erikaheidi/gdaisy)[ Packagist](https://packagist.org/packages/erikaheidi/gdaisy)[ RSS](/packages/erikaheidi-gdaisy/feed)WikiDiscussions main Synced today

READMEChangelog (8)Dependencies (2)Versions (12)Used By (0)

 [![gdaisy logo](https://user-images.githubusercontent.com/293241/121391345-8cb16480-c94e-11eb-9f86-1449e81034cc.png)](https://user-images.githubusercontent.com/293241/121391345-8cb16480-c94e-11eb-9f86-1449e81034cc.png)

gdaisy
======

[](#gdaisy)

A highly experimental image templating system based on PHP-GD to dynamically generate image banners and covers. GDaisy also comes with a few sample scripts to generate common size thumbnails via `bin/gdaisy`.

Installation
------------

[](#installation)

### 1. Require `erikaheidi/gdaisy` in your project using Composer:

[](#1-require-erikaheidigdaisy-in-your-project-using-composer)

```
composer require erikaheidi/gdaisy
```

### 2. Once it's installed, you can run the default script to generate an example cover based on meta tags.

[](#2-once-its-installed-you-can-run-the-default-script-to-generate-an-example-cover-based-on-meta-tags)

Gdaisy comes with an example script that generates a header image adequately sized for Twitter, based on a default template. The `vendor/bin/gdaisy generate` script expects the URL to fetch as first parameter and the output path as second parameter, as follows:

```
./vendor/bin/gdaisy generate cover https://www.digitalocean.com/community/tutorials/how-to-set-up-visual-studio-code-for-php-projects output.png
```

This will generate the following image:

 [![gdaisy generated cover image](https://user-images.githubusercontent.com/293241/121399169-77403880-c956-11eb-8aba-f2383e260ef0.png)](https://user-images.githubusercontent.com/293241/121399169-77403880-c956-11eb-8aba-f2383e260ef0.png)

This command is defined in `vendor/erikaheidi/gdaisy/bin/Command/Generate/CoverController.php`, and the JSON template for this cover is defined at `resources/templates/cover-default.json`.

Using GDaisy Scripts
--------------------

[](#using-gdaisy-scripts)

GDaisy comes with a few sample scripts in `bin/Command` based on default templates at `resources/templates`. These commands are available through the `gdaisy` bin script installed with Composer.

### Resize

[](#resize)

Resizes to a specific size, cropping the image to fully fit in the designated area.

```
./vendor/bin/gdaisy resize crop size=[size] input=[path/to/input.png] output=[path/to/output.png]
```

Sizes:

- `avatar`: 150x150
- `square`: 800x800
- `480p`: 640x480
- `720p`: 1280x720
- `1080p`: 1920x1080
- `1440p`: 2560x1440

*Defined in `resources/templates/resize-*.json`:*

### Generate

[](#generate)

Generates a generic banner based on Twitter meta tags in a page, or a page's title and description in case the `twitter:` tags aren't available.

```
./vendor/bin/gdaisy generate cover [URL] [path/to/output.png]
```

Creating Templates
------------------

[](#creating-templates)

In GDaisy, a `Template` is composed by `Placeholders`. A placeholder is like an image layer.

Placeholders must implement the `PlaceholderInterface`. Currently, there are two types of placeholders:

- **Image** - defines a placeholder for an image to be placed on a template, with specific coordinates. Images are automatically cropped/resized to fit the specified area.
- **Text** - defines a placeholder for a text to be placed on a template, with specific coordinates and font settings. Text can be wrapped at a maximum width.

There are two ways of setting up templates. You can programmatically define templates, and/or you can use a JSON file specification.

### Programmatically Defining Templates

[](#programmatically-defining-templates)

For basic templates, for instance to set up a resized thumbnail or add a watermark to an image, you can define the template along in your controller or script code.

```
