{"id":18510766,"url":"https://github.com/envato/aspect_ratio","last_synced_at":"2025-07-20T02:05:44.388Z","repository":{"id":54857802,"uuid":"57084892","full_name":"envato/aspect_ratio","owner":"envato","description":"Image aspect ratio calculation utility","archived":false,"fork":false,"pushed_at":"2024-10-06T05:21:24.000Z","size":25,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":62,"default_branch":"main","last_synced_at":"2025-06-25T04:29:35.366Z","etag":null,"topics":["aspect","ratio"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/envato.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}},"created_at":"2016-04-26T00:20:14.000Z","updated_at":"2025-01-24T03:25:34.000Z","dependencies_parsed_at":"2023-02-03T13:15:20.943Z","dependency_job_id":null,"html_url":"https://github.com/envato/aspect_ratio","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/envato/aspect_ratio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Faspect_ratio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Faspect_ratio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Faspect_ratio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Faspect_ratio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/envato","download_url":"https://codeload.github.com/envato/aspect_ratio/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Faspect_ratio/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266057171,"owners_count":23870120,"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":["aspect","ratio"],"created_at":"2024-11-06T15:24:57.091Z","updated_at":"2025-07-20T02:05:44.368Z","avatar_url":"https://github.com/envato.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aspect_ratio\n\n[![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/envato/aspect_ratio/blob/main/LICENSE)\n[![Gem Version](https://img.shields.io/gem/v/aspect_ratio.svg?maxAge=2592000)](https://rubygems.org/gems/aspect_ratio)\n[![Gem Downloads](https://img.shields.io/gem/dt/aspect_ratio.svg?maxAge=2592000)](https://rubygems.org/gems/aspect_ratio)\n[![Build Status](https://github.com/envato/aspect_ratio/workflows/tests/badge.svg?branch=main)](https://github.com/envato/aspect_ratio/actions?query=branch%3Amain+workflow%3Atests)\n\nImage aspect ratio utilities.\n\nThe Ruby port of [node-aspectratio](https://www.npmjs.com/package/aspectratio) npm module. \n\n## Install\n\nInstall globally\n\n```\ngem install aspect_ratio\n```\n\nOR\n\nInstall locally with Bundler\n\nPlease include \n\n```\ngem 'aspect_ratio'\n```\n\nin your `Gemfile` then `bundle install`\n\n## Test\n\n```\nruby test/aspect_ratio_test.rb\n```\n\n## API\n\n### crop(**integer** `width`, **integer** `height`, **string** `ratio`)\n\nApply a fixed aspect `ratio` crop without distoring the image aspect ratio.\n\n* **integer** `width` - original image width\n* **integer** `height` - original image height\n* **string** `ratio` - new image ratio\n\n\u003e The `ratio` must be on the following format: `x`:`y` where `x` and `y` are\n\u003e integers. The order of `x` and `z` does not matter and `3:4` will be treated\n\u003e as `4:3`.\n\n\u003e By default #crop() will match the orientation of the original image unless a\n\u003e forced orientation is given on the follwing format: `x`:`y`!`z` where `z` is\n\u003e the orientation (`v` for vertical, or `h` for horizontal).\n\n#### Return\n\nThis will return an `Array` of four values:\n\n1. **integer** `x` - top lef x coordinate\n2. **integer** `y` - top lef y coordinate\n3. **integer** `width` - new image width\n4. **integer** `height` - new image height\n\n#### Example\n\n```ruby\nrequire 'aspect_ratio'\nAspectRatio.crop(2048, 768, '4:3');\n// [512, 768, 1024, 768]\n```\n\n![Crop with fixed ratio](./aspect.png)\n\n### resize(**integer** `x`, **integer** `y`, **integer** `maxX`, **integer** `maxY`, **boolean** `enlarge`)\n\nGet resized height and width of an image while perserving the aspect ratio of\nthe image.\n\n* **integer** `x` - original image width\n* **integer** `y` - original image height\n* **integer** `maxX` - max image width\n* **integer** `maxY` - max image height\n* **boolean** `enlarge` - enlarge when original is smaller than the max - default true\n\n### Return\n\nReturns an `Array` of the resized `x` and `y` values:\n\n* **integer** `x` - resized image width\n* **integer** `y` - resized image height\n\n#### Example\n\n```ruby\nrequire 'aspect_ratio'\nAspectRatio.resize(2048, 768, 640, 640);\n// [640, 240]\n```\n\n## [MIT License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Faspect_ratio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenvato%2Faspect_ratio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Faspect_ratio/lists"}