{"id":22240063,"url":"https://github.com/brosenberger/module-image-optimizer","last_synced_at":"2026-02-19T19:32:14.387Z","repository":{"id":246496908,"uuid":"821303463","full_name":"brosenberger/module-image-optimizer","owner":"brosenberger","description":"Magento2 Module to convert images to a modern format and ship them accordingly","archived":false,"fork":false,"pushed_at":"2025-01-06T17:16:39.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-02T06:15:45.453Z","etag":null,"topics":["image-optimisation","magento2-module"],"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/brosenberger.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}},"created_at":"2024-06-28T08:40:02.000Z","updated_at":"2025-01-06T17:16:42.000Z","dependencies_parsed_at":"2025-04-11T15:03:05.357Z","dependency_job_id":"27c2eab1-11a4-4c65-b5a5-70c7b43c239a","html_url":"https://github.com/brosenberger/module-image-optimizer","commit_stats":null,"previous_names":["brosenberger/module-image-optimizer"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/brosenberger/module-image-optimizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brosenberger%2Fmodule-image-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brosenberger%2Fmodule-image-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brosenberger%2Fmodule-image-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brosenberger%2Fmodule-image-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brosenberger","download_url":"https://codeload.github.com/brosenberger/module-image-optimizer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brosenberger%2Fmodule-image-optimizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29628797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T18:02:07.722Z","status":"ssl_error","status_checked_at":"2026-02-19T18:01:46.144Z","response_time":117,"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":["image-optimisation","magento2-module"],"created_at":"2024-12-03T03:28:34.032Z","updated_at":"2026-02-19T19:32:14.370Z","avatar_url":"https://github.com/brosenberger.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/brosenberger"],"categories":[],"sub_categories":[],"readme":"# Image Optimizer Base - a Magento 2 setup for image optimizations\n\nThis module should ease the way of adding new image formats to a Magento 2 shop without the need of adapting any templates or markups.\n\n**Goals of this module:**\n* Base scanner of folders for images which might need to be served in modern formats (e.g. /pub/media)\n* Framework for adding various different converter to be extendable for any new future image formats\n\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/brosenberger)\n\n## Installation\n\n```\ncomposer require brocode/module-image-optimizer\nbin/magento module:enable BroCode_ImageOptimizer\nbin/magento setup:upgrade\n```\n\n## Idea on how to delivery optimized images in a Magento 2 shop (or any other system)\n\nMagento 2 is slow when delivering anything where a PHP process is involved in comparison to a simple file transfer for any file directly servable via the web server. This can be utilized to separate the conversion of the optimized images and serving them. \n\n1) The conversion takes place within the Magento2 environment (or any other) to determine which files need conversion and to which file they should be converted to. \n\n2) The webserver utilizes internal rewrites and file checks which file needs to be served, based on the request of the user agent (browser Accept-Header). \n\nFollowing .htaccess snippet can be used to deliver WEBP images for certain directories if they do exists in addition to the original one:\n\n```\n ############################################\n ## if client accepts webp, rewrite image urls to use webp version\nAddType image/webp .webp\nRewriteCond %{HTTP_ACCEPT} image/webp\nRewriteCond %{REQUEST_FILENAME} (.*)\\.(png|gif|jpe?g)$\nRewriteCond %{REQUEST_FILENAME}\\.webp -f\nRewriteRule ^ %{REQUEST_FILENAME}\\.webp [L,T=image/webp]\n```\n\nBackground information for this .htaccess entry:\n* add a new mime type for webp images\n* check if the browser accepts webp images\n* check if the requested file is a png, gif or jpeg file\n* check if a webp file exists for the requested file\n* rewrite the request to the webp file\n\nThe same can be done with any other image format (e.g. for AVIF use the mime type image/avif).\n\n\n## Features\n\n### Cronjob for folder scanning of images\n\nScans all configured image folders, can be disabled via configuration.\n\n**Configuration** \n\nThe cronjob can be disabled under ```Stores -\u003e Configuration -\u003e Services -\u003e BroCodeI ImageOptimizer```, it is enabled per default.\n\n**Image Paths**\n\nThe ImagePathScannerService recieves via dependency injection ``BroCode\\ImageOptimizer\\Api\\Data\\ImagePathProviderInterface`` which can provide any directory to be scanned. \n\n````xml\n\u003ctype name=\"BroCode\\ImageOptimizer\\Model\\ImagePathScannerService\"\u003e\n    \u003carguments\u003e\n        \u003cargument name=\"imagePathProviders\" xsi:type=\"array\"\u003e\n            \u003citem name=\"xmlConfigurable\" xsi:type=\"object\"\u003eBroCode\\ImageOptimizer\\Model\\Data\\XmlConfigurableImagePathProvider\u003c/item\u003e\n        \u003c/argument\u003e\n    \u003c/arguments\u003e\n\u003c/type\u003e\n````\n\nOne default path provider is implemented, which takes arguments via di.xml. The current setting is for the pub/media folder, the Magento base folder is added automatically to every entry given:\n```xml\n\u003ctype name=\"BroCode\\ImageOptimizer\\Model\\Data\\XmlConfigurableImagePathProvider\"\u003e\n    \u003carguments\u003e\n        \u003cargument name=\"paths\" xsi:type=\"array\"\u003e\n            \u003citem name=\"media\" xsi:type=\"string\"\u003epub/media\u003c/item\u003e\n        \u003c/argument\u003e\n    \u003c/arguments\u003e\n\u003c/type\u003e\n```\n\n### CLI commands\n\nImages Scanning (same function as cronjob + listing possibility of images to be optimized):\n```\nbin/magento images:optimize:scan\n``` \n\n**Options:**\n* `-l | --list`: List all images that need to be optimized, file is stored in ```var/\u003c\u003cdatetime\u003e\u003e_image_optimizer.log```\n\n### Conversion Hooks\n\nThis module provides an event hook for every image that needs to be converted. This is implemented with an default Magento 2 event and can be utilized with an observer listening on the event ```brocode_convert_image```. The event has following data stored that can be used:\n\n```php\n$this-\u003eeventManager-\u003edispatch(\n    'brocode_convert_image',\n    [\n        'image_path' =\u003e $file-\u003egetPathname(),\n        'converter_id' =\u003e $imageConvertValidator-\u003egetConverterId()\n    ]\n);\n```\n\n**Convert Validator**\n\nA convert validator checks if a given found image in any configured path needs conversion and which converter might be used for it. Every validator must implement ```BroCode\\ImageOptimizer\\Api\\Data\\ImageConvertValidationInterface```. A base implementation for file checks is implemented in the abstract class ```BroCode\\ImageOptimizer\\Model\\Converter\\AbstractImageConverter```.\n\nThese converter validator need to be contributed via di.xml to the ```\\BroCode\\ImageOptimizer\\Model\\ImageConverterService```:\n\n```xml\n\u003ctype name=\"BroCode\\ImageOptimizer\\Model\\ImageConverterService\"\u003e\n    \u003carguments\u003e\n        ...\n        \u003cargument name=\"imageValidator\" xsi:type=\"array\"\u003e\n            \u003citem name=\"avif\" xsi:type=\"object\"\u003eBroCode\\ImageAvifOptimizer\\Model\\Converter\\AvifImageConverter\u003c/item\u003e\n        \u003c/argument\u003e\n    \u003c/arguments\u003e\n\u003c/type\u003e\n```\n\n### Image conversion\n\nThere is currently no image conversion implemented in this module, this is done with following two basic modules:\n\n* **brocode/module-image-optimizer-avif** (for AVIF generation)\n* **brocode/module-image-optimizer-webp** (for WEBP generation)\n\nThough there is the default ```BroCode\\ImageOptimizer\\Observer\\InstantConvertImageObserver``` which catches the conversion event and try to convert the image with the help of any converter contributed to the ```\\BroCode\\ImageOptimizer\\Model\\ImageConverterService```:\n\n\n```xml\n\u003ctype name=\"BroCode\\ImageOptimizer\\Model\\ImageConverterService\"\u003e\n    \u003carguments\u003e\n        \u003cargument name=\"imageConverter\" xsi:type=\"array\"\u003e\n            \u003citem name=\"avif\" xsi:type=\"object\"\u003eBroCode\\ImageAvifOptimizer\\Model\\Converter\\AvifImageConverter\u003c/item\u003e\n        \u003c/argument\u003e\n        ...\n    \u003c/arguments\u003e\n\u003c/type\u003e\n```\n\n**This is done synchronously and slows down the according cron execution, especially if there are many images.**\n\nConsider using the extensions for the usage of the Magento 2 queue system to asynchronously process image conversion:\n* **brocode/module-image-optimizer-queue** (default MySQL queue for shops without active RabbitMQ installations)\n* **brocode/module-image-optimizer-amqp** (extension to the queue module for configurations of the RabbitMQ services)\n\n\n## Change Log\n\n**1.1.0**\n- Moved image path provider to service instead of cron job\n- added CLI command to scan/optimize images + listing of images to be optimized\n\n**1.0.0** \n- Initial version","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrosenberger%2Fmodule-image-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrosenberger%2Fmodule-image-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrosenberger%2Fmodule-image-optimizer/lists"}