josealejandro2928 / react-image-picker-editor

React library for the selection, edition and compression of images in png, jpeg and webp formats This package is made completely with html and css without any extra components or npm packages. It's based in functional components based in hooks, for optimization were used memo, useMemo and useCalback for avoiding any extra-renders.
https://www.npmjs.com/package/react-image-picker-editor
MIT License
27 stars 21 forks source link

Error loading the src on imageSrcProp #10

Closed BilawalSh closed 3 months ago

BilawalSh commented 5 months ago

Hello @josealejandro2928 @Lucas-Jav I have found this issue when we pass the image URL it shows an error

image

I try many ways but still get this error on all images url.

Can you fix it?

Lucas-Jav commented 5 months ago

I can to try fix!

Lucas-Jav commented 5 months ago

What version are you using, and are you on react or next?

Lucas-Jav commented 5 months ago

In fact, I think I already discovered the error, you are passing a url to the src, the src is for images in base64, it does not accept images in url image

josealejandro2928 commented 5 months ago

That is not an error, the package allows to load a image as url or as base64. For its internal behavio0r it always try to parse and convert images into base64, on init

josealejandro2928 commented 5 months ago

Look this example: image here i initialize the state with this wikipedia image, then it is passed as prop to the component:

Pick and edit an image:

    < ReactImagePickerEditor
      imageSrcProp={logo as any}
      config={config2}
      imageChanged={(newDataUri: any) => { setImageSrc2(newDataUri) }} />
  </div>
  then the result:

image

BilawalSh commented 5 months ago

Thank you for your quick reply, @josealejandro2928 @Lucas-Jav This is fresh project Here is the simplest Script:

image

Output (Error) image

Package.json image

what is wrong in this code

Lucas-Jav commented 5 months ago

That's exactly what I imagined, this error is occurring because this image is in "url" format, and in its lib it uses base64 in the src, because in base64 format it can edit it better. I recommend passing the image to base64. But in a future feature we will create the possibility of accepting urls as well.

website to convert the image: https://base64.guru/converter/encode/image

Or we also recommend downloading the image and doing this: image

BilawalSh commented 5 months ago

Thank you for confirmation

josealejandro2928 commented 3 months ago

I think i can close this