npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-profile

v1.3.3

Published

React Profile Editor, crop, upload, apply filters and adjust colors for your avatar image. Optimize the image size for your application

Downloads

1,754

Readme

React Profile Icon

React Profile

npm version

A simple and open-source React component for editing photos.

Demo

Homepage

Table of Contents

  1. Installation
  2. Example
  3. Options
  4. Props
  5. Contributing / Developing

Installation

In your terminal, execute this command depending on your preferred package manager:

npm i react-profile
yarn add react-profile
pnpm add react-profile

Example

One way to open the editor is passing the image path and rendering it. For example:

import React from "react";
import ReactProfile from "react-profile";
import "react-profile/themes/default.min.css";

function App() {
  return <ReactProfile src="./your-image.png" />;
}

export default App;

Additionally, you can open the editor directly in your code. For example:

import { openEditor } from "react-profile";
import "react-profile/themes/dark.min.css";

async function open() {
  const result = await openEditor({ src: "./your-image.jpg" });
}

Very important: Always import the corresponding style file for the desired theme when rendering/calling the editor.

Options

You can change the editor's language with the 'language' property. For example:

import React from "react";
import ReactProfile from "react-profile";
import "react-profile/themes/default.min.css";

function App() {
  return <ReactProfile src="./your-image.png" language="zh" />;
}

export default App;

You can request an image in square format. For example:

import React from "react";
import ReactProfile from "react-profile";
import "react-profile/themes/default.min.css";

function App() {
  return <ReactProfile src="./your-image.png" square />;
}

export default App;

You can enable only the modules you want using the 'modules' property. For example:

import React from "react";
import ReactProfile from "react-profile";
import "react-profile/themes/default.min.css";

function App() {
  return <ReactProfile src="./your-image.png" modules={["filter", "crop"]} />;
}

export default App;

You can add more filters or even all available filters. For example:

import React from "react";
import ReactProfile, { ALL_FILTERS } from "react-profile";
import "react-profile/themes/default.min.css";

function App() {
  return <ReactProfile src="./your-image.png" filters={ALL_FILTERS} />;
}

export default App;

Warning: Adding many filters could potentially slow down the editor depending on the image's size

To explore all the filters, you can visit the Pixels.js website

You can initialize the component with an HTMLImageElement object specifying the type. For Example:

import React from "react";
import ReactProfile from "react-profile";
import "react-profile/themes/default.min.css";

function App() {
  return <ReactProfile src={YOUR_IMG_OBJECT as HTMLImageElement} type="image/jpeg" />;
}

export default App;

You can change some options to crop the image. The 'react-image-crop' library specifies all the options. For Example:

import React from "react";
import ReactProfile from "react-profile";
import "react-profile/themes/default.min.css";

function App() {
  return <ReactProfile src="./your-image.png" cropOptions={{ maxWidth: 500, maxHeight: 300 }} />;
}

export default App;

You can change how the crop object is initialized in the editor. The 'react-image-crop' library specifies all the options. For Example:

import React from "react";
import ReactProfile from "react-profile";
import "react-profile/themes/default.min.css";

function App() {
  return (
    <ReactProfile
      src="./your-image.png"
      initCrop={{
        unit: "%",
        width: 50,
        height: 50,
        x: 25,
        y: 25,
      }}
    />
  );
}

export default App;

Props

src?: string | File | HTMLImageObject

Source of the image

initCrop?: Crop

react-image-crop init crop

cropOptions?: CropOptions

react-image-crop crop options

square?: boolean

Square Image

onCancel?: () => void

Handler when the user cancels edit

onDone?: (exportObject?: EXPORT_OBJECT) => void

Handler when the user finishes editing. The EXPORT_OBJECT has the following methods:

  • getCanvas() -> get canvas object
  • getBlob() (async) -> get blob
  • getDataURL() -> get data url
  • getImageFromBlob() (async) -> get HTMLImageElement from blob
  • getImageFromDataURL() (async) -> get HTMLImageElement from blob

maxWidth?: number

It refers to the maximum resolution (in width) of the image. Note: This is different from the size rendered on the screen. It is done for image optimization. The default maximum is '1000'. Try not to use very high resolutions to avoid slowdowns.

maxHeight?: number

It refers to the maximum resolution (in height) of the image. Note: This is different from the size rendered on the screen. It is done for image optimization. The default maximum is '1000'. Try not to use very high resolutions to avoid slowdowns.

quality?: number

Image quality for optimization purposes. Default is '0.8'. Only affects JPEG format images. Range of values 0-1

maxImageSize?: number

Maximum image size in bytes. The default maximum size is '10MB' (1024 * 1024 * 10). If you want to work with larger images, you should specify it here. Note: Working with very large images can overload the canvas object and may cause the editor to fail.

modules?: MODULES[]

An array that specifies which modules the developer wants to be rendered in the editor.

type?: 'image/jpeg|image/png'

This property declares the type of the image for the editor

Contributing / Developing

In your project, navigate to the 'node_modules' folder and look for the 'react-profile' package

Clone the repository

git clone https://github.com/mdjfs/react-profile

Install and build

yarn && yarn run build

Now. inside src/ you can change everything about logics, languages, icons, etc

And inside themes/ you can change all the styles, add new themes, etc

After each change. Remember run builds again.

When you're ready, open a pull request.