All Projects → useflyyer → use-smartcrop

useflyyer / use-smartcrop

Licence: other
React hook for smartcrop.js to content aware image cropping with points of interest and facial recognition.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to use-smartcrop

dynamic-utils
Utility functions to perform dynamic operations on Android.
Stars: ✭ 86 (-7.53%)
Mutual labels:  color
react-recycled-scrolling
Simulate normal scrolling by using only fixed number of DOM elements for large lists of items with React Hooks
Stars: ✭ 26 (-72.04%)
Mutual labels:  react-hooks
react-hook-clipboard
A React hook for accessing clipboard
Stars: ✭ 16 (-82.8%)
Mutual labels:  react-hooks
react-contentful
📰 A React component library that makes it super simple to compose Contentful content into your sites and applications.
Stars: ✭ 58 (-37.63%)
Mutual labels:  react-hooks
React-Chat-App
This is a real time chat application with features of online status,read receipnt,image support and create multiple rooms
Stars: ✭ 13 (-86.02%)
Mutual labels:  react-hooks
shop-app
A shopping mobile application made with react native for Android.
Stars: ✭ 100 (+7.53%)
Mutual labels:  react-hooks
nord-mintty
An arctic, north-bluish clean and elegant Mintty color theme.
Stars: ✭ 40 (-56.99%)
Mutual labels:  color
canvas-color-tracker
A utility to track objects on a canvas by unique px color
Stars: ✭ 29 (-68.82%)
Mutual labels:  color
php-invert-color
Invert a given color.
Stars: ✭ 13 (-86.02%)
Mutual labels:  color
React-Combine-Provider
combine react providers in ease
Stars: ✭ 29 (-68.82%)
Mutual labels:  react-hooks
color-rgba
Get rgba array from color string
Stars: ✭ 18 (-80.65%)
Mutual labels:  color
covid
COVID-19 updates webpage
Stars: ✭ 117 (+25.81%)
Mutual labels:  react-hooks
ocr
Simple app to extract text from pictures using Tesseract
Stars: ✭ 98 (+5.38%)
Mutual labels:  image-recognition
hierse
Zero-shot image tagging by hierarchical semantic embedding
Stars: ✭ 77 (-17.2%)
Mutual labels:  image-recognition
ColorPrefUtil
ColorPrefUtil for Android. Easily change theme and view/layout/text colors or custom background drawables.
Stars: ✭ 55 (-40.86%)
Mutual labels:  color
use-custom-compare-effect
useEffect hook which takes a comparison function instead of compare using reference equality
Stars: ✭ 26 (-72.04%)
Mutual labels:  react-hooks
UnityColorPicker
A standalone color picker asset for Unity
Stars: ✭ 70 (-24.73%)
Mutual labels:  color
color-name
A JSON with CSS color names
Stars: ✭ 72 (-22.58%)
Mutual labels:  color
Overwatcheat
Free, open-source undetected color cheat!
Stars: ✭ 180 (+93.55%)
Mutual labels:  color
swr-examples
SWR is a React Hook library for remote data fetching. Here are some simple examples.
Stars: ✭ 14 (-84.95%)
Mutual labels:  react-hooks

use-smartcrop

This is the React Hook version of jwagner/smartcrop.js + lokesh/color-thief with Typescript support.

We made this hook for Flyyer.io to enable developers to create content-aware marketing and social images but it is useful for any kind of project.

example of content aware cropping

Usage

Install this dependency:

yarn add use-smartcrop

By default images are loading with crossOrigin="" prop. See this StackOverflow thread.

Common case usage:

import React from "react";
import { useSmartcrop, SmartcropStatus } from "use-smartcrop";

function App() {
  const src = "https://images.pexels.com/photos/1496286/pexels-photo-1496286.jpeg";
  // Width and height are required.
  const [cropped, error] = useSmartcrop({ src }, { width: 200, height: 400, minScale: 1.0 });
  if (error) {
    console.error(error);
  }

  return (
    <div>
      {cropped && <img src={cropped} />}
    </div>
  );
}

API

Hook

const [dataURL, error] = useSmartcrop(
  /**
   * Properties of a <img> element.
   * Smartcrop will not be executed (so `dataURL` will be null) if `src` is not provided.
   * */
  image: ComponentProps<"img"> | null | undefined,
  /** See below */
  options: CropOptions,
)

Options

/**
 * Arguments for `smartcrop.js`
 * From: https://github.com/jwagner/smartcrop.js
 */
export interface CropOptions {
  /**
   * Minimal scale of the crop rect, set to `1.0` to prevent smaller than necessary crops (lowers the risk of chopping things off).
   */
  minScale?: number;
  /**
   * Width of the crop you want to use.
   */
  width: number;
  /**
   *  Height of the crop you want to use.
   */
  height: number;
  /**
   * Optional array of regions whose 'interestingness' you want to boost
   */
  boost?: CropBoost[];
  /**
   * Optional boolean if set to `false` it will turn off the rule of thirds composition weight
   */
  ruleOfThirds?: boolean;
  debug?: boolean;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].