{"id":18783681,"url":"https://github.com/tomkyle/yaphr","last_synced_at":"2025-12-20T18:30:17.146Z","repository":{"id":21919596,"uuid":"25243816","full_name":"tomkyle/yaphr","owner":"tomkyle","description":"Yet Another Photo Resizer: Resizing and cropping, crisp \u0026 useful sharpening.","archived":false,"fork":false,"pushed_at":"2015-04-14T10:00:30.000Z","size":1151,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T11:45:34.376Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomkyle.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":"2014-10-15T07:33:38.000Z","updated_at":"2015-04-14T10:00:27.000Z","dependencies_parsed_at":"2022-07-21T21:02:16.254Z","dependency_job_id":null,"html_url":"https://github.com/tomkyle/yaphr","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomkyle%2Fyaphr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomkyle%2Fyaphr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomkyle%2Fyaphr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomkyle%2Fyaphr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomkyle","download_url":"https://codeload.github.com/tomkyle/yaphr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239699579,"owners_count":19682574,"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-07T20:40:06.585Z","updated_at":"2025-12-20T18:30:17.042Z","avatar_url":"https://github.com/tomkyle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"#tomkyle\\yaphr\n\n[![Build Status](https://travis-ci.org/tomkyle/yaphr.svg?branch=master)](https://travis-ci.org/tomkyle/yaphr)\n\nYet Another Photo Resizer for JPG, PNG, GIF.  \nResizing and cropping, crisp \u0026 useful sharpening.\n\n\n##Installation\n\nYaphr has no dependencies so far, although but installing [Slim](https://github.com/codeguy/Slim) may be useful: Yaphr brings it own Slim Middleware for the most common resizing use cases. Install via Composer; add this to `composer.json`:\n\n```\n\"require\": {\n\t\"tomkyle/yaphr\": \"~1.1\"\n}\n```\n\n##Getting started\n\nYaphr comes with a convenience workflow that does most of the business for you:\n\n```php\nuse \\tomkyle\\yaphr\\ImageFactory;\nuse \\tomkyle\\yaphr\\Geometry\\BoxFactory;\nuse \\tomkyle\\yaphr\\Workflow;\nuse \\SplFileInfo;\n\n// YAPHR likes `SplFileInfo`\n$source = new SplFileInfo( '../master/path/to/original.jpg' );\n$output = new SplFileInfo( './path/to/resized.jpg' );\n\n// Generate factories:\n$image_factory = new ImageFactory;\n$box_factory   = new BoxFactory;\n\n// Grab your instances:\n$image  = $image_factory-\u003enewInstance( $source );\n$box    = $box_factory-\u003enewInstance( 300, 200, $image, 'crop');\n\n// Convenience, convenience:\n// Resize, Sharpen, Save to cache \n// and Delivery to client in one step:\nnew Workflow( $image, $box, $output);\n```\n\nSo the `Workflow` is your friend. This example shows what happens inside:\n\n```php\nuse \\tomkyle\\yaphr\\Resize;\nuse \\tomkyle\\yaphr\\Filters\\SharpenImage;\nuse \\tomkyle\\yaphr\\FileSystem\\CreateCacheDir;\nuse \\tomkyle\\yaphr\\FileSystem\\SaveImage;\nuse \\tomkyle\\yaphr\\FileSystem\\DeliverImage;\n\n// Create resized (cropped) image:\n$resized = new Resize($image, $box);\n\n// Make it nice and crisp:\nnew SharpenImage( $resized );\n\n// Save to file cache:\nnew CreateCacheDir( $output, 0775 );\nnew SaveImage( $resized, $output, 85 );\n\n// Send to client:\nnew DeliverImage( $output, \"exit\" );\n```\n\n\n\n\n##Resize boxes\nYaphr offers various resizing modes, all of them useful in different use cases. If you exactly know what you want, you may instantiate a concrete Box class; using the `BoxFactory` with string parameter gives more flexibility: Just pass desired `$width` and `$height`, your original `$image` and the box type.\n\n**Crop** extracts as much as possible from the original that fits into the given width and height. Most useful for pictures with varying side ratios, e.g. in responsive context.\n```php\n$exact = new CropBox( $width, $height, $image );\n// same as\n$exact = $box_factory-\u003enewInstance( $width, $height, $image, 'crop');\n```\n\n**Auto** makes portrait images `$height` pixels high, and landscape ones `$width` pixels, preserving side ratios. Perhaps the most classic resing mode.\n```php\n$exact = new AutoBox( $width, $height, $image );\n// same as\n$exact = $box_factory-\u003enewInstance( $width, $height, $image, 'auto');\n```\n\n**Exact** fits the image in the given width and height, not preserving side ratio (i.e. the result may be distorted). Mostly not useful (except from, well, distorting).\n```php\n$exact = new Box( $width, $height );\n// same as\n$exact = $box_factory-\u003enewInstance( $width, $height, $image, 'exact');\n```\n\n**Tall** resizes to the given height, regardless of the image width, but preserving side ratios. Useful for horizontal “same height” galleries or *Masonry galleries*.\n```php\n$exact = new TallBox( $height, $image );\n// same as\n$exact = $box_factory-\u003enewInstance( $height, $height, $image, 'tall');\n```\n\n**Wide** resizes to the given width, regardless of the image height, but preserving side ratios. Useful for vertical “same width” galleries.\n```php\n$exact = new WideBox( $width, $image );\n// same as\n$exact = $box_factory-\u003enewInstance( $width, $width, $image, 'wide');\n```\n\n\n\n\n##Classes overview\n\n###Image classes\n\n```php\n# Classes\nuse \\tomkyle\\yaphr\\GifImage;\nuse \\tomkyle\\yaphr\\JpegImage;\nuse \\tomkyle\\yaphr\\PngImage;\n\n# Abstracts and Interfaces\nuse \\tomkyle\\yaphr\\ImageAbstract;\nuse \\tomkyle\\yaphr\\ImageInterface;\nuse \\tomkyle\\yaphr\\GifImageInterface;\nuse \\tomkyle\\yaphr\\JpegImageInterface;\nuse \\tomkyle\\yaphr\\PngImageInterface;\n```\n\n###Business classes\n\n```php\n# Classes\nuse \\tomkyle\\yaphr\\ImageFactory;\nuse \\tomkyle\\yaphr\\Workflow;\nuse \\tomkyle\\yaphr\\Resize;\n```\n\n\n\n###Geometry classes\n\n```php\n# Boxes\nuse \\tomkyle\\yaphr\\Geometry\\Box;\nuse \\tomkyle\\yaphr\\Geometry\\BoxFactory;\nuse \\tomkyle\\yaphr\\Geometry\\AutoBox;\nuse \\tomkyle\\yaphr\\Geometry\\CropBox;\nuse \\tomkyle\\yaphr\\Geometry\\SquareBox;\nuse \\tomkyle\\yaphr\\Geometry\\TallBox;\nuse \\tomkyle\\yaphr\\Geometry\\WideBox;\n\n# Coordinates\nuse \\tomkyle\\yaphr\\Geometry\\CropStartCoordinates;\nuse \\tomkyle\\yaphr\\Geometry\\NullCoordinates;\n\n# Abstracts and Interfaces\nuse \\tomkyle\\yaphr\\Geometry\\CoordinatesInterface;\nuse \\tomkyle\\yaphr\\Geometry\\BoxAbstract;\nuse \\tomkyle\\yaphr\\Geometry\\BoxInterface;\nuse \\tomkyle\\yaphr\\Geometry\\CropBoxInterface;\n```\n\n###Image filter classes\n```php\n# Classes\nuse \\tomkyle\\yaphr\\Filters\\SharpenImage;\nuse \\tomkyle\\yaphr\\Filters\\UnsharpMask; # experimental\n```\n\n\n###File system classes\n\n```php\n# Classes\nuse \\tomkyle\\yaphr\\FileSystem\\CreateCacheDir;\nuse \\tomkyle\\yaphr\\FileSystem\\CheckReadableFile;\nuse \\tomkyle\\yaphr\\FileSystem\\DeliverImage;\nuse \\tomkyle\\yaphr\\FileSystem\\FileExtension;\nuse \\tomkyle\\yaphr\\FileSystem\\SaveImage;\nuse \\tomkyle\\yaphr\\FileSystem\\SaveGif;\nuse \\tomkyle\\yaphr\\FileSystem\\SaveJpeg;\nuse \\tomkyle\\yaphr\\FileSystem\\SavePng;\n\n# Abstracts and Interfaces\nuse \\tomkyle\\yaphr\\FileSystem\\SaveImageAbstract;\nuse \\tomkyle\\yaphr\\FileSystem\\SaveImageInterface;\n```\n\n###Exceptions\n\n```php\n# Classes and Interfaces\nuse \\tomkyle\\yaphr\\Exceptions\\FileNotFound;\nuse \\tomkyle\\yaphr\\Exceptions\\YaphrException;\nuse \\tomkyle\\yaphr\\Exceptions\\YaphrExceptionInterface;\n```\n\n###PHP resource aggregation\n\n```php\n# Interfaces and traits\nuse \\tomkyle\\yaphr\\Resources\\ResourceAggregate;\nuse \\tomkyle\\yaphr\\Resources\\ResourceAggregateTrait;\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomkyle%2Fyaphr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomkyle%2Fyaphr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomkyle%2Fyaphr/lists"}