Giter VIP home page Giter VIP logo

react-perspective-cropper's Introduction

Hello there

Hi, I'm Giacomo, I write software you use.
I've always written code since I was a kid. I have a Bachelor Degree in Computer Science.
What has always driven me in this field is the ability to craft and transform ideas into products that people actually use.

Currently senior JavaScript engineer at Musixmatch.
I'm a movie buff and I enjoy writing technical blog posts or shorter notes that may not necessarily relate to programming. Make also sure to check out my projects.

Read me here:

๐ŸŒ My website and blog

๐Ÿ—‚๏ธ My OSS projects

Unconventional Meet - A Chrome extension to enhance Google Meet's experience.
YoutubeBGAudio - Next.js PWA deployed on Vercel to listen for YouTube videos in the background
opencv-react - A library to correctly import and use OpenCV in your front-end app
react-perspective-cropper - A react lib to wrap and converts documents' photos into scan
UnivaqBot (archived) - An old project for scraping and notifying news to the students of my university through a telegram bot

๐Ÿ“ˆ GitHub Stats

giacomocerquone's GitHub Stats giacomocerquone's GitHub Stats

react-perspective-cropper's People

Contributors

arhamkhnz avatar danielbailey-web avatar giacomocerquone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-perspective-cropper's Issues

undefined (reading 'imread')

ERROR
Cannot read properties of undefined (reading 'imread')
TypeError: Cannot read properties of undefined (reading 'imread')
at showPreview

Add tests

Would be nice to add tests though I'm unsure on the right tool to do some integration and e2e test!

Add typings

A typescript typing's file should be added in order to let the editors provide correct hints on this package api

Change return type and quality

It would be nice to be able to declare a return mime-type for the image instead of just using the mime-type from the original image.

locally I am currently doing something like this (modified from the example)

const doSomething = async () => {
    try {
      const res = (await cropperRef?.current?.done({
        preview: true,
        filterCvParams: {
          grayScale: false,
          th: false,
        },
        image: {
          quality: 0.8,
          type: "image/jpeg",
        },
      })) as Blob;

      updateBlobState(res);
      setFileChanged(true);
    } catch (e) {
      console.log("error", e);
    }
  };

And then in Canvas.js using extended options.

canvasRef.current.toBlob(
          (blob) => {
            blob.name = image.name;
            resolve(blob);
            setLoading(false);
          },
          opts.image.type || image.type,
          opts.image.quality || 1
        );

I can submit a pull request if this is something you would be interested in adding to the library.
I believe the way I did it would implement it in a non-breaking way, given the OR operations to provide defaults.

React version too old

When I tried to install this library, an error was raised because the react version was not compatible. Can you update the react version, please?

npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.0.0" from [email protected]
npm ERR! node_modules/react-perspective-cropper
npm ERR!   react-perspective-cropper@"*" from the root project

croppedRef undefined

Hi @giacomocerquone,

I'm implementing this feature in a React app with typescript, and I can't initialize the croppedRef, I noticed in the files it is React.ElementRef with no children type, but it does require this ElementRef<{specific type}>.

Because of that, I can't call done method to crop the image.

I saw on npmjs it has the TypeScript icon, but I haven't seen a @types package, as I understand it's there because of the interface with props, but I can't inherit type of ref or anything.

Any ideas?

backToCrop and resetting the photo to the initial one results croppedState.loading to end up true

const [file, setFile] = useState<File | null>(null);
const [croppedFile, setCroppedFile] = useState<File | null>(null);

I have these two states, file is the initial one, croppedFile is passed to the component, on reset, I want to redo the crop from the file I already have, so this means to reassign the file to the cropped one state setCroppedFile(file).

const resetCrop = () => {
    setCroppedFile(file);
    cropperRef?.current?.backToCrop();
  };

This ends up leaving loading on true.

Provide maxHeight and maxWidth props

As of now both the image to crop and the resulting cropped image are presented with a maxHeight and maxWidth based on the height and width of the uploaded image.

This is a problem for two reasons:

  • The user can't correctly style it with CSS since canvas can't be styled through HTML styled wrapper elements that force a certain width or height to the inner child
  • The cropped image should be smaller, nonetheless it is presented with the same size of the original image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.