react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

Poor Image Quality after crop

Open imbudhiraja opened this issue 5 years ago • 24 comments

Version

  • react-native-image-crop-picker v0.23.1
  • react-native v0.59.4

Platform

  • iOS
  • Android

Steps to reproduce

  1. Open Gallery
  2. Select Image
  3. Crop Image

You will get a poor image quality after cropping.

Reproduce-able code

const config = {
  cropperStatusBarColor: 'black',
  cropperToolbarColor: 'black',
  cropping: true,
  mediaType: 'photo',
  showCropFrame: true,
  showCropGuidelines: true,
};

ImagePicker.openCamera(config)
  .then((response) => {})
  .catch((err) => {});

ImagePicker.openPicker(config)
  .then((response) => {})
  .catch((err) => {});

Love react-native-image-crop-picker? Please consider supporting our collective: 👉 https://opencollective.com/react-native-image-crop-picker/donate

imbudhiraja avatar Jul 30 '19 06:07 imbudhiraja

@imbudhiraja What are your dimensions of the crop?

For me I want to set to 150x150 images and it seems to be an awful quality. If I set to convert some 50x50 for the profile pics, then the quality is impossible to have. I found anything more than 500x500 turns out a good one but the size to store isnt

SourceCipher avatar Aug 25 '19 23:08 SourceCipher

@SourceCipher I'm using 320*120 for cover pictures

imbudhiraja avatar Aug 27 '19 04:08 imbudhiraja

I have tested both with base64 and original storage image and they all come up in a very bad quality. I uploaded them to the db and they are just unusable and the dimensions of my pic was 300 x 300.

I have checked issues on this library and a lot of them are with bad quality images dating back to 2017. Yet nobody managed to fix it as its the main part of the library. No point having it if the image quality turns out unusable.

SourceCipher avatar Aug 27 '19 15:08 SourceCipher

Any updates on this? I have been experiencing the same issues for a bit and I bet that a repo with almost 4k stars has at least some people who know the solution to this. Any help is greatly appreciated.

caetius avatar Sep 24 '19 02:09 caetius

After reading some guy on a different bug ticket, and reading the docs... it says you need to set height and width. It's used for the cropping option as the final resolution. Depending on how high you set it there, the better the quality after cropping.

msqar avatar Sep 29 '19 21:09 msqar

Anyone found solution on this? I set more width/height and problem still remain.

cporawat avatar Nov 10 '19 10:11 cporawat

@cporawat No luck buddy.

imbudhiraja avatar Nov 11 '19 04:11 imbudhiraja

I saw poor image quality using 400x500, when I upped it to 1200x1500 the quality greatly improved. I'd say the solution is to set a greater height/width.

jordangrant avatar Nov 20 '19 07:11 jordangrant

I saw poor image quality using 400x500, when I upped it to 1200x1500 the quality greatly improved. I'd say the solution is to set a greater height/width.

If you do that, you crop the picture, maybe it's not return the correct size

leviduan avatar Dec 19 '19 02:12 leviduan

any solution ?

axmedbek avatar Apr 23 '20 22:04 axmedbek

I am also facing same problem but if we set cropping to false, then image quality is not decreased. Please help if somebody found any solution

hackrx avatar Jun 02 '20 00:06 hackrx

