-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Do not remove orientation EXIF data #683
Do not remove orientation EXIF data #683
Conversation
0b920c2
to
6e840db
Compare
Finally done: 2023-12-17.15-57-52.mp4TODO:
mhh, for some reason, EXIF is no longer removed 🤔 |
I think I found the error. Apparently, Javascript also has the notion of transferable objects, similar to languages like C++. Because of that, the buffer that I passed into
Now trying to fix, for example via Tried to find out at which point the EXIF scrubbing gets broken by redoing all my steps, starting at 6763ef7. I have a feeling it's related to arrow functions vs regular functions. But I will continue after I slept. |
Can't use What I still don't get why removing EXIF data works in 6763ef7, but when I started to add code to save the orientation value before removing the EXIF data, it suddenly no longer works. Sounds like just accessing the buffer in some way changes behavior down the line in the code regarding this buffer? I feel like Javascript is trolling or even conspiring against me, lol I will try to read as much as I can about Transferable objects now. There MUST be a way. And it CAN'T be that hard. 😄 If I am still not done with this by 4PM CET, I will just start working on #661 and #662 as mentioned here and come back to this later. Also #684 annoys me a lot so maybe I'll also do that. Okay, already the beginning tells me that this is most likely caused by all the promises that I use due to Javascript's event-driven architecture:
but I thought this whole "array buffer getting detached and thus we no longer point to the buffer that is actually getting cleaned from EXIF data" problem is caused while |
An alternative approach would be to simply read the orientation data, remove the metadata, then rotate the image. I'm not sure how simple that is, but it sounds like most of the issue here is writing EXIF data so why don't we just not write it. |
I am currently failing at the "remove the metadata" step because of this buffer transferring between threads. The cleaned buffer is no longer reflected in the thread that will upload the image. So according to my current understanding, it's basically removing the EXIF data in another thread and then throwing away this buffer later, lol. It's weird. The existing code works but if I slightly try to change it (adding some promises for example), it suddenly no longer works. So writing is currently not the problem. Removing it is (I know how weird that sounds since we're already able to remove it in the running code). One solution is probably to not add "some promises". Or just completely rewrite this code and use canvas drawing. I even tried to use |
6e840db
to
4d03721
Compare
Proof of fix: 2023-12-19.11-04-58.mp4Going to lunch now. Will refactor afterwards and test some more. Update: Done. Tested JPEGs with and without orientation metadata, WEBP, GIF, PNG. All good. |
4d03721
to
55104fb
Compare
I think you forgot to include package.json |
Oh right, |
Fix #678
Keeping this in draft until I confirmed this does indeed not strip orientation EXIF data - which I am going to do now.
I got the tag value 0x0112 from here.
Okay, 21a9c3e does not work because we are actually deleting all EXIF data at once. So the loop is not iterating over EXIF "tags". It's searching for the start of the EXIF data and then deleting it all at once. At least that is my current understanding which I am writing down here to not forget that this is my current "baseline of progress".
I think I need to dive deeper into the EXIF spec to be able to do what some tools can do on the CLI in JS using our existing approach.
There are libraries which handle EXIF data in JS but they seem to be either unmaintained, or not necessary. I also don't like new dependencies anymore. There is a way to do it within our code but ... might take me too long to pull it off. I'll keep trying for a few hours more at least :)
Worst case scenario, I have to look at the source code of these tools to see how they manage to keep orientation data.
Ok I stopped trying to get this to work without using a library since it is taking me too long and doing binary stuff in Javascript is definitely not my strength, lol. I am now trying to simply use piexifjs even though last update was from 4 years ago. But the EXIF spec seems to be from 1999 itself, so maybe the latest update doesn't matter? If I can get it to work with a library, maybe THEN I am able to do it without a library, lol.
I should learn to find the right order of doing things, lol. First try the simple thing so I at least have something working which I can fall back on when other things don't work out for whatever reason.
Tried to get piexifjs to work but somehow it didn't work. Didn't even get a real error message. Trying out sharp now because it was mentioned as an alternative in a ticket. Turns out that is super maintained since the last commit is literally from 15 hours ago, lol.
So I think we should really go with this if possible.
Seems like it only runs on the server, not in the browser:
lol, I found another custom code just for orientation now. Going to try this now. If not, I can try this SO code using the even older exif-js library but someone said:
Okay, finally was able to read the orientation metadata with the custom code provided, lol
For some reason, struggling with the last step of putting the extracted orientation value back in after deleting everything else ...
finding this piece of documentation was what i was missing all along. and it turns out, using a simple int was right all along (as I initially tried), I just must have gotten confused that there was still an error:
Looking at the code, the documentation and basically everything about this library: i guess this library really only supports JPEG, lol:
documentation:
example:
code
mhh, but I think that's not a problem since there aren't other file formats we allow that can have EXIF data according to my research while working on #634. So I guess this is just another additional indicator that there are indeed no other common image files that allow EXIF next to JPEG.
So I think the only stuff left to do is this (I am finally back with my TODOs in PR descriptions, lol):
getOrientation
to required values forpiexifjs
.I thinkthat's the cause that some JPEGs still throwpack error
since there is aval > 0
check in the library butgetOrientation
can return value < 0 (ah, no mapping required, just filter for value < 0)+ make sure there is indeed no EXIF with a sanity checkimg.src
is set to themWhat the spec says on page 30 about the values for orientation:
source