Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image can't resize, it is compress #604

Open
ntnamag opened this issue Feb 2, 2018 · 14 comments
Open

Image can't resize, it is compress #604

ntnamag opened this issue Feb 2, 2018 · 14 comments

Comments

@ntnamag
Copy link

ntnamag commented Feb 2, 2018

Version

  • react-native-image-crop-picker v0.19.1
  • react-native v0.52.2

Platform

  • iOS (no test)
  • Android (tested)

Steps to reproduce

Image only compress, can't resize with below options

ImagePicker.openPicker({
                        multiple: true,
                        maxFiles: 9,
                        compressImageMaxWidth: 640,
                        compressImageMaxHeight: 480,
                        compressImageQuality: 0.75,
                        mediaType: 'photo'
                    });
@ivpusic
Copy link
Owner

ivpusic commented Feb 2, 2018

what image size do you get in a response?

@ntnamag
Copy link
Author

ntnamag commented Feb 2, 2018

image size ~70-100kb, dimensions is same source image

@robdsoule
Copy link

robdsoule commented Mar 11, 2018

react-native-image-crop-picker v0.20.0
RN v0.53.3

Also seeing this issue where compressImageMaxWidth and compressImageMaxHeight are being honored on iOS but having no impact on image dimensions for android

@rabindrachhachan
Copy link

Hi,
Any update in image compression, currently my image is compressed but size and dimension are still same as original image. original image size is 4mb and dimension is 768*1024. I need image size to be 100-120kb after compression .

@staffannase
Copy link

Also have this issue, not tested on ios but on android compressImageMaxWidth and compressImageMaxHeight is not respected.

@armaanahluwalia
Copy link

armaanahluwalia commented Oct 3, 2018

Same issue here. @ivpusic Shouldn't issues like this be super high on the priority list considering they're listed in the readme as options and don't actually work?

Edit: FYI this is android only. Works on iOS.

armaanahluwalia added a commit to armaanahluwalia/zulip-mobile that referenced this issue Oct 3, 2018
Update the implementation of image uploading in ComposeMenu.js
We adopt react-native-image-crop-picker in favor of the
old library (react-native-image-picker).

This gives us the additional ability to downsample and downscale images
before uploading them and also allows selecting multiple images in the
same selection ( iOS only for now ). These changes will be implemented in
a following commit.

Currently, there is a bug in the image picker which results in the max
width and height to only be applied on android. This is still an
improvement over the previous library but will need to be kept in mind
so when that bug is fixed we can upgrade.
See ivpusic/react-native-image-crop-picker#604
@toytonic
Copy link

stumbled upon the same. android doesn't work.

armaanahluwalia added a commit to armaanahluwalia/zulip-mobile that referenced this issue Oct 11, 2018
Update the implementation of image uploading in ComposeMenu.js
We adopt react-native-image-crop-picker in favor of the
old library (react-native-image-picker).

This gives us the additional ability to downsample and downscale images
before uploading them and also allows selecting multiple images in the
same selection ( iOS only for now ). These changes will be implemented in
a following commit.

Currently, there is a bug in the image picker which results in the max
width and height to only be applied on android. This is still an
improvement over the previous library but will need to be kept in mind
so when that bug is fixed we can upgrade.
See ivpusic/react-native-image-crop-picker#604
@DISKONEKTeD
Copy link

This issue only seems to happen with multiple images is selected.

the cropping is completely ignored when multiple is set to true on android

@DISKONEKTeD
Copy link

Since this seems to be an issue that's been around a while, i suggest using: https://github.com/bamlab/react-native-image-resizer

Note: i had an issue with that package regarding SDK vesions, so I had to add this to android/build.grade:

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 26 // <-- match this to your project's compileSdkVersion
                buildToolsVersion '26.0.3' // <-- match this to your project's buildToolsVersion
            }
        }
    }
}

