{"id":24540662,"url":"https://github.com/mistralys/application-utils-image","last_synced_at":"2025-04-15T08:42:35.930Z","repository":{"id":209896757,"uuid":"725206274","full_name":"Mistralys/application-utils-image","owner":"Mistralys","description":"PHP image helper library for basic image operations and color management.","archived":false,"fork":false,"pushed_at":"2025-01-13T15:56:03.000Z","size":106,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T11:41:44.406Z","etag":null,"topics":[],"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/Mistralys.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-29T16:52:26.000Z","updated_at":"2025-01-13T15:55:57.000Z","dependencies_parsed_at":"2023-11-29T18:28:40.139Z","dependency_job_id":"78440dcf-d1b6-4c6a-b946-525223dfaffa","html_url":"https://github.com/Mistralys/application-utils-image","commit_stats":null,"previous_names":["mistralys/application-utils-image"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fapplication-utils-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fapplication-utils-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fapplication-utils-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fapplication-utils-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mistralys","download_url":"https://codeload.github.com/Mistralys/application-utils-image/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249038887,"owners_count":21202803,"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":"2025-01-22T18:14:36.916Z","updated_at":"2025-04-15T08:42:35.911Z","avatar_url":"https://github.com/Mistralys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AppUtils - Image Helper\n\nPHP image helper library for basic image editing and color management.\n\n# Features\n\n- Dedicated image file classes, e.g. `JPGFile`, `SVGFile`.\n- Resample images by width, height, or both.\n- Get image dimensions, SVG files included.\n- Crop images.\n- Sharpen images.\n- Trim images.\n- Work with alpha transparency.\n- Add text to images.\n- Calculate the average color of an image.\n- Calculate the brightness or luma value of an image.\n- Work with a mix of HEX, 8Bit, 7Bit and percentage-based color values. \n\n# Requirements\n\n- PHP 7.4 or higher\n- [Composer](https://getcomposer.org)\n- GD extension\n\n# Usage\n\n## Image file classes\n\nThe library provides classes for handling different image formats:\n\n- `GIFFile`\n- `JPGFile` and `JPEGFile`\n- `PNGFile`\n- `SVGFile`\n \nThese classes work like the `FileInfo` class provided by the File Helper,\nso they provide all typical file operation methods as well as specialized \nimage-related methods.\n\n## Simple image operations\n\nThe image file class methods will immediately save the modifications \nto the file system. If you want to perform multiple operations before saving, \nyou will have to use an `ImageHelper` instance instead.\n\n### Resampling by width\n\nThis resamples the image to a new width, adjusting the height to keep the\noriginal image aspect ratio.\n\n```php\nuse AppUtils\\ImageHelper\\ImageFiles\\FileTypes\\JPGFile;\n\nJPGFile::factory('image.jpg')\n    -\u003eresampleByWidth('resized.jpg', 200);\n```\n\n### Resampling by height\n\nThis resamples the image to a new height, adjusting the width to keep the\noriginal image aspect ratio.\n\n```php\nuse AppUtils\\ImageHelper\\ImageFiles\\FileTypes\\JPGFile;\n\nJPGFile::factory('image.jpg')\n    -\u003eresampleByHeight('resized.jpg', 200);\n```\n\n### Resampling without the aspect ratio\n\nThis resamples the image to a new width and height, ignoring the original\nimage aspect ratio.\n\n```php\nuse AppUtils\\ImageHelper\\ImageFiles\\FileTypes\\JPGFile;\n\nJPGFile::factory('image.jpg')\n    -\u003eresample('resized.jpg', 200, 400);\n```\n\n### Displaying an image in the browser\n\nSend an image file to the browser for display.\nThis automatically sets the correct headers for the \nimage format.\n\n```php\nuse AppUtils\\ImageHelper\\ImageFiles\\FileTypes\\JPGFile;\n\nJPGFile::factory('image.jpg')\n    -\u003esend('optional-name.jpg');\n\n// You must manually exit the script after sending the image.\nexit;\n```\n\n### Trigger the download of an image\n\nThis will send the image to the browser, and force it to\ntreat it as a download and show the download dialog.\n\n```php\nuse AppUtils\\ImageHelper\\ImageFiles\\FileTypes\\JPGFile;\n\nJPGFile::factory('image.jpg')\n    // Set the second parameter to true to force the download.\n    -\u003esend('optional-name.jpg', true);\n\n// You must manually exit the script after sending the image.\nexit;\n```\n\n## Advanced editing\n\n### The ImageHelper class\n\nWhile the image file classes are practical for simple operations, the \n`ImageHelper` class provides more advanced editing capabilities, as\nwell as combining multiple operations in a single chain.\n\n### Creating an instance\n\n```php\nuse AppUtils\\ImageHelper;\nuse AppUtils\\ImageHelper\\ImageFiles\\FileTypes\\JPGFile;\n\n// From a file path\n$helper = ImageHelper::createFromFile('image.jpg');\n\n// From an image class\n$helper = JPGFile::factory('image.jpg')-\u003ecreateImageHelper();\n\n// From a GD resource    \n$resource = imagecreatefromjpeg('image.jpg');\n$helper = ImageHelper::createFromResource($resource);\n\n// New blank image\n$helper = ImageHelper::createNew(200, 100);\n```\n\n### Examples\n\n#### Resampling an image\n\n```php\nuse AppUtils\\ImageHelper;\n\nImageHelper::createFromFile('image.jpg')\n    -\u003eresampleByWidth(200)\n    -\u003esave('resized.jpg');\n```\n\n#### Sharpening an image\n\nThis will sharpen the image by the given percentage.\n\n\u003e NOTE: For best results, do some testing to find the \n\u003e optimal sharpening percentage for your target image size.\n\n```php\nuse AppUtils\\ImageHelper;\n\nImageHelper::createFromFile('image.jpg')\n    -\u003eresampleByWidth(200)\n    -\u003esharpen(50)\n    -\u003esetQuality(80)\n    -\u003esave('sharpened.jpg');\n```\n\n#### Get image dimensions (including SVG)\n\n```php\nuse AppUtils\\ImageHelper;\n\n$size = ImageHelper::getImageSize('image.jpg');\n\necho $size-\u003etoReadableString();\n```\n\n### Freeing resources\n\nWhen you're done editing, call the `dispose()` method to \nrelease file handles and memory resources. By default, \nthe `save()` method will automatically do this for you.\nIn case you're not saving the image, you should call\n`dispose()` manually.\n\n```php\nuse AppUtils\\ImageHelper;\n\n$average = ImageHelper::createFromFile('image.jpg')\n    -\u003ecalcAverageColorRGB();\n\n// Not needed anymore? Free up resources.    \n$helper-\u003edispose();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fapplication-utils-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmistralys%2Fapplication-utils-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fapplication-utils-image/lists"}