{"id":13684269,"url":"https://github.com/ADmad/cakephp-glide","last_synced_at":"2025-04-30T20:33:44.392Z","repository":{"id":36395370,"uuid":"40700279","full_name":"ADmad/cakephp-glide","owner":"ADmad","description":"CakePHP plugin for using Glide image manipulation library","archived":false,"fork":false,"pushed_at":"2024-02-09T12:39:23.000Z","size":148,"stargazers_count":35,"open_issues_count":0,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-08T00:41:59.480Z","etag":null,"topics":["cakephp","cakephp-plugin","image-processing","middleware","php","thumbnail"],"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/ADmad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","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},"funding":{"github":["ADmad"]}},"created_at":"2015-08-14T06:49:04.000Z","updated_at":"2024-11-03T05:15:12.000Z","dependencies_parsed_at":"2024-02-09T14:07:02.788Z","dependency_job_id":null,"html_url":"https://github.com/ADmad/cakephp-glide","commit_stats":{"total_commits":151,"total_committers":5,"mean_commits":30.2,"dds":"0.10596026490066224","last_synced_commit":"cffd2da8a476e5b5ecc8289e46c63fed30759b1c"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ADmad%2Fcakephp-glide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ADmad%2Fcakephp-glide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ADmad%2Fcakephp-glide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ADmad%2Fcakephp-glide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ADmad","download_url":"https://codeload.github.com/ADmad/cakephp-glide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224224786,"owners_count":17276428,"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":["cakephp","cakephp-plugin","image-processing","middleware","php","thumbnail"],"created_at":"2024-08-02T14:00:31.728Z","updated_at":"2024-11-12T05:31:48.274Z","avatar_url":"https://github.com/ADmad.png","language":"PHP","readme":"# CakePHP Glide\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/ADmad/cakephp-glide/ci.yml?style=flat-square\u0026branch=master)](https://github.com/ADmad/cakephp-glide/actions?query=workflow%3ACI+branch%3Amaster)\n[![Coverage Status](https://img.shields.io/codecov/c/github/ADmad/cakephp-glide.svg?style=flat-square)](https://codecov.io/github/ADmad/cakephp-glide)\n[![Total Downloads](https://img.shields.io/packagist/dt/ADmad/cakephp-glide.svg?style=flat-square)](https://packagist.org/packages/ADmad/cakephp-glide)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.txt)\n\nCakePHP plugin to help using [Glide](http://glide.thephpleague.com/) image manipulation library.\n\nThe plugin consists of a middlware, view helper and a Glide response class.\n\n## Installation\n\nInstall the plugin through composer:\n\n```\ncomposer require admad/cakephp-glide\n```\n\nLoad the plugin using CLI:\n\n```sh\nbin/cake plugin load ADmad/Glide\n```\n\n## Usage\n\n### Middleware\n\nIn your `config/routes.php` setup the `GlideMiddleware` for required scope which\nintercepts requests and serves images generated by Glide. For e.g.:\n\n```php\n$routes-\u003escope('/images', function ($routes) {\n    $routes-\u003eregisterMiddleware('glide', new \\ADmad\\Glide\\Middleware\\GlideMiddleware([\n        // Run this middleware only for URLs starting with specified string. Default null.\n        // Setting this option is required only if you want to setup the middleware\n        // in Application::middleware() instead of using router's scoped middleware.\n        // It would normally be set to same value as that of server.base_url below.\n        'path' =\u003e null,\n\n        // Either a callable which returns an instance of League\\Glide\\Server\n        // or config array to be used to create server instance.\n        // http://glide.thephpleague.com/1.0/config/setup/\n        'server' =\u003e [\n            // Path or League\\Flysystem adapter instance to read images from.\n            // http://glide.thephpleague.com/1.0/config/source-and-cache/\n            'source' =\u003e WWW_ROOT . 'uploads',\n\n            // Path or League\\Flysystem adapter instance to write cached images to.\n            'cache' =\u003e WWW_ROOT . 'cache',\n\n            // URL part to be omitted from source path. Defaults to \"/images/\"\n            // http://glide.thephpleague.com/1.0/config/source-and-cache/#set-a-base-url\n            'base_url' =\u003e '/images/',\n\n            // Response class for serving images. If unset (default) an instance of\n            // \\ADmad\\Glide\\Response\\PsrResponseFactory() will be used.\n            // http://glide.thephpleague.com/1.0/config/responses/\n            'response' =\u003e null,\n        ],\n\n        // http://glide.thephpleague.com/1.0/config/security/\n        'security' =\u003e [\n            // Boolean indicating whether secure URLs should be used to prevent URL\n            // parameter manipulation. Default false.\n            'secureUrls' =\u003e false,\n\n            // Signing key used to generate / validate URLs if `secureUrls` is `true`.\n            // If unset value of Cake\\Utility\\Security::salt() will be used.\n            'signKey' =\u003e null,\n        ],\n\n        // Cache duration. Default '+1 days'.\n        'cacheTime' =\u003e '+1 days',\n\n        // Any response headers you may want to set. Default null.\n        'headers' =\u003e [\n            'X-Custom' =\u003e 'some-value',\n        ],\n\n        // Allowed query string params. If for e.g. you are only using glide presets\n        // then you can set allowed params as `['p']` to prevent users from using\n        // any other image manipulation params.\n        'allowedParams' =\u003e null\n    ]));\n\n    $routes-\u003eapplyMiddleware('glide');\n\n    $routes-\u003econnect('/*');\n});\n```\n\nFor the example config shown above, for URL like `domain.com/images/user/profile.jpg`\nthe source image should be under `webroot/uploads/user/profile.jpg`.\n\n__Note__: Make sure the image URL does not directly map to image under webroot.\nOtherwise as per CakePHP's default URL rewriting rules the image will be served by\nwebserver itself and request won't reach your CakePHP app.\n\n#### Exceptions\n\nIf you have enabled secure URLs and a valid token is not present in query string\nthe middleware will throw a `ADmad\\Glide\\Exception\\SignatureException` exception.\n\nIf a response image could not be generated by the Glide library then by default\nthe middleware will throw a `ADmad\\Glide\\Exception\\ResponseException`.\nA `Glide.response_failure` event will also be triggered in this case. You can setup a\nlistener for this event and return a response instance from it. In this case\nthat response will be sent to client and `ResponseException` will not be thrown.\n\n```php\n\\Cake\\Event\\EventManager::instance()-\u003eon(\n    \\ADmad\\Glide\\Middleware\\GlideMiddleware::RESPONSE_FAILURE_EVENT,\n    function ($event) {\n        return (new Response())\n            -\u003ewithFile('/path/to/default-image.jpg');\n    }\n);\n```\n\n### Helper\n\nThe provided `GlideHelper` helps creating URLs and image tags for generating\nimages. You can load the helper in your `AppView::initialize()` as shown in\nexample below:\n\n```php\npublic function initialize(): void\n{\n    // All option values should match the corresponding options for `GlideFilter`.\n    $this-\u003eloadHelper('ADmad/Glide.Glide', [\n        // Base URL.\n        'baseUrl' =\u003e '/images/',\n        // Whether to generate secure URLs.\n        'secureUrls' =\u003e false,\n        // Signing key to use when generating secure URLs.\n        'signKey' =\u003e null,\n    ]);\n}\n\n```\n\nHere are the available methods of `GlideHelper`:\n\n```php\n    /**\n     * Creates a formatted IMG element.\n     *\n     * @param string $path Image path.\n     * @param array $params Image manipulation parameters.\n     * @param array $options Array of HTML attributes and options.\n     *   See `$options` argument of `Cake\\View\\HtmlHelper::image()`.\n     * @return string Complete \u003cimg\u003e tag.\n     */\n    GlideHelper::image(string $path, array $params = [], array $options = []): string\n\n    /**\n     * URL with query string based on resizing params.\n     *\n     * @param string $path Image path.\n     * @param array $params Image manipulation parameters.\n     * @return string Image URL.\n     */\n    GlideHelper::url(string $path, array $params = []): string\n```\n\nThe main benefit of using this helper is depending on the value of `secureUrls`\nconfig, the generated URLs will contain a token which will be verified by the\nmiddleware. The prevents modification of query string params.\n","funding_links":["https://github.com/sponsors/ADmad"],"categories":["Imagery"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FADmad%2Fcakephp-glide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FADmad%2Fcakephp-glide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FADmad%2Fcakephp-glide/lists"}