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
Getting a NoSuchMethodError: The getter 'exif' was called on null.
when converting a .png to .jpeg
#67
Comments
Sorry, I messed that one up, didn’t put in proper checking. I’ll be able to
fix it tonight.
…On Sun, May 27, 2018 at 11:26 AM Pablo Compagni ***@***.***> wrote:
This is my code. Image comes directly from the camera using the
image_picker plugin:
var imageFile = await ImagePicker.pickImage(source: ImageSource.camera);
try {
var pngImage = image.decodePng(imageFile.readAsBytesSync());
print("## Image decoded fine");
var jpegFile = new File(path.join(tempPath, 'upload.jpg'));
print("## 1");
var jpegBytes = image.encodeJpg(pngImage);
print("## 1B");
jpegFile.writeAsBytesSync(jpegBytes);
print("## 2");
imageFile = jpegFile;
print("## 3");
} catch (error) {
print("## ERROR");
print(error);
print("## ERROR DONE");
}
And it logs to console:
I/flutter (15417): ## Camera filename/storage/emulated/0/Android/data/com.scanrapp/files/Pictures/3967201f-c26f-49db-8d04-09929bace1f21282873232.png
I/flutter (15417): ## Image decoded fine
I/flutter (15417): ## 1
I/flutter (15417): ## ERROR
I/flutter (15417): NoSuchMethodError: The getter 'exif' was called on null.
I/flutter (15417): Receiver: null
I/flutter (15417): Tried calling: exif
I/flutter (15417): ## ERROR DONE
If instead of decodePng I use decodeImage, then it doesn't fail. But the
generated image seems invalid, I can't open it with any application.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#67>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADeS8wPqfadgHpkZSf5bV0beNOWOpTdLks5t2u_IgaJpZM4UPYHf>
.
|
Just did some more testing. thanks! |
I don’t know ImagePicker at all. What type of image does it produce?
Cameras usual encode jpegs, I’m curious if it’s encoded as png. Since it’s
returning null, I suspect it’s not a png. I’m not sure why it’s malformed,
unless maybe it’s some sort of hdr image that’s not supported (proper error
messages would be nice).
…On Sun, May 27, 2018 at 11:40 AM Pablo Compagni ***@***.***> wrote:
Just did some more testing. decodePng returns null for my image, so that
explains the The getter 'exif' was called on null error, not sure why
that returns null though. Using decodeImage works, and returns an Image
object. Although it then seems to generate a malformed jpeg.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADeS80f-WFU71aVwe8fnR1QEGPwBNjR0ks5t2vM0gaJpZM4UPYHf>
.
|
Thanks for the help, I found something new (sorry for all the back and forth). ImagePicker plugin saves a .png file, but the content is actually is a JPEG image (flutter/flutter#17947). So that explains decodePng returning null, and decodeImage working. The malformed image it's harder to reproduce I guess, I'm uploading the image to a python backend and saving it as a file. I'm confident that part of the code works fine, cause I have no problems with other images, only the ones that go though this process. The example code might seems useless now, but I'm planning on using this to reduce the size of the file before uploading, so I'm still hoping this to work. About error messages, the Python backend shows this when trying to open with Pillow: |
If you have an example image, I can debug it tonight.
…On Sun, May 27, 2018 at 12:07 PM Pablo Compagni ***@***.***> wrote:
Thanks for the help, I found something new (sorry for all the back and
forth). ImagePicker plugin saves a .png file, but the content is actually
is a JPEG image (flutter/flutter#17947
<flutter/flutter#17947>). So that explains de
decodePng returning null, and decodeImage working.
The malformed image it's harder to reproduce I guess, I'm uploading the
image to a python backend and saving it as a file. I'm confident that part
of the code works fine, cause I have no problems with other images, only
the ones that go though this process. The example code might seems useless
now, but I'm planning on using this to reduce the size of the file before
uploading, so I'm still hoping this to work.
About error messages, pythons shows this when trying to open with Pillow: broken
data stream when reading image file. And if it open it on my mac:
[image: screen shot 2018-05-27 at 4 06 48 pm]
<https://user-images.githubusercontent.com/2463995/40589671-fe8219f2-61c7-11e8-9149-1f17cd3613ec.png>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADeS86ugcv9oSny-e1Rao1ZVHSpH0WEmks5t2vlbgaJpZM4UPYHf>
.
|
Thank you very much. |
Would it be possible to get the original image out of ImagePicker? |
Looking at that jpeg, it starts off ok, has the correct tags. It gets to the EXIF tag (which I just recently added), and the file goes wrong from that point on. If I had the original file, I could determine why the EXIF block got messed up. |
Actually, I found some jpeg exif unit test images and some of them produce corrupted output images too, so I can use those to debug with. |
I got all of the jpegs that were generating bad output images fixed. The problem was caused by multiple exif blocks in the jpeg. Hopefully it will fix your particular issue, but I can't know for sure until you can test it. |
Unfortunately I'm only saving the final image, not the before and after, but I'll do that tonight and get you a sample. So there's an updated version of the lib with a fix? :D I'll try that tonight too, thanks! |
I didn’t publish it, it’s in git. I can publish it this afternoon.
…On Mon, May 28, 2018 at 6:03 AM Pablo Compagni ***@***.***> wrote:
Unfortunately I'm only saving the final image, not the before and after,
but I'll do that tonight and get you a sample. So there's an updated
version of the lib with a fix? :D I'll try that tonight too, thanks!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADeS83rb3YPdou6zfJ1QBBz_dQ3vtpxCks5t2_WQgaJpZM4UPYHf>
.
|
Attaching a before and after of the images. This is the code running in between:
|
Great, I’ll verify yesterday’s fix works for this, and I’ll push the new
version if it does (and fix it if not.)
…On Mon, May 28, 2018 at 1:59 PM Pablo Compagni ***@***.***> wrote:
Attaching a before and after of the images. This is the code running in
between:
await ApiClient.postDocument(this.loggedInUser, imageFile);
imageFile = await ApiClient.convertToJpeg(imageFile);
await ApiClient.postDocument(this.loggedInUser, imageFile);
static Future<File> convertToJpeg(File imageFile) async {
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
try {
var pngImage = image.decodeImage(imageFile.readAsBytesSync());
print("## Image decoded fine");
var jpegFile = new File(path.join(tempPath, 'upload.jpg'));
print("## 1");
var jpegBytes = image.encodeJpg(pngImage, quality: 85);
print("## 1B");
jpegFile.writeAsBytesSync(jpegBytes);
print("## 2");
return jpegFile;
} catch (error) {
print("## ERROR");
print(error);
print("## ERROR DONE");
throw error;
}
}
images.zip
<https://github.com/brendan-duncan/image/files/2046172/images.zip>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADeS8wHq8b6lDmPWVCI8gNu_PgMOW7Mxks5t3GVEgaJpZM4UPYHf>
.
|
Another sample, this time with |
I verified it does fix the output images. I have to fix one more thing with it, but I’ll be able to push the new version this evening (after I get the kids to bed.) |
awesome, thanks |
I pushed the new version, 2.0.1, to pub. It was one of things where it should never have worked to begin with, I don't know what voodoo made most jpeg encoded images not be broken before this. |
Great! Does it take a while for pub to show new versions? I was about to test this and I still see 2.0.0 as latest |
There shouldn't be any delay...unless I spaced out on actually running `pub
publish`, which is entirely possible. I was updating my other package at
the same time, maybe my brain wires got crossed. I'll try it again.
…On Tue, May 29, 2018 at 2:29 PM Pablo Compagni ***@***.***> wrote:
Great! Does it take a while for pub to show new versions? I was about to
test this and I still see 2.0.0 as latest
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADeS85Dmq3MLzJcN_5Ze7q23XdKHePOkks5t3b2wgaJpZM4UPYHf>
.
|
I published it, and actually checked this time that it got uploaded to pub. |
I just tested this and it's working great, thanks! :) |
Hey, Can I talk to you about the issue, I'm facing same kind of problem |
This is my code. Image comes directly from the camera using the image_picker plugin:
And it logs to console:
If instead of
decodePng
I usedecodeImage
, then it doesn't fail. But the generated image seems invalid, I can't open it with any application.The text was updated successfully, but these errors were encountered: