php-gd based image templates

Overview

gdaisy logo

gdaisy

A highly experimental image templating system based on PHP-GD to dynamically generate image banners and covers.

Installation

1. Require erikaheidi/gdaisy 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.

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

The example generation script is defined in vendor/erikaheidi/gdaisy/bin/gdaisy.

Creating Templates

Consider the following basic.json template example:

{
  "width": 600,
  "height": 600,
  "background": "FFFFFF",
  "elements": {
    "title": {
      "type": "text",
      "properties": {
        "pos_x": 50,
        "pos_y": 20,
        "size": 30,
        "color": "666666",
        "max_width": 500,
        "align": "center"
      }
    },
    "thumbnail": {
      "type": "image",
      "properties": {
        "pos_x": 50,
        "pos_y": 50,
        "width": 500,
        "height": 500
      }
    }
  }
}

This template has two elements: title (type text) and thumbnail (type image).

Template Properties:

  • width: Resulting image width
  • height: Resulting image height
  • background: Resulting image background

Text Properties:

  • pos_x: X coordinate (bottom left X coordinate for the base of text)
  • pos_y: Y coordinate (botom left Y coordinate for the base of text)
  • size: Text size
  • color: Text Color (hex)
  • max_width (optional): Maximum text width - text will be broken down into multiple lines when set
  • align (optional): Text align, possible values are left(default), center, or right.
  • font: path to font file (ttf)

Image Properties:

  • pos_x: X coordinate (top left corner) where the image will be applied
  • pos_y: Y coordinate (top left corner) where the image will be applied,
  • width: width (will proportially resize to fit)
  • height: height (will proportially resize to fit)
  • image_file (optional): when set, will use this image, otherwise you'll have to provide this as parameter when applying the template
  • crop (optional): when set to center, will resize-crop while centering the image. Default is left, can also be set to right.

Following, a PHP script to generate a new image based on the example template:

<?php

use GDaisy\Template;

require __DIR__. '/vendor/autoload.php';

$template = Template::create(__DIR__ . '/resources/templates/basic.json');

$template->apply("thumbnail", [
    "image_file" => __DIR__ . '/resources/images/gdaisy.png'
])->apply("title", [
    "text" => "generated with gdaisy"
]);

$template->write('output.png');
echo "Finished.\n";
You might also like...
image sharing site made in PHP just for fun and freetime
image sharing site made in PHP just for fun and freetime

2bart image sharing site made in PHP just for fun and freetime To-do list: upload system [DONE] ✔️ views system [DONE] ✔️ image list system [DONE] ✔️

This is an image manipulation REST API written in PHP Laravel Framework

Laravel Image Manipulation REST API Demo Here is fully working Demo: https://www.lobiimages.com/ You have to register first in order to generate acces

PHP Thumb is a light-weight image manipulation library aimed at thumbnail generation

PHP Thumb NOTICE - This project was recently updated to 2.0 and is PSR-0 compliant and supports Composer integration. Some parts of the documentation

Image manager extension for the Yii PHP framework.

yii-imagemanager Image manager extension for the Yii PHP framework. Introduction I started this project to reduce the need for boilerplate code when w

Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

Image Optimizer This library is handy and very easy to use optimizer for image files. It uses optipng, pngquant, jpegoptim, svgo and few more librarie

:racehorse: find the size of an image without downloading the whole file. Supports batch requests.

FasterImage FasterImage finds the dimensions or filetype of a remote image file given its uri by fetching as little as needed, based on the excellent

Extract colors from an image like a human would do.

ColorExtractor Extract colors from an image like a human would do. Install Via Composer $ composer require league/color-extractor:0.3.* Usage require

 An open source image hosting service powered by Laravel
An open source image hosting service powered by Laravel