This issue is solved, here is the code ImagePicker.openPicker({ width: 1000, height: 800, cropping: true, includeBase64: false, compressImageQuality: 1, // compressImageMaxHeight: 1, // compressImageMaxWidth: 1, compressImageMaxWidth: 1500, compressImageMaxHeight: 1000, }) We need to use height and width as max as possible, before this I was setting ImagePicker.openPicker({ width: 300, height: 300, cropping: true, includeBase64: false, compressImageQuality: 1, // compressImageMaxHeight: 1, // compressImageMaxWidth: 1, compressImageMaxWidth: 1500, compressImageMaxHeight: 1000, }) And as a result, I was getting poor quality cropped image.

hackrx avatar Jun 02 '20 00:06 hackrx

width: 1000, height: 800

Is fine that you found a workaround. But this is not solved. The image will have a bigger space on the server.

MariusCatanoiu avatar Jun 26 '20 11:06 MariusCatanoiu

width: 1000, height: 800

Is fine that you found a workaround. But this is not solved. The image will have a bigger space on the server.

No, I have checked my firebase storage and I found that 4.2Mb image file is get converted to 478kb and this is what I want

hackrx avatar Jun 26 '20 11:06 hackrx

Still no fix for this?

jdcaacbay-wp avatar Jul 12 '21 15:07 jdcaacbay-wp

I saw poor image quality using 400x500, when I upped it to 1200x1500 the quality greatly improved. I'd say the solution is to set a greater height/width.

this is worked for me bro, thanks a lot

salik-a avatar Jan 14 '22 14:01 salik-a

This issue is solved, here is the code ImagePicker.openPicker({ width: 1000, height: 800, cropping: true, includeBase64: false, compressImageQuality: 1, // compressImageMaxHeight: 1, // compressImageMaxWidth: 1, compressImageMaxWidth: 1500, compressImageMaxHeight: 1000, }) We need to use height and width as max as possible, before this I was setting ImagePicker.openPicker({ width: 300, height: 300, cropping: true, includeBase64: false, compressImageQuality: 1, // compressImageMaxHeight: 1, // compressImageMaxWidth: 1, compressImageMaxWidth: 1500, compressImageMaxHeight: 1000, }) And as a result, I was getting poor quality cropped image.

this worked for me, but any specific reason why?? Curious if anyone had the chance to dig around.

SeamusY avatar Feb 22 '22 15:02 SeamusY

Increasing dimensions is not the solution at all unless you have someone giving you free unlimited cloud storage, then that's not a problem, but for anyone wanting to use for profile pictures or anything really apart wallpaper sizes, this is unusable as its pointless to store 1mb size pictures with 1000x800 size when your app displays them as 150x150 or smaller

SourceCipher avatar Feb 23 '22 16:02 SourceCipher

Applying the changes from this PR manually solves the issue for me.

iOS image is resized to 200x200 by default, not to selected crop rect.

meznaric avatar Apr 05 '22 11:04 meznaric

same problem

thangflydino avatar Oct 27 '22 07:10 thangflydino

  • 1 to cropping to aspect ratio rather than outright size. we run a photo app, we need to offer the ability to crop to common aspect ratios (eg 16:9, 4:3, 3:2) but dont want the images to be crushed.

Dakuan avatar Nov 16 '22 11:11 Dakuan

In our team we need the cropping to aspect ratio rather than outright size. How can we help to move mentioned PR forward?

altsanz avatar Jul 18 '23 14:07 altsanz

I think the confusion is what is height & width does on the API of the cropper...

the height & width are the attempted output size of the cropper, which is different from the Cropper rectangle on the device.

So, if you don't set these, then what ever your rectangle size is, is what will be used. However, the kicker with this API is that we'll never know beforehand WHAT the cropped dimension will be. So we have to guess. We can try to get the original image dimensions, but this has obvious downsides because cropping inherently makes the image smaller.

So, if I use these options:

await ImageCropper.openCropper({
      mediaType: 'photo',
      path: photoPath,
      freeStyleCropEnabled: true,
      width: 1000,
      height: 1000,
      enableRotationGesture: false,
      compressImageQuality: 1,
    });

The Cropper will try to output 1000x1000.
However, since I have freeStyleCropEnabled, if I choose 16:9 ratio, it will not output the 1000x1000. It will max out the width to 1000 regardless of the cropping box. So now, my output is width: 1000; height: 403.

The image quality is at least useable now...

lucksp avatar Oct 02 '23 14:10 lucksp

Still facing same issue, if u capture the document image or image which contain text After capture the images text is not visible clearly
I have crop the image ratio in 3:4

ImportedPhoto_1722918164923

U can set this option for android in native files, that improve image quality little bit uCrop.withMaxResultSize(1000, 1000); options.setCompressionQuality(100); options.setMaxBitmapSize(10000);

But for my case this still not working So for crop the image i've used this. https://github.com/hhunaid/react-native-image-crop-tools

ajay-mandaviya avatar Aug 05 '24 11:08 ajay-mandaviya