{"id":16528581,"url":"https://github.com/yeonjuan/mode-image","last_synced_at":"2025-08-03T22:39:23.007Z","repository":{"id":57300372,"uuid":"394980861","full_name":"yeonjuan/mode-image","owner":"yeonjuan","description":null,"archived":false,"fork":false,"pushed_at":"2021-08-14T10:59:10.000Z","size":281,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-03T20:30:38.559Z","etag":null,"topics":["cavnas","crop","image-manipulation","image-processing","resize"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/yeonjuan.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":"2021-08-11T12:27:20.000Z","updated_at":"2021-08-18T02:13:16.000Z","dependencies_parsed_at":"2022-09-07T15:21:53.997Z","dependency_job_id":null,"html_url":"https://github.com/yeonjuan/mode-image","commit_stats":null,"previous_names":["yeonjuan/mod-image"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yeonjuan/mode-image","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeonjuan%2Fmode-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeonjuan%2Fmode-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeonjuan%2Fmode-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeonjuan%2Fmode-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yeonjuan","download_url":"https://codeload.github.com/yeonjuan/mode-image/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeonjuan%2Fmode-image/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268624130,"owners_count":24280148,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cavnas","crop","image-manipulation","image-processing","resize"],"created_at":"2024-10-11T17:40:55.805Z","updated_at":"2025-08-03T22:39:22.984Z","avatar_url":"https://github.com/yeonjuan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mode-image\n\nSimple image editing library.\n\n- [Installation](#installation)\n- [Usage](#Usage)\n- [License](#license)\n\n## Installation\n\n- npm\n  ```console\n  npm install mode-image\n  ```\n- yarn\n  ```console\n  yarn add mode-image\n  ```\n\n## Usage\n\n- [modeImage](#modeimageimage-source)\n- [rotate](#rotateradian)\n- [resize](#resizesize)\n- [crop](#croparea)\n- [repeatX](#repeatxnum)\n- [repeatY](#repeatynum)\n- [merge](#mergeimage)\n- [toDataURL](#todataurl)\n\n### modeImage(_image source_)\n\nWe can specify image source to editing using `modeImage(image source)`.\n\n- Image URL\n\n  \u003c!-- prettier-ignore-start --\u003e\n\n  ```js\n  modeImage(\"/public/foo.png\")\n    .rotate(angle)\n    .crop(area)\n    // ...\n    .toDataURL()\n    .then((result) =\u003e {\n      result; // data:image/png;base64,R0lGOD....\n    });\n  ```\n\n  \u003c!-- prettier-ignore-end --\u003e\n\n- Data URL\n\n  The URLs string prefixed with the `data:image/...` scheme. see [MDN Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs)\n\n  \u003c!-- prettier-ignore-start --\u003e\n\n  ```js\n  modeImage(\"data:image/png;base64,R0lGOD....\")\n    .rotate(angle)\n    .crop(area)\n    // ...\n    .toDataURL()\n    .then((result) =\u003e {\n      result; // data:image/png;base64,R0lGOD....\n    });\n  ```\n\n  \u003c!-- prettier-ignore-end --\u003e\n\n- HTMLImageElement\n\n  The instance of [HTMLImageElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement).\n\n  \u003c!-- prettier-ignore-start --\u003e\n\n  ```js\n  const image = new Image();\n  image.src = \"https://...\";\n\n  modeImage(image)\n    .rotate(angle)\n    .crop(area)\n    // ...\n    .toDataURL()\n    .then((result) =\u003e {\n      result; // data:image/png;base64,R0lGOD....\n    });\n  ```\n\n  \u003c!-- prettier-ignore-end --\u003e\n\n- in NodeJS\n\n  In NodeJS, we should use custom image, canvas creator. see [node-canvas](https://github.com/Automattic/node-canvas).\n\n  \u003c!-- prettier-ignore-start --\u003e\n\n  ```js\n  import { createCanvas, Image, loadImage } from \"canvas\";\n\n  const options = {\n    createCanvas: createCanvas,\n    createImage: () =\u003e new Image(),\n  };\n  const image = await loadImage(\"./path/foo.png\");\n  modeImage(image, options)\n    .rotate()\n    .toDataURL()\n    .then((result) =\u003e {\n      result; // data:image/png;base64,R0lGOD....\n    });\n  ```\n\n  \u003c!-- prettier-ignore-end --\u003e\n\n### .rotate(_radian_)\n\n- radian (number): The rotation angle, clockwise in radians.\n\n#### example\n\n| /origin.png (100 x 100)                                  | result (100 x 100)                                                                        |\n| -------------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| \u003cimg src=\"./tests/__fixtures__/right-arrow-100-100.png\"\u003e | \u003cimg src=\"./tests/__image_snapshots__/rotate-test-ts-rotate-90-deg-100-x-100-1-snap.png\"\u003e |\n\n\u003c!-- prettier-ignore-start --\u003e\n```js\nimport modeImage from \"mode-image\";\n\nconst result = await modeImage(\"/origin.png\")\n  .rotate((Math.PI / 180) * 90)\n  .toDataUrl();\n// data:image/png;base64,...\n```\n\u003c!-- prettier-ignore-end --\u003e\n\n### .resize(_size_)\n\n- size (object):\n  - width (number): The height to change.\n  - height (number): The width to change.\n\n#### example\n\n| /origin.png (150 x 150)                            | result (50 x 50)                                                                              |\n| -------------------------------------------------- | --------------------------------------------------------------------------------------------- |\n| \u003cimg src=\"./tests/__fixtures__/smile-150-150.png\"\u003e | \u003cimg src=\"./tests/__image_snapshots__/resize-test-ts-resize-150-x-150-to-50-x-50-1-snap.png\"\u003e |\n\n\u003c!-- prettier-ignore-start --\u003e\n```js\nimport modeImage from \"mode-image\";\n\nconst result = await modeImage(\"/origin.png\")\n  .resize({\n    width: 50,\n    height: 50,\n  })\n  .toDataUrl();\n// data:image/png;base64,...\n```\n\u003c!-- prettier-ignore-end --\u003e\n\n### .crop(_area_)\n\n- area (object):\n  - x (number): The pixels from left side.\n  - y (number): The Pixels from right side.\n  - width (number): The width pixels of the crop.\n  - height (number): The height pixels of the crop.\n\n#### example\n\n| /origin.png (150 x 150)                            | result (50 x 50)                                                                          |\n| -------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| \u003cimg src=\"./tests/__fixtures__/smile-150-150.png\"\u003e | \u003cimg src=\"./tests/__image_snapshots__/crop-test-ts-crop-150-x-150-to-50-x-50-2-snap.png\"\u003e |\n\n\u003c!-- prettier-ignore-start --\u003e\n```js\nimport modeImage from \"mode-image\";\n\nconst result = await modeImage(\"/origin.png\")\n  .crop({\n    x: 50,\n    y: 50,\n    width: 50,\n    height: 50,\n  })\n  .toDataUrl();\n// data:image/png;base64,...\n```\n\u003c!-- prettier-ignore-end --\u003e\n\n### .repeatX(_num_)\n\n- num (number): The number of times to repeat.\n\n#### example\n\n| /origin.png (150 x 150)                           | result (450 x 150)                                                                             |\n| ------------------------------------------------- | ---------------------------------------------------------------------------------------------- |\n| \u003cimg src=\"./tests/__fixtures__/walk-150-150.png\"\u003e | \u003cimg src=\"./tests/__image_snapshots__/repeat-x-test-ts-repeat-x-3-times-150-x-150-1-snap.png\"\u003e |\n\n\u003c!-- prettier-ignore-start --\u003e\n```js\nimport modeImage from \"mode-image\";\n\nconst result = await modeImage(\"/origin.png\")\n  .repeatX(3)\n  .toDataUrl();\n// data:image/png;base64,...\n```\n\u003c!-- prettier-ignore-end --\u003e\n\n### .repeatY(_num_)\n\n- num (number): The number of times to repeat.\n\n#### example\n\n| /origin.png (150 x 150)                           | result (150 x 300)                                                                             |\n| ------------------------------------------------- | ---------------------------------------------------------------------------------------------- |\n| \u003cimg src=\"./tests/__fixtures__/walk-150-150.png\"\u003e | \u003cimg src=\"./tests/__image_snapshots__/repeat-y-test-ts-repeat-y-2-times-150-x-150-1-snap.png\"\u003e |\n\n\u003c!-- prettier-ignore-start --\u003e\n```js\nimport modeImage from \"mode-image\";\n\nconst result = await modeImage(\"/origin.png\")\n  .repeatY(2)\n  .toDataUrl();\n// data:image/png;base64,...\n```\n\u003c!-- prettier-ignore-end --\u003e\n\n### .merge(_image_)\n\n- image (image source): The image source merging with the current image. It support same data type with ``\n\n#### example\n\n| /left.png (100 x 50)                                   | /right.png (100 x 50)                                   | result (100 x 50)                                                                            |\n| ------------------------------------------------------ | ------------------------------------------------------- | -------------------------------------------------------------------------------------------- |\n| \u003cimg src=\"./tests/__fixtures__/left-arrow-100-50.png\"\u003e | \u003cimg src=\"./tests/__fixtures__/right-arrow-100-50.png\"\u003e | \u003cimg src=\"./tests/__image_snapshots__/merge-test-ts-merge-merge-100-x-50-100-50-1-snap.png\"\u003e |\n\n\u003c!-- prettier-ignore-start --\u003e\n```js\nimport modeImage from \"mode-image\";\n\nconst result = await modeImage(\"/left.png\")\n  .merge(\"/right.png\")\n  .toDataUrl();\n// data:image/png;base64,...\n```\n\u003c!-- prettier-ignore-end --\u003e\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeonjuan%2Fmode-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeonjuan%2Fmode-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeonjuan%2Fmode-image/lists"}