then i imported it and did this where react-native-image-crop-picker fails to resize/crop (possibly compress as well, didnt' check), it's a quick WIP:

   ImagePicker.openPicker({
      mediaType: "photo",
      multiple: true,
      maxFiles: 4,
      width: 1080,
      height: 1350,
      cropping: true,
      compressImageMaxWidth: 1080,
      compressImageMaxHeight: 1350,
    }).then((image) => {

      // console.log(image);
      const imagesArray = [];
      if (Platform.OS === "android") {
        for (let i = 0; i < image.length; i++) {
          const { path, mime } = image[i];

          let compressFormat;

          if (mime === 'image/jpeg') {
            compressFormat = 'JPEG';
          } else if (mime === 'image/png') {
            compressFormat = 'PNG';
          }
          console.log(image[i]);
          // null means images are stored in cache folder e.g. context.getCacheDir()
          // probably be a good idea to clean/delete after using the compressed files for upload
          ImageResizer.createResizedImage(path, 1080, 1350, compressFormat, 100, 0, null)
            .then((response) => {
              console.log(response);
              // send to server for upload w/e
              // response.path is the path of the new image
            })
            .catch((err) => {
              // TODO:
              // Oops, something went wrong. Check that the filename is correct and
              // inspect err to get more details.
            });
        } else {
        // do ios stuff here etc send to server etc w/e
      }`

But otherwise react-native-image-crop-picker works perfectly for my needs and it is very much appreciated!

This isn't the most practical or prettiest solutions, but seem like this will have to do for users who want multiple images and want resize/compressed to work on android. At least for now, until this gets addressed at some point.

armaanahluwalia added a commit to armaanahluwalia/zulip-mobile that referenced this issue Oct 19, 2018
Update the implementation of image uploading in ComposeMenu.js
We adopt react-native-image-crop-picker in favor of the
old library (react-native-image-picker).

This gives us the additional ability to downsample and downscale images
before uploading them and also allows selecting multiple images in the
same selection ( iOS only for now ). These changes will be implemented in
a following commit.

Currently, there is a bug in the image picker which results in the max
width and height to only be applied on android. This is still an
improvement over the previous library but will need to be kept in mind
so when that bug is fixed we can upgrade.
See ivpusic/react-native-image-crop-picker#604
@hkung77
Copy link

hkung77 commented Nov 6, 2018

So this fork seems to provide the fix for images respecting the max compressed width/height (https://github.com/ChrisLahaye/react-native-image-crop-picker)

armaanahluwalia added a commit to armaanahluwalia/zulip-mobile that referenced this issue Dec 8, 2018
Update the implementation of image uploading in ComposeMenu.js
We adopt react-native-image-crop-picker in favor of the
old library (react-native-image-picker).

This gives us the additional ability to downsample and downscale images
before uploading them and also allows selecting multiple images in the
same selection ( iOS only for now ). These changes will be implemented in
a following commit.

Currently, there is a bug in the image picker which results in the max
width and height to only be applied on android. This is still an
improvement over the previous library but will need to be kept in mind
so when that bug is fixed we can upgrade.
See ivpusic/react-native-image-crop-picker#604
@chengsam
Copy link

This is due to a bug in the compressor it used.

@xstable
Copy link

xstable commented Mar 15, 2019

When will it be fixed, or should be choosed another compressor.
In my opinion it's an important feature of image-crop-picker which should be fixed soon.

@s5963028
Copy link

s5963028 commented Jul 4, 2019

some updates?

@dragma
Copy link

dragma commented Feb 14, 2020

Since this seems to be an issue that's been around a while, i suggest using: https://github.com/bamlab/react-native-image-resizer

Note: i had an issue with that package regarding SDK vesions, so I had to add this to android/build.grade:

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 26 // <-- match this to your project's compileSdkVersion
                buildToolsVersion '26.0.3' // <-- match this to your project's buildToolsVersion
            }
        }
    }
}

then i imported it and did this where react-native-image-crop-picker fails to resize/crop (possibly compress as well, didnt' check), it's a quick WIP:

   ImagePicker.openPicker({
      mediaType: "photo",
      multiple: true,
      maxFiles: 4,
      width: 1080,
      height: 1350,
      cropping: true,
      compressImageMaxWidth: 1080,
      compressImageMaxHeight: 1350,
    }).then((image) => {

      // console.log(image);
      const imagesArray = [];
      if (Platform.OS === "android") {
        for (let i = 0; i < image.length; i++) {
          const { path, mime } = image[i];

          let compressFormat;

          if (mime === 'image/jpeg') {
            compressFormat = 'JPEG';
          } else if (mime === 'image/png') {
            compressFormat = 'PNG';
          }
          console.log(image[i]);
          // null means images are stored in cache folder e.g. context.getCacheDir()
          // probably be a good idea to clean/delete after using the compressed files for upload
          ImageResizer.createResizedImage(path, 1080, 1350, compressFormat, 100, 0, null)
            .then((response) => {
              console.log(response);
              // send to server for upload w/e
              // response.path is the path of the new image
            })
            .catch((err) => {
              // TODO:
              // Oops, something went wrong. Check that the filename is correct and
              // inspect err to get more details.
            });
        } else {
        // do ios stuff here etc send to server etc w/e
      }`

But otherwise react-native-image-crop-picker works perfectly for my needs and it is very much appreciated!

This isn't the most practical or prettiest solutions, but seem like this will have to do for users who want multiple images and want resize/compressed to work on android. At least for now, until this gets addressed at some point.

I used this. It is working so far ! Thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests