All Projects → erikaheidi → gdaisy

erikaheidi / gdaisy

Licence: MIT License
php-gd based image templates

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to gdaisy

Image
Manipulate images with an expressive API
Stars: ✭ 781 (+1223.73%)
Mutual labels:  gd
Simpleimage
A PHP class that makes working with images as simple as possible.
Stars: ✭ 1,184 (+1906.78%)
Mutual labels:  gd
Imagecow
PHP library to manipulate and generate responsive images
Stars: ✭ 234 (+296.61%)
Mutual labels:  gd
Watimage
🖼 PHP image manipulation class
Stars: ✭ 25 (-57.63%)
Mutual labels:  gd
Sparkline
PHP script (using GD) to generate sparklines
Stars: ✭ 61 (+3.39%)
Mutual labels:  gd
Thumb
A simple, local image only, thumbnail generation script written in PHP
Stars: ✭ 119 (+101.69%)
Mutual labels:  gd
Ngx small light
Dynamic Image Transformation Module For nginx.
Stars: ✭ 447 (+657.63%)
Mutual labels:  gd
Text2Image
The most useful & easy2use PHP library for converting any text into image
Stars: ✭ 29 (-50.85%)
Mutual labels:  gd
Zimg Host
Simple image hosting service
Stars: ✭ 62 (+5.08%)
Mutual labels:  gd
Php Legofy
Transform your images as if they were made out of LEGO bricks.
Stars: ✭ 161 (+172.88%)
Mutual labels:  gd
Grafika
An image processing library for PHP
Stars: ✭ 838 (+1320.34%)
Mutual labels:  gd
Smartcrop.php
smartcrop implementation in PHP
Stars: ✭ 37 (-37.29%)
Mutual labels:  gd
Gimage
A PHP library for easy image handling. 🖼
Stars: ✭ 148 (+150.85%)
Mutual labels:  gd
Image
A PHP library to handle images
Stars: ✭ 898 (+1422.03%)
Mutual labels:  gd
laravel-color-palette
Laravel Wrapper for @ksubileau/color-thief-php. Grabs the dominant color or a representative color palette from an image. Uses PHP and GD or Imagick.
Stars: ✭ 27 (-54.24%)
Mutual labels:  gd
Color Thief Php
Grabs the dominant color or a representative color palette from an image. Uses PHP and GD, Imagick or Gmagick.
Stars: ✭ 564 (+855.93%)
Mutual labels:  gd
Minecraft Avatar
PHP script (using GD) to generate avatar or skin from a Minecraft username
Stars: ✭ 104 (+76.27%)
Mutual labels:  gd
tcl.gd
Feature-complete Tcl interface to GD graphics drawing library
Stars: ✭ 15 (-74.58%)
Mutual labels:  gd
php-smartcrop-extension
smartcrop implementation in php extension
Stars: ✭ 17 (-71.19%)
Mutual labels:  gd
Image
PHP Image Manipulation
Stars: ✭ 12,298 (+20744.07%)
Mutual labels:  gd

gdaisy logo

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

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

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

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

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

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

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

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.

<?php

use GDaisy\Template;
use GDaisy\Placeholder\ImagePlaceholder;

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

//Defining Template
$template = new Template('article-thumb', [
    'width' => 150,
    'height' => 150,
]);
$image = new ImagePlaceholder([
    'width' => 150,
    'height' => 150,
]);
$template->addPlaceholder('thumb', $image);

//Applying Template
$template->apply("thumb", [
    "image_file" => __DIR__ . '/resources/images/gdaisy.png'
]);

$template->write('output.png');
echo "Finished.\n";

This will generate a 150x150 thumbnail for the specified image, which could be provided as argument to the script for instance.

If your template has many placeholders or uses text, it might be easier to work with a JSON file instead.

Using a JSON Template

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,
        "filters": [ "GDaisy\\Filter\\Rounded" ]
      }
    }
  }
}

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

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

Template / Placeholders Reference

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.
  • filters: (optional): accepts an array of FilterInterface classes that should be applied to this element. Currently, there are two filters implemented:
    • Rounded (src/Filter/Rounded.php): creates a rounded corners effect on the image.
    • Circle (src/Filter/Circle.php): creates a fully rounded image.

Example Templates

Creates a circle avatar sized 600x600 with white background

{
  "width": 600,
  "height": 600,
  "background": "FFFFFF",
  "elements": {
    "thumbnail": {
      "type": "image",
      "properties": {
        "pos_x": 0,
        "pos_y": 0,
        "width": 600,
        "height": 600,
        "filters": [ "GDaisy\\Filter\\Circle" ]
      }
    }
  }
}

Creates a rounded avatar sized 600x600 with white background

{
  "width": 600,
  "height": 600,
  "background": "FFFFFF",
  "elements": {
    "thumbnail": {
      "type": "image",
      "properties": {
        "pos_x": 0,
        "pos_y": 0,
        "width": 600,
        "height": 600,
        "filters": [ "GDaisy\\Filter\\Rounded" ]
      }
    }
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].