{"id":46540254,"url":"https://github.com/ivanpreziosi/phpemailtimer","last_synced_at":"2026-03-07T01:01:37.012Z","repository":{"id":325436510,"uuid":"1099882894","full_name":"ivanpreziosi/phpEmailTimer","owner":"ivanpreziosi","description":"A small php library for generating dynamic email marketing countdowns. Forked and updated from https://github.com/goors/php-gif-countdown","archived":false,"fork":false,"pushed_at":"2025-11-28T16:00:29.000Z","size":750,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-29T09:12:20.293Z","etag":null,"topics":["animated-gif","countdown-timer","email","marketing","newsletters","php-library"],"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/ivanpreziosi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-19T15:05:55.000Z","updated_at":"2025-11-28T15:59:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ivanpreziosi/phpEmailTimer","commit_stats":null,"previous_names":["ivanpreziosi/phpemailtimer"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/ivanpreziosi/phpEmailTimer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanpreziosi%2FphpEmailTimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanpreziosi%2FphpEmailTimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanpreziosi%2FphpEmailTimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanpreziosi%2FphpEmailTimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanpreziosi","download_url":"https://codeload.github.com/ivanpreziosi/phpEmailTimer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanpreziosi%2FphpEmailTimer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30204449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["animated-gif","countdown-timer","email","marketing","newsletters","php-library"],"created_at":"2026-03-07T01:01:31.652Z","updated_at":"2026-03-07T01:01:36.856Z","avatar_url":"https://github.com/ivanpreziosi.png","language":"PHP","readme":"# PHP EMAIL TIMER\n\u003cp align=\"center\"\u003e\n   \u003cimg src=\"example.gif\" align=\"center\"/\u003e\n   \n   ![PHP Version](https://img.shields.io/badge/php-%3E%3D7.4-777bb4)\n   ![License](https://img.shields.io/badge/license-MIT-green)\n   ![Status](https://img.shields.io/badge/version-2.5-blue)\n   ![GD Extension](https://img.shields.io/badge/GD-required-orange)\n\u003c/p\u003e\n\nThis library generates an animated GIF that visualizes a live countdown to a target date/time.\nEach frame represents one second, up to a configurable maximum. \u003cbr\u003e\u003cbr\u003e\nIt is based on (and updated from) the original project by goors/php-gif-countdown, extended with improved rendering, validation, and configuration options. \u003cbr\u003e\u003cbr\u003e\n\n\n## Features\n\n* Generates a second-by-second animated GIF countdown\n* Customizable **background image per request** via `bg=...`\n* Customizable **font per request** via `font=...`\n* Customizable **text position** via `x-offset` / `y-offset`\n* Customizable **text color (RGB)** via `font-color-r` / `font-color-g` / `font-color-b`\n* Anti-aliased text rendering with alpha preservation\n* Fully timezone-aware countdown calculation\n* Zero-padding and formatting for multi-day countdowns\n* Optional filesystem-based caching to reduce server load\n\n---\n## Requirements\n\n* **PHP 7.4+**\n* **GD Extension** with TrueType font support (FreeType)\n* At least one PNG background in the `backgrounds/` folder\n* At least one TrueType font in the `fonts/` folder\n\n---\n\n## Installation\n\nClone the repository:\n\n```bash\ngit clone https://github.com/\u003cyour-username\u003e/\u003cyour-repo\u003e.git\ncd \u003cyour-repo\u003e\n```\n\nMake sure your server has the GD extension enabled:\n\n```bash\nphp -m | grep gd\n```\n\nIf not present, enable it in your PHP configuration.\n\n---\n\n## Usage\n\n### Basic HTTP Call\n\nThe script exposes a GIF endpoint that can be included directly in HTML `\u003cimg\u003e` tags.\n\nExample:\n\n```html\n\u003cimg src=\"path_to_the_library/index.php?time=2025-12-31%2023:59:59\"\u003e\n```\n\n### GET Parameters\n\n| Parameter             | Description                                                                                                  |\n| --------------------- | ------------------------------------------------------------------------------------------------------------ |\n| `time`                | Target date/time for the countdown (timestamp or any format supported by `strtotime()`)                      |\n| `bg` (optional)       | Selects a background PNG file (must exist in `backgrounds/`). Example: `bg=dark`                             |\n| `font` (optional)     | Selects a TrueType font file (must exist in `fonts/`). Example: `font=roboto`                                |\n| `x-offset` (optional) | Horizontal text offset. Example: `x-offset=150`                                                              |\n| `y-offset` (optional) | Vertical text offset. Example: `y-offset=150`                                                                |\n| `font-color-r` (opt.) | Text color red channel (0..255). Example: `font-color-r=255`                                                 |\n| `font-color-g` (opt.) | Text color green channel (0..255). Example: `font-color-g=255`                                               |\n| `font-color-b` (opt.) | Text color blue channel (0..255). Example: `font-color-b=255`                                                |\n\nExample using multiple parameters:\n\n```html\n\u003cimg src=\"path_to_the_library/index.php?time=2025-07-20T18:00:00\u0026bg=dark\u0026font=led\u0026x-offset=100\u0026y-offset=100\u0026font-color-r=255\u0026font-color-g=0\u0026font-color-b=0\"\u003e\n```\n\nExample with URL Encoding:\n\n```html\n\u003cimg src=\"path_to_the_library/index.php?time=2025-07-20T18%3A00%3A00\"\u003e\n```\n\n---\n\n## Countdown Display Format\n\nThe countdown text appears as:\n\n```\nDD:HH:MM:SS\n```\n\nExample with more than 9 days:\n\n```\n12:03:45:01\n```\n\nIf the target date is reached or passed, the GIF displays:\n\n```\n00:00:00:00\n```\n\n…and stops at that frame.\n\n---\n\n## Configuration\n\nThe script supports *dynamic backgrounds*, *dynamic fonts*, *dynamic text position*, and *dynamic RGB text color* selectable through query string parameters.\n\n### Directory Structure\n\n```\nbackgrounds/\n   - base.png\n   - dark.png\n   - light.png\n\nfonts/\n   - font.ttf\n   - led.ttf\n   - digital.ttf\n```\n\n### Runtime Override\n\nYou can override background, font, offsets, and color per request:\n\n```\n?time=2025-12-31%2023:59:59\u0026bg=dark\u0026font=digital\u0026x-offset=80\u0026y-offset=110\u0026font-color-r=255\u0026font-color-g=255\u0026font-color-b=255\n```\n\nIf omitted, the script falls back to the defaults `DEFAULT_BACKGROUND_NAME` and `DEFAULT_FONT_NAME`.\n\nEditable constants are defined near the top of the script:\n\n```php\nconst BASE_IMAGE_FOLDER = __DIR__ . '/backgrounds/';\nconst BASE_FONT_FOLDER = __DIR__ . '/fonts/';\nconst DEFAULT_BACKGROUND_NAME = 'base'; // omit extension (.png)\nconst DEFAULT_FONT_NAME = 'font'; // omit extension (.ttf)\n\nconst FONT_SIZE = 60;\nconst FONT_COLOR_RGB = [\"r\" =\u003e 255, \"g\" =\u003e 255, \"b\" =\u003e 255];\nconst FONT_X_OFFSET = 60;\nconst FONT_Y_OFFSET = 95;\n\nconst FRAME_DELAY = 100; // Delay between frames in centiseconds (100 = 1 second)\nconst MAX_FRAMES = 60;   // Maximum number of frames to generate\nconst TIME_ZONE = 'Europe/Rome';   // Time Zone\n```\n\n### What You Can Customize\n\n* Background image\n* Font file and size\n* Text color (RGB)\n* Text positioning (X/Y offsets)\n* Frame delay\n* Maximum frames\n* Timezone\n\n---\n\n## Caching System (Optional)\n\nStarting from version **1.2**, the library includes a lightweight caching layer that prevents excessive regeneration of the GIF countdown.\n\n### Why Caching?\n\nGenerating a GIF frame-by-frame is CPU-intensive.\nIf many clients request the same countdown (e.g., in emails), the server might regenerate identical animations multiple times per second.\n\nThe caching system ensures:\n\n* **At most one GIF is generated every 60 seconds** per unique combination of request parameters\n* Subsequent requests within that TTL are served instantly from disk\n* Server CPU usage is drastically reduced\n\n### How It Works\n\nEach request is keyed using all parameters that affect the rendered output:\n\n- `time`\n- `bg`\n- `font`\n- `x-offset`\n- `y-offset`\n- `font-color-r`, `font-color-g`, `font-color-b`\n\nInternally, the cache filename is generated from a JSON-encoded cache key (with a fallback to `serialize()`):\n\n```php\n$cacheKey = [\n  \"time\"  =\u003e (string)$time,\n  \"bg\"    =\u003e $bg,\n  \"font\"  =\u003e $font,\n  \"x\"     =\u003e $fontXOffset,\n  \"y\"     =\u003e $fontYOffset,\n  \"color\" =\u003e $fontColorRgb,\n];\n\n$cacheJson = json_encode($cacheKey, JSON_UNESCAPED_SLASHES);\nif ($cacheJson === false) {\n  $cacheJson = serialize($cacheKey);\n}\n$cacheFilename = md5($cacheJson) . \".gif\";\n```\n\nThe generated GIF is stored in the `cache/` directory.\n\nFor the next 60 seconds:\n\n* If the cached GIF exists and is fresh → it is returned immediately\n* If the cache is expired or missing → a new GIF is generated and stored\n\n### Enabling the Cache\n\nThe caching layer is automatically active if:\n\n* `CacheManager.php` exists\n* the `cache/` directory is writable\n\nNo configuration is required.\n\n### Cache Lifetime\n\nThe default TTL is **60 seconds**.\nYou may change it by modifying the `CACHE_TIMETOLIVE` constant:\n\n```php\nconst CACHE_TIMETOLIVE = 60; // TTL IN SECONDS\n```\n\n---\n\n## Integration Examples\n\n### 1. Embedding in a Website\n\n```html\n\u003cp\u003eEvent Countdown:\u003c/p\u003e\n\u003cimg src=\"/path_to_the_library/index.php?time=2026-01-01%2000:00:00\"\u003e\n```\n\n### 2. Dynamic Email (as long as your server allows external GIFs)\n\n```html\n\u003cimg src=\"https://example.com/path_to_the_library/index.php?time={{deadline}}\"\u003e\n\u003cimg src=\"https://example.com/path_to_the_library/index.php?time={{deadline}}\u0026bg=my_bg_filename\u0026font=my_ttf_font_filename\u0026x-offset=100\u0026y-offset=100\u0026font-color-r=255\u0026font-color-g=255\u0026font-color-b=255\"\u003e\n```\n\n### 3. Display in a Dashboard or Admin Panel\n\n```php\necho '\u003cimg src=\"path_to_the_library/index.php?time=' . urlencode($deadline) . '\"\u003e';\n```\n\n---\n\n## Error Handling\n\nThe script returns meaningful HTTP status codes:\n\n| Code    | Meaning                                                                    |\n| ------- | -------------------------------------------------------------------------- |\n| **400** | Invalid date format                                                        |\n| **403** | Missing `time` parameter                                                   |\n| **500** | Missing files, corrupted base image/font, rendering errors, GIF generation |\n\n---\n\n## Changelog\n\n### v2.5\n\n* Added support for dynamic **RGB text color** via `font-color-r`, `font-color-g`, `font-color-b`\n* Improved input validation and security (sanitized asset names)\n* Improved caching key to include offsets and RGB color\n* Added additional runtime checks for rendering/graphics functions\n\n### v2.3\n\n* Added optional GET parameters `x-offset` and `y-offset`\n\n### v2.2\n\n* Updated README and extended comments in code.\n\n### v2.0.1\n\n* Updated README accordingly\n\n### v2.0\n\n* Added support for dynamic backgrounds via `bg` query parameter\n* Added support for dynamic fonts via `font` query parameter\n* Updated README accordingly\n\n### v1.2\n\n* Added filesystem-based caching layer (1 GIF/minute per timestamp)\n* Added CacheManager class\n* Updated README with new documentation\n* Improved overall formatting and badges\n\n### v1.0\n\n* Major refactor and cleanup\n* Improved rendering quality\n* Better error handling\n* Full timezone support\n\n### v0.1\n\n* Forked from goors/php-gif-countdown\n\n---\n\n## License\n\nDistributed under the MIT License.\nSee `LICENSE` for details.\n\n---\n\nForked and updated from [https://github.com/goors/php-gif-countdown](https://github.com/goors/php-gif-countdown)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanpreziosi%2Fphpemailtimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanpreziosi%2Fphpemailtimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanpreziosi%2Fphpemailtimer/lists"}