{"id":19258928,"url":"https://github.com/lassehaslev/image-handler","last_synced_at":"2026-06-10T23:31:11.183Z","repository":{"id":57012585,"uuid":"61963574","full_name":"LasseHaslev/image-handler","owner":"LasseHaslev","description":"PHP image handler gives easy to use function for manipulating images","archived":false,"fork":false,"pushed_at":"2017-04-28T12:35:01.000Z","size":7205,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-05T09:29:05.648Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/LasseHaslev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-25T22:09:10.000Z","updated_at":"2023-03-05T01:46:03.000Z","dependencies_parsed_at":"2022-08-21T15:10:18.892Z","dependency_job_id":null,"html_url":"https://github.com/LasseHaslev/image-handler","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Fimage-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Fimage-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Fimage-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LasseHaslev%2Fimage-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LasseHaslev","download_url":"https://codeload.github.com/LasseHaslev/image-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240356192,"owners_count":19788513,"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-09T19:14:49.391Z","updated_at":"2026-06-10T23:31:11.157Z","avatar_url":"https://github.com/LasseHaslev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# image-handler\nPHP image handler gives easy to use function for manipulating images\n\n## Motivation\n\nResizing and cropping images on web is pain, and i wanted an image-engine that does this for me.\n\nThis package and its base concept is greatly inspired by [Croppa](https://github.com/BKWLD/croppa).\n\n## Usage\nI use this package mainly in my [Laravel](https://laravel.com/) projects.\n\nRun ```composer require lassehaslev/image``` in your project folder\n\n#### Laravel\nIf you want to use this package in you laravel project. We automaticly crops and resize the images based on the filename.\n\nOpen ```config/app.php``` and add ```LasseHaslev\\Image\\Providers\\LaravelServiceProvider::class``` to ```providers``` array.\n\n## Classes\nYou can nativly use this package in all php projects.\n\n#### CropHandler\nAdds base folder and crops folder and handle image from image path.\n\nIf no crops folder is set, we crate crops in same folder as original.\n```php\n$baseFolder = '/image';\n$cropsFolder = '/image/crops';\n$handler = CropHandler::create( $baseFolder, $cropsFolder );\n\n$this-\u003ehandler\n    -\u003ehandle( [\n        'name'=\u003e'test-image.jpg',\n        'width'=\u003e89,\n        'height'=\u003e89,\n        'resize'=\u003etrue,\n    ] )\n    -\u003esave( 'test-image-89x89-resize.jpg' );\n```\n\n#### Adaptors\nYou can use adapotors to handle image.\n```php\nclass Adaptor implements CropAdaptorInterface\n{\n    public function transform( $input, $handler = null )\n    {\n        return [\n            'name'=\u003e$input,\n            'width'=\u003e300,\n            'height'=\u003e200,\n            'resize'=\u003etrue,\n        ];\n    }\n}\n$baseFolder = '/image';\n$cropsFolder = '/image/crops';\n$handler = CropHandler::create( $baseFolder, $cropsFolder, new Adaptor );\n\n$this-\u003ehandler\n    -\u003ehandle( 'originalFilename.jpg' )\n    -\u003esave( 'newFilename' );\n```\n#### ImageModifier\nThe ```ImageModifier``` is the base image class for manipulating the images. \n```php\nuse LasseHaslev\\Image\\Modifiers\\ImageModifier;\n$modifier = ImageModifier::create( { absolute image path } );\n\n// Crop image function\n$modifier-\u003ecrop( $x1, $y1, $x2, $y2 );\n\n// Crop image to width and height based on fucuspoint\n$modifier-\u003ecropToFit( $width, $height, $focusPointX = 0, $focusPointY = 0 );\n\n// Resize width and height\n$modifier-\u003eresize( $width, $height );\n\n// Save the new image\n$modifier-\u003esave( {absolutePath} );\n\n// Example\n$modifier-\u003ecropToFit( 300, 300 )\n    -\u003esave( '/path/to/image.jpg' );\n```\n\n#### ImageHandler\nThe ImageHandler is for handling image and the crops. It extends from ```ImageModifier```.\n```php\nuse LasseHaslev\\Image\\Handlers\\ImageHandler;\n$modifier = ImageHandler::create( $filepath );\n\n// Remove the crops\n$modifier-\u003eremoveCrops();\n\n// Save\n$modifier-\u003esave( $pathOrFilename, $isFullPath = false );\n```\n\n## Development\nI have a problem with my tests. but i dont know why. Sometimes it passes and sometimes it dont.\n``` bash\n# Prepare test images\nsh prepare.sh\n\n# Install php dependencies\ncomposer install\n\n# Install elixir dependencies\nnpm install\n\n# run Test driven development through elixir\ngulp tdd\n```\n``\n\n## License\nMIT, dawg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flassehaslev%2Fimage-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flassehaslev%2Fimage-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flassehaslev%2Fimage-handler/lists"}