{"id":19651807,"url":"https://github.com/tanaikech/cropimagebyborder_js","last_synced_at":"2025-04-28T16:31:49.284Z","repository":{"id":55062403,"uuid":"522850201","full_name":"tanaikech/CropImageByBorder_js","owner":"tanaikech","description":"This is a Javascript library for cropping images by the border.","archived":false,"fork":false,"pushed_at":"2022-08-10T00:57:35.000Z","size":8,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T09:51:08.278Z","etag":null,"topics":["image-processing","javascript","javascript-library","library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/tanaikech.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":"2022-08-09T07:40:01.000Z","updated_at":"2025-02-12T10:29:50.000Z","dependencies_parsed_at":"2022-08-14T10:40:36.508Z","dependency_job_id":null,"html_url":"https://github.com/tanaikech/CropImageByBorder_js","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FCropImageByBorder_js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FCropImageByBorder_js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FCropImageByBorder_js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FCropImageByBorder_js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanaikech","download_url":"https://codeload.github.com/tanaikech/CropImageByBorder_js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251345996,"owners_count":21574813,"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":["image-processing","javascript","javascript-library","library"],"created_at":"2024-11-11T15:08:09.547Z","updated_at":"2025-04-28T16:31:49.015Z","avatar_url":"https://github.com/tanaikech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Javascript Library for Cropping Image by Border\n\n\u003ca name=\"top\"\u003e\u003c/a\u003e\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENCE)\n\n\u003ca name=\"overview\"\u003e\u003c/a\u003e\n\n# Overview\n\nThis is a Javascript library for cropping images by the border.\n\n\u003ca name=\"description\"\u003e\u003c/a\u003e\n\n# Description\n\nWhen an image is used, there is a case where I wanted to simply crop the image by a script. In this Javascript library, the image is cropped by a border. The sample situation is as follows.\n\n![](https://tanaikech.github.io/image-storage/20220809a/fig1.png)\n\nIn this sample situation, a red rectangle is enclosed by a border (1 pixel) with \"#000000\". By this border, this library crops the red rectangle. In this case, the 1-pixel border is not included in the resulting image.\n\n\u003ca name=\"install\"\u003e\u003c/a\u003e\n\n# Install\n\n```html\n\u003cscript src=\"cropImageByBorder_js.min.js\"\u003e\u003c/script\u003e\n```\n\nOr, using jsdelivr cdn\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/tanaikech/CropImageByBorder_js@latest/cropImageByBorder_js.min.js\"\u003e\u003c/script\u003e\n```\n\n# Usage\n\nThis library is used for cropping the image by the border. The simple sample script is as follows.\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/tanaikech/CropImageByBorder_js@latest/cropImageByBorder_js.min.js\"\u003e\u003c/script\u003e\n\n\u003cbody\u003e\n  \u003cinput type=\"file\" accept=\"image/png\" onchange=\"main(this)\" /\u003e\n\u003c/body\u003e\n\n\u003cscript\u003e\n  function main(e) {\n    const filename = \"sample.png\";\n    const file = e.files[0];\n    const fr = new FileReader();\n    fr.readAsDataURL(file);\n    fr.onload = async (f) =\u003e {\n      const obj = { borderColor: \"#000000\", base64Data: f.target.result };\n      const base64 = await CropImageByBorder.getInnerImage(obj).catch((err) =\u003e\n        console.log(err)\n      );\n      const link = document.createElement(\"a\");\n      link.download = filename;\n      link.href = base64;\n      document.body.appendChild(link);\n      link.click();\n      document.body.removeChild(link);\n      delete link;\n    };\n  }\n\u003c/script\u003e\n```\n\nWhen this HTML is opened, you can see the file input tag. When you put a sample PNG file including a border of \"#000000\", the cropped image is returned.\n\n## Options\n\nIn the current version, the method of `getInnerImage` has 1 argument like `CropImageByBorder.getInnerImage(obj)`. The cropping is done using **Canvas API**. [Ref](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API)\n\n- `obj` : This is an object including the border color and data.\n\n  - `borderColor`: Border color. This library crops the image using this border. Please set the color as the HEX like `#000000`.\n  - `base64Data`: In this case, the data is required to be base64 data including the header like `data:image/png;base64,` for PNG.\n  - `offset`: If the result image shows the border, please adjust this value. The default value is `2` pixel.\n\n- Returned value: Promise is returned. And, in this library, the output image is returned as base64 data including the header of `data:image/png;base64,`. The default output mimeType is `image/png`.\n\n---\n\n\u003ca name=\"licence\"\u003e\u003c/a\u003e\n\n# Licence\n\n[MIT](LICENCE)\n\n\u003ca name=\"author\"\u003e\u003c/a\u003e\n\n# Author\n\n[Tanaike](https://tanaikech.github.io/about/)\n\nIf you have any questions and commissions for me, feel free to tell me.\n\n\u003ca name=\"updatehistory\"\u003e\u003c/a\u003e\n\n# Update History\n\n- v1.0.0 (August 9, 2022)\n\n  1. Initial release.\n\n- v1.0.1 (August 10, 2022)\n\n  1. `offset` is added.\n\n[TOP](#top)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanaikech%2Fcropimagebyborder_js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanaikech%2Fcropimagebyborder_js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanaikech%2Fcropimagebyborder_js/lists"}