{"id":18750648,"url":"https://github.com/webiny/image","last_synced_at":"2025-11-26T20:30:17.501Z","repository":{"id":62547878,"uuid":"23499149","full_name":"webiny/Image","owner":"webiny","description":"[READ-ONLY] PHP image manipulation library. You can crop, rotate, resize, create thumbnails. (master at Webiny/Framework)","archived":false,"fork":false,"pushed_at":"2017-11-26T21:24:49.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-28T22:53:16.987Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.webiny.com/","language":"PHP","has_issues":false,"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/webiny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-08-30T19:31:24.000Z","updated_at":"2024-12-20T05:17:09.000Z","dependencies_parsed_at":"2022-11-02T22:30:23.392Z","dependency_job_id":null,"html_url":"https://github.com/webiny/Image","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FImage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FImage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FImage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FImage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/Image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239635836,"owners_count":19672239,"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":[],"created_at":"2024-11-07T17:12:41.808Z","updated_at":"2025-11-26T20:30:17.441Z","avatar_url":"https://github.com/webiny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Image Component\n===============\n\nThe `Image` component provides basic functions for manipulating images. Component also fixes the incorrect rotation \non pictures taken by a smartphone like iPhone or Android.\n\nInstall the component\n---------------------\nThe best way to install the component is using Composer.\n\n```bash\ncomposer require webiny/image\n```\nFor additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/image).\n\n## Usage\n\nThis component is deeply coupled with the `Storage` component,\nso it's advised that you get yourself familiar with that component first, if you already haven't.\n\nUnder **basic functions** it's meant that you can do these manipulations on any image:\n- `resize`\n- `crop`\n- `rotate`\n\nBut before you can do any of the manipulations, you must first load an image. You can load an image from several different\nsources by calling appropriate methods on `ImageLoader` class:\n- `create` - creates a blank image\n- `open` - create an image from the given File storage instance\n- `load` - create an image from the given binary string\n- `resource` - create an image from the given (stream) resource\n\nEach of these methods returns an instance of `ImageInterface`. Using `ImageInterface` you can perform the defined manipulations\non the loaded image.\n\nOnce you are done manipulating the image you can either save it by calling the `save` method, or you can output the image\nby calling the `show` method.\n\nHere is a usage example:\n\n```php\n// storage\n$imageStorage = \\Webiny\\Component\\ServiceManager\\ServiceManager::getInstance()-\u003egetService('storage.local');\n$image = new \\Webiny\\Component\\Storage\\File\\File('embed.jpg', $imageStorage);\n\n// load the image using the `open` method\n$imgInstance = \\Webiny\\Component\\Image\\ImageLoader::open($image);\n\n// perform manipulations\n$imgInstance-\u003eresize(800, 800)\n            -\u003ecrop(200, 200, 50, 40);\n            -\u003erotate(30, 'bfbfbf');\n\n// save the new image\n$destination = new \\Webiny\\Component\\Storage\\File\\File('embed-rotated.jpg', $imageStorage);\n$result = $imgInstance-\u003esave($destination); // if you don't set the destination, the original image will be overwritten\n```\n\n## Using ImageTrait\n\nAn easier way of loading the image and creating instances of ImageInterface is using the ImageTrait.\nHere is an example of loading the image from the \\Webiny\\Component\\Storage\\File\\File object:\n\n```php\nclass MyClass{\n\tuse \\Webiny\\Component\\Image\\ImageTrait;\n\n\tfunction __construct(){\n\t\t$imageStorage = \\Webiny\\Component\\ServiceManager\\ServiceManager::getInstance()-\u003egetService('Storage.Local');\n\t\t$image = new \\Webiny\\Component\\Storage\\File\\File('embed.jpg', $imageStorage);\n\n\t\t$imgInstance = $this-\u003eimage($image);\n\n\t\t$imgInstance-\u003eresize(800, 800);\n\t\t$imgInstance-\u003ecrop(200, 200, 50, 40);\n\t\t$imgInstance-\u003erotate(30, 'bfbfbf');\n\n\t\t$imgInstance-\u003eshow();\n\t}\n}\n```\n\nHere is another example where we load the image by file storage key and storage driver:\n\n``` php\nclass MyClass{\n\tuse \\Webiny\\Component\\Image\\ImageTrait;\n\n\tfunction __construct(){\n\t\t$imgInstance = $this-\u003eimage('embed.jpg', 'Local');\n\n\t\t$imgInstance-\u003eresize(800, 800);\n\t\t$imgInstance-\u003ecrop(200, 200, 50, 40);\n\t\t$imgInstance-\u003erotate(30, 'bfbfbf');\n\n\t\t$imgInstance-\u003eshow();\n\t}\n}\n```\n\nSo as you can see, you can load and create ImageInterface instances either by passing directly the File object, or by\npassing the file key together with the name of the storage service.\n\n## Bridge\n\nThe default bridge for image library uses `Imagine` library (https://github.com/avalanche123/Imagine) by Bulat Shakirzyanov\nwhich perform all the image manipulations.\n\nIf you wish to expand or change the current bridged library you need to create two classes:\n- a loader class that implements `Webiny\\Component\\Image\\Bridge\\ImageLoaderInterface`\n- an image manipulation class that extends `Webiny\\Component\\Image\\Bridge\\AbstractImage`\n\nAfter that just change the `Bridge` in the configuration and the framework will use your bridge instead the\ndefault one.\n\n## Configuration\n\nThe `Image` component requires very little configuration. Here is an example:\n\n```yaml\n    Image:\n        Library: gd\n        Quality: 90\n```\n\nThe `Library` parameter defines which image library will be used. Supported libraries by `Imagine` library are:\n- `gd` - uses native PHPs GD library\n- `imagick` - uses ImageMagick library which requires php-imagick extension\n- `gmagick` - uses GraphicsMagick API which also requires php-gmagick extension\n\nThe `Quality` parameter defines at which quality to save the image. The default quality is 90 (max is 100).\n\nTo register the config with the component, just call `Image::setConfig($pathToYamlConfig)`.\n\nResources\n---------\n\nTo run unit tests, you need to use the following command:\n\n    $ cd path/to/Webiny/Component/Image/\n    $ composer.phar install\n    $ phpunit","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fimage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Fimage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fimage/lists"}