{"id":13561748,"url":"https://github.com/useflyyer/use-smartcrop","last_synced_at":"2025-08-21T02:31:23.627Z","repository":{"id":38426082,"uuid":"354884671","full_name":"useflyyer/use-smartcrop","owner":"useflyyer","description":"React hook for smartcrop.js to content aware image cropping with points of interest and facial recognition.","archived":false,"fork":false,"pushed_at":"2023-01-07T23:49:05.000Z","size":1195,"stargazers_count":103,"open_issues_count":10,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-08T00:12:18.682Z","etag":null,"topics":["color","flyyer","image-recognition","react","react-hooks","smartcrop","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/use-smartcrop","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/useflyyer.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-04-05T15:41:15.000Z","updated_at":"2024-07-03T22:42:04.000Z","dependencies_parsed_at":"2023-02-08T03:31:44.514Z","dependency_job_id":null,"html_url":"https://github.com/useflyyer/use-smartcrop","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/useflyyer%2Fuse-smartcrop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/useflyyer%2Fuse-smartcrop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/useflyyer%2Fuse-smartcrop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/useflyyer%2Fuse-smartcrop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/useflyyer","download_url":"https://codeload.github.com/useflyyer/use-smartcrop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230479864,"owners_count":18232630,"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":["color","flyyer","image-recognition","react","react-hooks","smartcrop","typescript"],"created_at":"2024-08-01T13:01:00.681Z","updated_at":"2024-12-19T18:15:36.857Z","avatar_url":"https://github.com/useflyyer.png","language":"JavaScript","readme":"# use-smartcrop\n\nThis is the React Hook version of [jwagner/smartcrop.js](https://github.com/jwagner/smartcrop.js/) + [lokesh/color-thief](https://github.com/lokesh/color-thief) with Typescript support.\n\nWe made this hook for [Flyyer.io](https://www.flyyer.io?ref=github) to enable developers to create content-aware marketing and social images but it is useful for any kind of project.\n\n![example of content aware cropping](.github/image.png)\n\n## Usage\n\nInstall this dependency:\n\n```sh\nyarn add use-smartcrop\n```\n\nBy default images are loading with `crossOrigin=\"\"` prop. [See this StackOverflow thread](https://stackoverflow.com/questions/22097747/how-to-fix-getimagedata-error-the-canvas-has-been-tainted-by-cross-origin-data).\n\nCommon case usage:\n\n```tsx\nimport React from \"react\";\nimport { useSmartcrop, SmartcropStatus } from \"use-smartcrop\";\n\nfunction App() {\n  const src = \"https://images.pexels.com/photos/1496286/pexels-photo-1496286.jpeg\";\n  // Width and height are required.\n  const [cropped, error] = useSmartcrop({ src }, { width: 200, height: 400, minScale: 1.0 });\n  if (error) {\n    console.error(error);\n  }\n\n  return (\n    \u003cdiv\u003e\n      {cropped \u0026\u0026 \u003cimg src={cropped} /\u003e}\n    \u003c/div\u003e\n  );\n}\n```\n\n## API\n\n### Hook\n\n```tsx\nconst [dataURL, error] = useSmartcrop(\n  /**\n   * Properties of a \u003cimg\u003e element.\n   * Smartcrop will not be executed (so `dataURL` will be null) if `src` is not provided.\n   * */\n  image: ComponentProps\u003c\"img\"\u003e | null | undefined,\n  /** See below */\n  options: CropOptions,\n)\n```\n\n### Options\n\n```ts\n/**\n * Arguments for `smartcrop.js`\n * From: https://github.com/jwagner/smartcrop.js\n */\nexport interface CropOptions {\n  /**\n   * Minimal scale of the crop rect, set to `1.0` to prevent smaller than necessary crops (lowers the risk of chopping things off).\n   */\n  minScale?: number;\n  /**\n   * Width of the crop you want to use.\n   */\n  width: number;\n  /**\n   *  Height of the crop you want to use.\n   */\n  height: number;\n  /**\n   * Optional array of regions whose 'interestingness' you want to boost\n   */\n  boost?: CropBoost[];\n  /**\n   * Optional boolean if set to `false` it will turn off the rule of thirds composition weight\n   */\n  ruleOfThirds?: boolean;\n  debug?: boolean;\n}\n```\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuseflyyer%2Fuse-smartcrop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuseflyyer%2Fuse-smartcrop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuseflyyer%2Fuse-smartcrop/lists"}