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

Changing image formats (PNG to JPG) itself #105

Closed
saqibsoftwares opened this issue Aug 1, 2020 · 8 comments
Closed

Changing image formats (PNG to JPG) itself #105

saqibsoftwares opened this issue Aug 1, 2020 · 8 comments

Comments

@saqibsoftwares
Copy link

Hi,
The library is changing selected PNG image into JPG image itself when .maxResultSize and .compress functions are used with the Companion.

ImagePicker.Companion.with(this).galleryOnly().maxResultSize(Globals.MAX_IMAGE_WIDTH, Globals.MAX_IMAGE_HEIGHT).compress(Globals.MAX_IMAGE_SIZE_KB).start

Is there any way to keep the original format?

@Dhaval2404
Copy link
Owner

@saqibsoftwares Have you tried in v1.7.3? I think the issue is resolved in this version. Please let me know if the issue still persists.

implementation 'com.github.dhaval2404:imagepicker:1.7.3'

@saqibsoftwares
Copy link
Author

Thank you for replying.
Unfortunately the problem is still. I updated to 1.7.3 and tried it again same results. I cleaned my android studio project then built it again still the same problem.

Here is the file name which I'm giving it as source file:
/storage/emulated/0/Download/face-png-vladimir-putin-face-png-image-1645.png

Here is the new file name it returning after compressing/resizing:
/storage/emulated/0/DCIM/Camera/IMG_20200801_231355718.jpg

I have even tried to add mime type (.galleryMimeTypes(new String[]{"image/png"})) with the request but same results.

Here is the full code I'm using

ImagePicker.Companion.with(PeopleEditorActivity.this).compress(Globals.MAX_IMAGE_SIZE_KB).maxResultSize(Globals.MAX_IMAGE_WIDTH, Globals.MAX_IMAGE_HEIGHT).galleryMimeTypes(new String[]{"image/png"}).galleryOnly().start(new Function2<Integer, Intent, Unit>()
                {
                    @Override
                    public Unit invoke(Integer integer, Intent intent)
                    {
                        if (intent.getData() != null)
                        {
                            final String path = ImagePicker.Companion.getFilePath(intent);
                            addSingleImage(position, path);
                        }
                        return null;
                    }
                });

@saqibsoftwares
Copy link
Author

I tried to dig into the library to provide you more information,

inside CompressionProvider class there is a method called startCompression
private fun startCompression(file: File): File? { used to compress the provided PNG image file. It called multiple times until we got our desired compress size. Inside this method on the following line
newFile = applyCompression(file, attempt)
When the attempt is zero the file in our provided PNG file but when the attempt is one (or greater) the file changed and becomes a JPG file with random file name and JPG extension and the same file returned to our calling activity.

May be the above information could help you to find the problem. Use the large size PNG image 3 or 4 MB in size and try to compress is with very small size like 500KB to reproduce the problem. Can you please also give us max file size selection limit so we can restrict user to select large files.

@Dhaval2404
Copy link
Owner

@saqibsoftwares Thank you so much for the detailed information. I will get back to you shortly. I really appreciate you putting your effort behind improving this lib. This will be helpful to lots of Users.
Thank you again!

@saqibsoftwares
Copy link
Author

Don't thank me. What I did is nothing as compared to what you have done for all of us by creating this amazing library. Just one more request that please add Max File Size option just like you have added mime type option. This should disable all the images in selection list those are greater than allowed file size.

Dhaval2404 added a commit that referenced this issue Aug 2, 2020
Fixed image extention change to PNG on Compress issue

#105
@Dhaval2404
Copy link
Owner

Dhaval2404 commented Aug 2, 2020

@saqibsoftwares I have fixed the issue now. You can verify the changes in v1.7.4. Thank you!

@saqibsoftwares
Copy link
Author

Thanks a lot. Confirmed. Issue has been resolved in v1.7.4.

@dhaval-noledger
Copy link

@Dhaval2404 I'm still facing image format issue in version 2.1

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

3 participants