{"id":20731078,"url":"https://github.com/greg-md/php-imagix","last_synced_at":"2025-03-11T10:21:37.150Z","repository":{"id":12032912,"uuid":"70835580","full_name":"greg-md/php-imagix","owner":"greg-md","description":"Save images as static in real-time in different formats using Intervention Image.","archived":false,"fork":false,"pushed_at":"2023-04-19T19:20:55.000Z","size":73,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-18T09:23:27.041Z","etag":null,"topics":["greg-md","greg-php","image","intervention","intervention-image","php","php-static-image","static-image","web-artisans"],"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/greg-md.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}},"created_at":"2016-10-13T18:22:48.000Z","updated_at":"2019-07-24T08:31:13.000Z","dependencies_parsed_at":"2025-01-18T00:35:30.219Z","dependency_job_id":null,"html_url":"https://github.com/greg-md/php-imagix","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":0.06521739130434778,"last_synced_commit":"b5b215e02dfefc93e70c36c1ef8c143d94a8e669"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-imagix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-imagix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-imagix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-imagix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greg-md","download_url":"https://codeload.github.com/greg-md/php-imagix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243012751,"owners_count":20221616,"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":["greg-md","greg-php","image","intervention","intervention-image","php","php-static-image","static-image","web-artisans"],"created_at":"2024-11-17T05:13:38.816Z","updated_at":"2025-03-11T10:21:37.110Z","avatar_url":"https://github.com/greg-md.png","language":"PHP","readme":"# Greg PHP Imagix\n\n[![StyleCI](https://styleci.io/repos/70835580/shield?style=flat)](https://styleci.io/repos/70835580)\n[![Build Status](https://travis-ci.org/greg-md/php-imagix.svg)](https://travis-ci.org/greg-md/php-imagix)\n[![Total Downloads](https://poser.pugx.org/greg-md/php-imagix/d/total.svg)](https://packagist.org/packages/greg-md/php-imagix)\n[![Latest Stable Version](https://poser.pugx.org/greg-md/php-imagix/v/stable.svg)](https://packagist.org/packages/greg-md/php-imagix)\n[![Latest Unstable Version](https://poser.pugx.org/greg-md/php-imagix/v/unstable.svg)](https://packagist.org/packages/greg-md/php-imagix)\n[![License](https://poser.pugx.org/greg-md/php-imagix/license.svg)](https://packagist.org/packages/greg-md/php-imagix)\n\nSave images in real-time in different formats using [Intervention Image](http://image.intervention.io/).\n\nYou don't care anymore about generating new images from their sources when your app UI was changed.\nOnly thing you should do is to add new formats or change existent and the application will take care of them by itself.\n\n# Table of Contents:\n\n* [Requirements](#requirements)\n* [How It Works](#how-it-works)\n* [Methods](#methods)\n* [License](#license)\n* [Huuuge Quote](#huuuge-quote)\n\n# Requirements\n\n* PHP Version `^5.6 || ^7.0`\n\n# How It Works\n\n**First of all**, you have to initialize the Imagix.\n\nOptionally you can create an URL decorator for it.\nIt helps to rewrite image URLs to/from HTTP Server(Apache/Nginx).\n\n```php\nclass ImagixDecorator implements ImageDecoratorStrategy\n{\n    // Will use /imagix public path for generated images.\n    private $uri = '/imagix';\n    \n    public function output($url)\n    {\n        return $this-\u003enginxUri . $url;\n    }\n\n    public function input($url)\n    {\n        return \\Greg\\Support\\Str::shift($url, $this-\u003euri);\n    }\n}\n\n$sourcePath = __DIR__ . '/img';\n\n$destinationPath = __DIR__ . '/imagix';\n\n$decorator = new ImagixDecorator();\n\n$intervention = new Intervention\\Image\\ImageManager();\n\n$imagix = new \\Greg\\Imagix\\Imagix($intervention, $sourcePath, $destinationPath, $decorator);\n```\n\n**Next**, create image formats.\n\n```php\n$imagix-\u003eformat('square', function (\\Intervention\\Image\\Image $image) {\n    $image-\u003eresize(600, 600, function (\\Intervention\\Image\\Constraint $constraint) {\n        $constraint-\u003easpectRatio();\n        $constraint-\u003eupsize();\n    });\n});\n```\n\n**Now**, it's time to use it in your app.\n\nIt will generate an URL in format `\u003cimage_path\u003e/\u003cimage_name\u003e@\u003cformat\u003e@\u003clast_modified\u003e.\u003cimage_extension\u003e`.\n\n```php\n// result: /imagix/pictures/picture@square@129648839.jpg\n$imageUrl = $imagix-\u003eurl('/pictures/picture.jpg', 'square');\n\necho '\u003cimg src=\"' . $imageUrl . '\" width=\"600\" height=\"600\" alt=\"Picture\" /\u003e';\n```\n\nTo see the results, you have to config your `http server`.\n\n**Nginx**\n\n```nginxconfig\n# Imagix\nlocation ~* ^/imagix/.+ {\n    # If images doesn't exists, send to PHP to create it.\n    if (!-f $document_root$uri) {\n        rewrite .+ /imagix.php last;\n    }\n\n    expires max;\n    add_header Pragma public;\n    add_header Cache-Control \"public\";\n    add_header Vary \"Accept-Encoding\";\n}\n```\n\nIn **imagix.php** you will dispatch new files that was not generated yet in `/imagix` path.\n\n```php\n$imagix-\u003esend($_SERVER['REQUEST_URI']);\n```\n\n# Methods\n\n**Magic methods**:\n\n* [__construct](#__construct)\n\n## __construct\n\nInitialize the manager.\n\n```php\n__construct(ImageManager $manager, string $sourcePath, string $destinationPath, ImageDecoratorStrategy $decorator = null)\n```\n\n`$manager` - Intervention image manager;  \n`$sourcePath` - Source path;  \n`$destinationPath` - Destination path;  \n`$decorator` - Decorator.\n\n_Example:_\n\n```php\nclass ImagixDecorator implements ImageDecoratorStrategy\n{\n    // Will use /imagix public path for generated images.\n    private $uri = '/imagix';\n    \n    public function output($url)\n    {\n        return $this-\u003enginxUri . $url;\n    }\n\n    public function input($url)\n    {\n        return \\Greg\\Support\\Str::shift($url, $this-\u003euri);\n    }\n}\n\n$sourcePath = __DIR__ . '/img';\n\n$destinationPath = __DIR__ . '/imagix';\n\n$decorator = new ImagixDecorator();\n\n$intervention = new Intervention\\Image\\ImageManager();\n\n$imagix = new \\Greg\\Imagix\\ImagixManager($intervention, $sourcePath, $destinationPath, $decorator);\n```\n\n**Supported methods**:\n\n* [format](#format) - Register an image format;\n* [url](#url) - Get formatted image URL;\n* [source](#source) - Get source URL of a formatted image URL;\n* [effective](#effective) - Get effective URL of a formatted image URL;\n* [compile](#compile) - Compile a formatted image URL;\n* [send](#send) - Send image of a formatted image URL;\n* [unlink](#unlink) - Remove formatted versions of an image;\n* [remove](#remove) - Remove formatted images.\n\n## format\n\nRegister an image format.\n\n```php\nformat(string $name, callable(\\Intervention\\Image\\Image $image): void $callable): $this\n```\n\n`$name` - Format name;  \n`$callable` - A callable to format an image.  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;`$image` - The image.\n\n_Example:_\n\n```php\n$imagix-\u003eformat('square', function (\\Intervention\\Image\\Image $image) {\n    $image-\u003eresize(600, 600, function (\\Intervention\\Image\\Constraint $constraint) {\n        $constraint-\u003easpectRatio();\n        $constraint-\u003eupsize();\n    });\n});\n```\n\n## url\n\nGet formatted image URL.\n\n```php\nurl(string $source, string $format): string\n```\n\n`$source` - Original image URL;  \n`$format` - Format name.\n\n_Example:_\n\n```php\n$imagix-\u003eurl('/pictures/picture.jpg', 'square'); // result: /pictures/picture@square@129648839.jpg\n```\n\n## source\n\nGet source URL of a formatted image URL.\n\n```php\nsource(string $destination): string\n```\n\n`$destination` - Formatted image URL.\n\n_Example:_\n\n```php\n$imagix-\u003esource('/pictures/picture@square@129648839.jpg'); // result: /pictures/picture.jpg\n```\n\n## effective\n\nGet effective URL of a formatted image URL.\n\nEvery time a image changes, it's effective URL also changes.\nSo, if you have an old URL, you will get the new one.\n\n\u003e This is useful when you store somewhere formatted urls.\n\n\u003e By default, [`send`](#send) method will return a 301 redirect to the new URL.\n\n```php\neffective(string $destination): string\n```\n\n`$destination` - Formatted image URL.\n\n_Example:_\n\n```php\n$imagix-\u003eeffective('/pictures/picture@square@129642346.jpg'); // result: /pictures/picture@square@129648839.jpg\n```\n\n## compile\n\nCompile a formatted image URL. Will return the real path of the image.\n\n```php\ncompile(string $destination): string\n```\n\n`$destination` - Formatted image URL.\n\n_Example:_\n\n```php\n$imagix-\u003ecompile('/pictures/picture@square@129648839.jpg'); // result: /path/to/pictures/picture@square@129648839.jpg\n```\n\n## send\n\nSend image of a formatted image URL.\n\n```php\nsend(string $destination): $this\n```\n\n`$destination` - Formatted image URL.\n\n_Example:_\n\n```php\n$imagix-\u003esend('/pictures/picture@square@129648839.jpg');\n```\n\n## unlink\n\nRemove formatted versions of an image.\n\n```php\nunlink(string $source, string $format = null, int $lifetime = 0): $this\n```\n\n`$source` - Formatted image URL;  \n`$format` - Format name;  \n`$lifetime` - If set, will remove only expired files.\n\n_Example:_\n\n```php\n$imagix-\u003eunlink('/pictures/picture.jpg');\n```\n\n## remove\n\nRemove formatted images.\n\n```php\nremove(string $format = null, int $lifetime = 0): $this\n```\n\n`$format` - Format name;  \n`$lifetime` - If set, will remove only expired files.\n\n_Example:_\n\n```php\n$imagix-\u003eremove(); // Will remove all formatted images.\n\n$imagix-\u003eremove('square'); // Will remove only square images.\n```\n\n# License\n\nMIT © [Grigorii Duca](http://greg.md)\n\n# Huuuge Quote\n\n![I fear not the man who has practiced 10,000 programming languages once, but I fear the man who has practiced one programming language 10,000 times. #horrorsquad](http://greg.md/huuuge-quote-fb.jpg)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreg-md%2Fphp-imagix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreg-md%2Fphp-imagix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreg-md%2Fphp-imagix/lists"}