{"id":13405098,"url":"https://github.com/erikaheidi/gdaisy","last_synced_at":"2025-04-09T15:09:32.287Z","repository":{"id":46290839,"uuid":"374616494","full_name":"erikaheidi/gdaisy","owner":"erikaheidi","description":"php-gd based image templates","archived":false,"fork":false,"pushed_at":"2022-09-28T16:07:47.000Z","size":506,"stargazers_count":77,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T15:09:27.840Z","etag":null,"topics":["gd","image-processing","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erikaheidi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-07T09:57:13.000Z","updated_at":"2025-01-27T20:59:59.000Z","dependencies_parsed_at":"2022-09-11T11:00:15.927Z","dependency_job_id":null,"html_url":"https://github.com/erikaheidi/gdaisy","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikaheidi%2Fgdaisy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikaheidi%2Fgdaisy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikaheidi%2Fgdaisy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikaheidi%2Fgdaisy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erikaheidi","download_url":"https://codeload.github.com/erikaheidi/gdaisy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055282,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gd","image-processing","php"],"created_at":"2024-07-30T19:01:55.720Z","updated_at":"2025-04-09T15:09:32.267Z","avatar_url":"https://github.com/erikaheidi.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/293241/121391345-8cb16480-c94e-11eb-9f86-1449e81034cc.png\" alt=\"gdaisy logo\"\u003e\n  \u003c/p\u003e\n  \n# gdaisy\n\nA highly experimental image templating system based on PHP-GD to dynamically generate image banners and covers. \nGDaisy also comes with a few sample scripts to generate common size thumbnails via `bin/gdaisy`.\n\n## Installation\n\n### 1. Require `erikaheidi/gdaisy` in your project using Composer:\n\n```shell\ncomposer require erikaheidi/gdaisy\n```\n\n### 2. Once it's installed, you can run the default script to generate an example cover based on meta tags.\n\nGdaisy 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:\n\n```shell\n./vendor/bin/gdaisy generate cover https://www.digitalocean.com/community/tutorials/how-to-set-up-visual-studio-code-for-php-projects output.png\n```\n\nThis will generate the following image:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/293241/121399169-77403880-c956-11eb-8aba-f2383e260ef0.png\" alt=\"gdaisy generated cover image\"\u003e\n  \u003c/p\u003e\n\nThis 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`.\n\n## Using GDaisy Scripts\n\nGDaisy 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.\n\n### Resize\n\nResizes to a specific size, cropping the image to fully fit in the designated area. \n\n```shell\n./vendor/bin/gdaisy resize crop size=[size] input=[path/to/input.png] output=[path/to/output.png]\n```\n\nSizes:\n\n- `avatar`: 150x150\n- `square`: 800x800\n- `480p`: 640x480\n- `720p`: 1280x720\n- `1080p`: 1920x1080\n- `1440p`: 2560x1440\n\n_Defined in `resources/templates/resize-*.json`:_\n\n### Generate\n\nGenerates 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.\n\n```shell\n./vendor/bin/gdaisy generate cover [URL] [path/to/output.png]\n```\n\n## Creating Templates\n\nIn GDaisy, a `Template` is composed by `Placeholders`. A placeholder is like an image layer.\n\nPlaceholders must implement the `PlaceholderInterface`. Currently, there are two types of placeholders:\n\n- **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.\n- **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.\n\nThere are two ways of setting up templates. You can programmatically define templates, and/or you can use a JSON file specification.\n\n### Programmatically Defining Templates\n\nFor 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.\n\n```php\n\u003c?php\n\nuse GDaisy\\Template;\nuse GDaisy\\Placeholder\\ImagePlaceholder;\n\nrequire __DIR__. '/vendor/autoload.php';\n\n//Defining Template\n$template = new Template('article-thumb', [\n    'width' =\u003e 150,\n    'height' =\u003e 150,\n]);\n$image = new ImagePlaceholder([\n    'width' =\u003e 150,\n    'height' =\u003e 150,\n]);\n$template-\u003eaddPlaceholder('thumb', $image);\n\n//Applying Template\n$template-\u003eapply(\"thumb\", [\n    \"image_file\" =\u003e __DIR__ . '/resources/images/gdaisy.png'\n]);\n\n$template-\u003ewrite('output.png');\necho \"Finished.\\n\";\n```\n\nThis will generate a 150x150 thumbnail for the specified image, which could be provided as argument to the script for instance.\n\nIf your template has many placeholders or uses text, it might be easier to work with a JSON file instead.\n\n### Using a JSON Template\n\nConsider the following `basic.json` template example:\n\n```json\n{\n  \"width\": 600,\n  \"height\": 600,\n  \"background\": \"FFFFFF\",\n  \"elements\": {\n    \"title\": {\n      \"type\": \"text\",\n      \"properties\": {\n        \"pos_x\": 50,\n        \"pos_y\": 20,\n        \"size\": 30,\n        \"color\": \"666666\",\n        \"max_width\": 500,\n        \"align\": \"center\"\n      }\n    },\n    \"thumbnail\": {\n      \"type\": \"image\",\n      \"properties\": {\n        \"pos_x\": 50,\n        \"pos_y\": 50,\n        \"width\": 500,\n        \"height\": 500,\n        \"filters\": [ \"GDaisy\\\\Filter\\\\Rounded\" ]\n      }\n    }\n  }\n}\n```\n\nThis template has two elements: `title` (type `text`) and `thumbnail` (type `image`).\n\nFollowing, a PHP script to generate a new image based on the example template:\n\n```php\n\u003c?php\n\nuse GDaisy\\Template;\n\nrequire __DIR__. '/vendor/autoload.php';\n\n$template = Template::create(__DIR__ . '/resources/templates/basic.json');\n\n$template-\u003eapply(\"thumbnail\", [\n    \"image_file\" =\u003e __DIR__ . '/resources/images/gdaisy.png'\n])-\u003eapply(\"title\", [\n    \"text\" =\u003e \"generated with gdaisy\"\n]);\n\n$template-\u003ewrite('output.png');\necho \"Finished.\\n\";\n```\n\n## Template / Placeholders Reference\n\n**Template Properties:**\n\n- `width`: Resulting image width\n- `height`: Resulting image height\n- `background`: Resulting image background\n\n**Text Properties:**\n\n- `pos_x`: X coordinate (bottom left X coordinate for the base of text)\n- `pos_y`: Y coordinate (botom left Y coordinate for the base of text)\n- `size`: Text size\n- `color`: Text Color (hex)\n- `max_width` (optional): Maximum text width - text will be broken down into multiple lines when set\n- `align` (optional): Text align, possible values are `left`(default), `center`, or `right`.\n- `font`: path to font file (ttf)\n\n**Image Properties:**\n\n- `pos_x`: X coordinate (top left corner) where the image will be applied\n- `pos_y`: Y coordinate (top left corner) where the image will be applied,\n- `width`: width (will proportially resize to fit)\n- `height`: height (will proportially resize to fit)\n- `image_file`: (optional): when set, will use this image, otherwise you'll have to provide this as parameter when applying the template\n- `crop`: (optional): when set to `center`, will resize-crop while centering the image. Default is `left`, can also be set to `right`.\n- `filters`: (optional): accepts an array of `FilterInterface` classes that should be applied to this element. Currently, there are two filters implemented:\n    - `Rounded` (`src/Filter/Rounded.php`): creates a rounded corners effect on the image.\n    - `Circle` (`src/Filter/Circle.php`): creates a fully rounded image.\n  \n\n## Example Templates\n\n### Creates a circle avatar sized 600x600 with white background\n\n```json\n{\n  \"width\": 600,\n  \"height\": 600,\n  \"background\": \"FFFFFF\",\n  \"elements\": {\n    \"thumbnail\": {\n      \"type\": \"image\",\n      \"properties\": {\n        \"pos_x\": 0,\n        \"pos_y\": 0,\n        \"width\": 600,\n        \"height\": 600,\n        \"filters\": [ \"GDaisy\\\\Filter\\\\Circle\" ]\n      }\n    }\n  }\n}\n```\n\n### Creates a rounded avatar sized 600x600 with white background\n\n```json\n{\n  \"width\": 600,\n  \"height\": 600,\n  \"background\": \"FFFFFF\",\n  \"elements\": {\n    \"thumbnail\": {\n      \"type\": \"image\",\n      \"properties\": {\n        \"pos_x\": 0,\n        \"pos_y\": 0,\n        \"width\": 600,\n        \"height\": 600,\n        \"filters\": [ \"GDaisy\\\\Filter\\\\Rounded\" ]\n      }\n    }\n  }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikaheidi%2Fgdaisy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferikaheidi%2Fgdaisy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikaheidi%2Fgdaisy/lists"}