Limg An open source image hosting service powered by Laravel Features Upload your image via file, url or ShareX ! Manage your image (custom title, pub

A simple page view counter that store data as text and shows data as a PNG image

Image Counter A simple page view counter that store data as text and shows the counter as a PNG image.

Comments
  • Updates tests to use Higher Order Expectations

    Updates tests to use Higher Order Expectations

    Hi Erika,

    You mentioned the other day about this on Twitter, and it looked cool so wanted to contribute! I've refactored the Pest suite to the new Higher Order Expectations, which removes some of the boilerplate.

    Hope you had a good weekend!

    Kind regards, Luke

    opened by lukeraymonddowning 1
  • Add support for PHP8

    Add support for PHP8

    This PR adds support for PHP8, which gdaisy doesn't currently have. minicli supports PHP8 though, so gdaisy doesn't have any requirements that interfere with PHP8.

    I did run the test suite on PHP 8.0.7 and got all greens, also symlinked this branch locally and went through requiring it and generating an image, and everything went smoothly there. 👍

    Screen Shot 2021-06-11 at 7 50 24 PM

    opened by thinkverse 1
  • Switch from `/usr/bin` to `/usr/bin/env`

    Switch from `/usr/bin` to `/usr/bin/env`

    This PR switches bin/gdaisy to use /usr/bin/env php instead of /usr/bin/php, this lets the end-users environment pick which PHP version to use via its PATH, as oppose to gdaisy pointing to a specific version.

    For me, this fixes the issue of gdaisy using the built-in PHP 7.1 instead of my homebrew versions, causing me to manually change the vendor file directly to get it to work instead of throwing parse errors.

    Screen Shot 2021-06-09 at 10 04 31 PM

    This is also an accepted practice, Laravel's artisan command uses this shebang, as well as Symfony in their Creating a Console Application example.

    opened by thinkverse 1
Releases(0.3.1)
  • 0.3.1(Sep 28, 2022)

  • 0.2.0(Jun 30, 2021)

    This version introduces Filters. This is a first iteration on this feature so it might be subjected to breaking changes in the near future.

    • Image Placeholders now support Filters to apply visual changes to image resources.
    • Two initial filters added: Circle and Rounded
    • It is now possible to create banners with rounded / circle avatars directly on top of any background

    Breaking Changes for v. 0.1.5

    • Placeholders were relocated to the Gdaisy/Placeholder namespace, so you'll have to update code that works directly with placeholders (ImagePlaceholder and TextPlaceholder)
    Source code(tar.gz)
    Source code(zip)
  • 0.1.5(Jun 21, 2021)

    This release comes with:

    • updated Pest test suite to use higher order expectations (thanks @lukeraymonddowning !)
    • restructured bin to allow for expanding the built-in commands available
    • resize command included with support to several popular resolutions
    • small fixes
    • updated Readme
    Source code(tar.gz)
    Source code(zip)
  • 0.1.4(Jun 12, 2021)

  • 0.1.3(Jun 11, 2021)

    This update brings new text alignment options (center, left, right), right crop align for images, upgraded bin path (thanks @thinkverse !) and updated README with instructions on how to set up custom templates and how to build the template images.

    Source code(tar.gz)
    Source code(zip)
  • 0.1.2(Jun 9, 2021)

  • 0.1.1(Jun 9, 2021)

  • 0.1(Jun 9, 2021)

Owner
Erika Heidi
Creative developer & content creator passionate about open source, Linux, and PHP. Senior Technical Writer @digitalocean. GitHub Star ⭐
Erika Heidi
✨ Automatic image creation from templates

This package enables you to automatically create images from Placid templates. You can use the REST API or the URL API to create placid.app embed links with your variables to dynamically set the image content.

placid.app 49 Nov 30, 2022
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image

Laravel ImageUp The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization. Install

QCode.in 708 Dec 22, 2022
A Laravel Gravatar package for retrieving gravatar image URLs or checking the existance of an image.

Gravatar for Laravel 5.x, 6, 7 and 8 Installation First, pull in the package through Composer via the command line: composer require creativeorange/gr

Creativeorange 477 Dec 1, 2022
This plugin adds a new image style for the Core Image block.

This plugin adds a new image style for the Core Image block. Introduction How to use? Go to Gutenberg Editor and add a image block. e.g. Add new image

Mahesh Waghmare 3 Feb 17, 2022
Wonderfully easy on-demand image manipulation library with an HTTP based API.

Glide Glide is a wonderfully easy on-demand image manipulation library written in PHP. Its straightforward API is exposed via HTTP, similar to cloud i

The League of Extraordinary Packages 2.4k Dec 19, 2022
PHP Image Manipulation

Intervention Image Intervention Image is a PHP image handling and manipulation library providing an easier and expressive way to create, edit, and com

null 13k Jan 3, 2023
PHP 5.3 Object Oriented image manipulation library

Imagine Tweet about it using the #php_imagine hashtag. Image manipulation library for PHP 5.3 inspired by Python's PIL and other image libraries. Requ

Bulat Shakirzyanov 4.3k Jan 6, 2023
🌄 Perceptual image hashing for PHP

ImageHash A perceptual hash is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions

Jens Segers 1.9k Dec 28, 2022
Grabs the dominant color or a representative color palette from an image. Uses PHP and GD, Imagick or Gmagick.

Color Thief PHP A PHP class for grabbing the color palette from an image. Uses PHP and GD or Imagick libraries to make it happen. It's a PHP port of t

Kevin Subileau 610 Dec 28, 2022
PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options !

PHP Image Editor PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options ! ✨ Supporting ⭐ Star this repos

Franck Alary 17 Nov 13, 2022