• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 3 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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;
}

More Repositories

1

next-rosetta

Next.js + Rosetta + TypeScript with native i18n support | Lightweight, simple, easy to integrate, no custom server required and efficient because will only download the locale you need.
TypeScript
62
star
2

create-flyyer-app

Scaffold everything you need to create a https://flyyer.io template | Generate social media images and og:image
TypeScript
26
star
3

use-googlefonts

React hook to dynamically load Google Fonts v2 during execution.
TypeScript
19
star
4

flyyer-js

SaaS to manage, optimize and generate your og:image og-image
TypeScript
17
star
5

flyyer-wp

πŸ‘‰ Visit the wiki: https://github.com/useflyyer/flyyer-wp/wiki | Generate social share images with web technologies
PHP
16
star
6

flyyer-python

Python helpers to create https://flyyer.io URLs for link previews | Manage your og:images from a single dashboard
Python
14
star
7

flyyer-ruby

Ruby helpers to create https://cdn.flyyer.io URLs | Og:Image as a Service
Ruby
13
star
8

flyyer-cli

Command-line interface to develop dynamic og:images via https://flyyer.io | Generate social share images with web technologies
TypeScript
11
star
9

flyyer-marketplace-github-cards

Replica of new GitHub og images to show how to use Flyyer to generate images.
TypeScript
8
star
10

flyyer-php

PHP helpers to create https://flyyer.io URLs | Manage your og:image from a single dashboard
PHP
7
star
11

socialpreview-flyyer

SocialPreview.io flyyer smart image preview served from https://flyyer.io
TypeScript
6
star
12

studio

Companion dev server for @flyyer/cli and create-flyyer-app | https://useflyyer.github.io/studio/
TypeScript
5
star
13

flyyer-actions

Github Actions and Workflows to automatically deploy your Flyyer.io decks.
5
star
14

flyyer-deck-docs

Templates for https://docs.flyyer.io
CSS
4
star
15

flyyer-types

Flyyer type definition for Typescript templates created with https://github.com/useflyyer/create-flyyer-app
TypeScript
4
star
16

flyyer-ping

Script for analytics and pre-rendering Flayyer images simple as https://edge.flayyer.host/v2/pixel.gif
JavaScript
4
star
17

use-next-intl-format

Super lightweight and zero-dependencies React Hook for creating memoized native instances of Intl for Next.js i18n
TypeScript
4
star
18

flyyer-ruby-liquid

Liquid helpers to create https://flyyer.io URLs | Generate social share images with web technologies
Ruby
4
star
19

example

Example project (appears in the https://flyyer.io landing page)
CSS
3
star
20

gatsby-plugin-flyyer

Gatsby.js plugin | WIP πŸ‘·β€β™€οΈ
JavaScript
3
star
21

flyyer-docs

Public collaborative documentation and guides for Flyyer.io
JavaScript
2
star
22

flyyer-stringify

Just a wrapper around https://github.com/streamich/fastest-stable-stringify but with Typescript typing we use in some projects.
TypeScript
2
star
23

flyyer-example-rails

Example using Rails 5 and Flyyer.io | https://docs.flyyer.io/guides/ruby/rails
Ruby
1
star
24

flyyer-opengraph-properties

Convert meta-tags into an object with accessor. Supports single and multiple tags via pluralization.
TypeScript
1
star
25

flyyer-marketplace-simplefade

Free template | https://flyyer.io/@/flyyer/simple-fade
TypeScript
1
star
26

integration-examples

Integration examples with popular technologies with https://flyyer.io | Generate social share images with web technologies
1
star
27

flyyer-marketplace-brand

Free template for Flyyer.io | https://flyyer.io/@/flyyer/branded
TypeScript
1
star
28

better-url

Implements the URL class definition but preserves base's path and queryparams when resolving URLs.
TypeScript
1
star
29

flyyer-hook

React Hook to memoize a @flyyer/flyyer instance | https://flyyer.io
TypeScript
1
star
30

proxy

Helper function to proxy images via Flyyer network to bypass CORS with Typescript support for Flyyer.io
TypeScript
1
star
31

flyyer-marketplace-imagefluent

Second inspirational template for the marketplace account | Flyyer.io
TypeScript
1
star
32

flyyer-variables

Helper module to create a `schema` that enables Flyyer.io to display template's variables on https://flyyer.io/dashboard for decks and templates.
TypeScript
1
star
33

flyyer-marketplace-nicetypography

Free template for Flayyer.com | https://flyyer.io/@/flyyer/nice-typography
TypeScript
1
star
34

flyyer-official

Official templates for Flyyer.io | https://flyyer.io/@/flyyer/official
TypeScript
1
star
35

flyyer-marketplace-angled

Free template | https://flyyer.io
TypeScript
1
star
36

eslint-config

Flyyer.io company wide ESLint config with Prettier, TypeScript and React support
JavaScript
1
star
37

flyyer-marketplace-quoteque

Free template | https://Flyyer.io
TypeScript
1
star
38

docusaurus-preset

Flyyer.io integration preset for Docusaurus.io v2 | Manage your og:image from a single dashboard
TypeScript
1
star
39

flyyer-marketplace-default

This is the default deck created with create-flyyer-app to showcase how to start your own set of templates | https://flyyer.io
JavaScript
1
star