{"id":19162320,"url":"https://github.com/agilie/canvas-image-cover-position","last_synced_at":"2025-05-07T10:41:22.516Z","repository":{"id":57095554,"uuid":"93735240","full_name":"agilie/canvas-image-cover-position","owner":"agilie","description":"Calculating image position for scaling it on the canvas.","archived":false,"fork":false,"pushed_at":"2020-06-08T23:55:28.000Z","size":204,"stargazers_count":40,"open_issues_count":1,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-13T08:58:37.762Z","etag":null,"topics":["background-image","canvas","cover","image","javascript","size-calculation"],"latest_commit_sha":null,"homepage":"https://agilie.com","language":"HTML","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/agilie.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":"2017-06-08T10:07:02.000Z","updated_at":"2024-10-24T06:16:29.000Z","dependencies_parsed_at":"2022-08-22T23:10:20.759Z","dependency_job_id":null,"html_url":"https://github.com/agilie/canvas-image-cover-position","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agilie%2Fcanvas-image-cover-position","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agilie%2Fcanvas-image-cover-position/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agilie%2Fcanvas-image-cover-position/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agilie%2Fcanvas-image-cover-position/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agilie","download_url":"https://codeload.github.com/agilie/canvas-image-cover-position/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252861748,"owners_count":21815741,"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":["background-image","canvas","cover","image","javascript","size-calculation"],"created_at":"2024-11-09T09:10:01.096Z","updated_at":"2025-05-07T10:41:22.468Z","avatar_url":"https://github.com/agilie.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/agilie/canvas-image-cover-position)\n\n# Calculate cover size\nThis method is helpful for calculating size and position of one element to fill another element. A behavior is the same as css property 'background-size: cover;'\n\n![Preview](img/Image.png)\n![Preview](img/Image_cover.png)\n```typescript\ninterface CoverSize = {\n    width: number;\n    height: number;\n    offsetLeft: number;\n    offsetTop: number;\n}\n\ntype getCoverSize = (\n    contentWidth: number,\n    contentHeight: number,\n    containerWidth: number,\n    containerHeight: number,\n    offsetLeft: number = 0.5, \n    offsetTop: number = 0.5) =\u003e CoverSize\n```\nOffsets values are in range between 0 an 1\n## Installation \nJust add file or function to your project\n\n```html\n\u003cscript src=\"https://unpkg.com/@agilie/canvas-image-cover-position\"\u003e\u003c/script\u003e\n```\n\n**or**\n\n```bash\n$ npm install @agilie/canvas-image-cover-position\n```\n## How to use\n```javascript\nimport getCoverSize from '@agilie/canvas-image-cover-position'\n\nvar imageCoverSize = getCoverSize(\n    image.naturalWidth,\n    image.naturalHeight,\n    canvas.width,\n    canvas.height,\n    0.5,\n    0.5\n);\ncanvas.getContext('2d').drawImage(\n    image,\n    imageCoverSize.offsetLeft,\n    imageCoverSize.offsetTop,\n    imageCoverSize.width,\n    imageCoverSize.height\n);\n```\n\u003ca href=\"https://agilie.github.io/canvas-image-cover-position/\" style=\"font-size: 20px\" target=\"_blank\"\u003edemo\u003c/a\u003e\n\n## Troubleshooting\nProblems? Check the [Issues](https://github.com/agilie/canvas-image-cover-position/issues) block \nto find the solution or create an new issue that we will fix asap. Feel free to contribute.\n\n## Author\nThis method is open-sourced by [Agilie Team](https://www.agilie.com) \u003cinfo@agilie.com\u003e\n\n## Contributors\n[Agilie Team](https://github.com/agilie)\n\n## Contact us\nIf you have any questions, suggestions or just need a help with web or mobile development, please email us at \u003cweb@agilie.com\u003e. You can ask us anything from basic to complex questions. \n\nWe will continue publishing new open-source projects. Stay with us, more updates will follow!\n\n## License\nThe [MIT](LICENSE) License (MIT) Copyright © 2019 [Agilie Team](https://www.agilie.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagilie%2Fcanvas-image-cover-position","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagilie%2Fcanvas-image-cover-position","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagilie%2Fcanvas-image-cover-position/lists"}