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-cropify

v1.1.1

Published

react-cropify helps with cropping image in react js

Downloads

8

Readme

React-Cropify

React-Cropify is an npm package that simplifies the process of cropping images in your web applications. With just a some lines of code, you can integrate powerful image cropping functionality into your project.

Introduction

React-Cropify is your ultimate solution for effortlessly incorporating image cropping capabilities into your web applications. Gone are the days of complex and time-consuming image cropping processes. With React-Cropify, you can achieve powerful image editing functionality in your projects with minimal effort and a clean, user-friendly interface.

Animated GIF

Sample Usage

import React, { useState, useRef } from 'react';
import cropContainer from 'react-cropify';

function App() {
  const [selectedImage, setSelectedImage] = useState(null);
  const [croppedImage, setCroppedImage] = useState(null);
  const [imageZoom, setImageZoom] = useState(0);
  const [croppedWidth, setCroppedWidth] = useState(100); // Set your desired initial value
  const [croppedHeight, setCroppedHeight] = useState(100); // Set your desired initial value

  const imageRef = useRef(null);
  const canvasRef = useRef(null);
  const sliderRef = useRef(null);

  const handleFileSelect = (event) => {
    const file = event.target.files[0];
    if (file) {
      const imageUrl = URL.createObjectURL(file);
      setSelectedImage(imageUrl);
      // Reset zoom when a new image is selected
      setImageZoom(0.3);
      if (sliderRef.current) {
        sliderRef.current.value = 0.1; // Reset the slider value
      }
    }
  };

  const handleZoomSliderChange = () => {
    const zoomValue = parseFloat(sliderRef.current.value); // Parse the slider value as a float
    setImageZoom(zoomValue);
  };

  
  const handleCrop = async () => {
    if (selectedImage) {
      try {
        const croppedImageUrl = await cropContainer(selectedImage, imageZoom, croppedWidth, croppedHeight);
        setCroppedImage(croppedImageUrl);
      } catch (error) {
        console.error('Error cropping image:', error);
      }
    }
  };
  

  return (
    <div
      style={{
        fontFamily: 'Arial',
        textAlign: 'center',
        minHeight: '100vh',
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
      }}
    >
      <h1>Image Cropper</h1>
      <input
        type="file"
        accept="image/*"
        onChange={handleFileSelect}
        style={{ margin: '20px' }}
      />
      {selectedImage && (
        <div>
          <h2>Selected Image:</h2>
          <div
            style={{
              position: 'relative',
              width: '100%',
              height: 0,
              paddingBottom: '100%', // Creates a square container - Change for different shapes
              overflow: 'hidden',
            }}
          >
            <img
              ref={imageRef}
              src={selectedImage}
              alt="Selected"
              style={{
                position: 'absolute',
                top: '50%',
                left: '50%',
                transform: `translate(-50%, -50%) scale(${imageZoom})`,
                maxWidth: 'none',
                maxHeight: 'none',
              }}
            />
          </div>
          <div>
            <input
              type="range"
              min={0.3}
              max={3}
              step={0.01}
              ref={sliderRef}
              value={imageZoom}
              onChange={handleZoomSliderChange}
              style={{
                width: '100%',
                position: 'relative',
                zIndex: 2,
              }}
            />
          </div>
        </div>
      )}
      {selectedImage && (
        <div>
          <button
            onClick={handleCrop}
            style={{
              margin: '20px',
              padding: '10px 20px',
              background: '#0074D9',
              color: 'white',
              border: 'none',
              cursor: 'pointer',
            }}
          >
            Crop Image
          </button>
        </div>
      )}

      <canvas ref={canvasRef} style={{ display: 'none' }} />

      {croppedImage && (
        <div>
          <h2>Cropped Image:</h2>
          <img src={croppedImage} alt="Cropped" width="200" />
        </div>
      )}
    </div>
  );
}

export default App;