qpixel
qpixel copied to clipboard
Prevent user avatar animation until a community decision is made
Describe the bug See Let's not allow dynamic avatars on Codidact Meta.
Until the community settles on a longer term solution, anyone is free to upload an animated avatar and no-one can avoid seeing them under posts.
To Reproduce See the example question linked from the Meta post.
Expected behavior There should be no animation of an avatar, even if the uploaded image was animated.
I see 3 potential ways to prevent user avatar animation:
- Reject the upload of any image format that supports animation (such as the GIF format).
- Allow upload but convert to a non-animated image format before saving (for example, server side conversion from GIF to PNG).
- Client side suppression of the animation of images that are already uploaded (such as GIFs).
As this is a quick (and potentially temporary) fix to prevent accessibility concerns and potentially medical issues, I'd recommend we go with whichever is considered quickest to implement, and leave consideration of the best long term approach for after the community has decided on what they want to see.
PNG supports animations. You probably want to continue allowing uploads in PNG format
Thanks for the warning. I definitely want PNG to be supported. When I suggested option 1 I had assumed that APNG had a different file extension but I've just checked and it can be .png just the same as a still image.
We could probably still check the file content to determine the file type, but that would depend on being able to do that both client side and server side ideally.
I don't think this necessarily rules out option 1 but we definitely can't do it based on file extension.
Checking if a PNG is animated is non-trivial. It's just a normal PNG file with some extra types of chunks. Any image processing library should be able to do it but it's more complex than just checking the magic number.
Oh I see. I guess that's so it's still displayable as a static PNG by browsers that don't support APNG?
In that case I'd lean towards option 2, at least server side, with client side as a separate issue to avoid holding this one up.
On the server side I believe ImageMagick is already available, so hopefully saving a static version alongside each image should be possible. Ideally we'd continue to save the original image and just not display it, so those images that happen to have animation can be displayed in future if we end up with a user setting and/or a community setting.
Uploads all go through the same code path, I'm pretty sure, and a question might legitimately need an animated image. So let's not prevent the upload unless we're sure it only affects profile images. If feasible, let's let the upload go through but prevent avatars from rendering with the animation. (I don't know if that means 2 or 3 is better.)
Ah I see. That does seem to rule out 1.
I'm still leaning towards 2, as 3 would require loading an image library for every user who is not opted in to animation (so everyone until a community decision is reached), slowing down page load and slowing down more for the processing required for every avatar on the page. It would also require serving the full animated version of every avatar (large file size) only to then convert it to a much smaller non-animated version on the user's machine.
2 would require one of:
- Storing both animated and non-animated versions of every animated upload. Consequence: potentially slow saving of uploaded avatar.
- Storing the uploaded version (which may be animated) and doing a conversion to a non-animated version before serving it to a user who is not opted in to animation. Consequence: potentially slow loading of every page that contains an avatar.
The first approach affects far fewer users, and far less often, but is less straightforward to implement.
Perhaps rather than trying to be future proof for when a community decision is made, we just throw away the animated version for now so we do 2 (convert at the point of upload) but don't save the original. The only drawback I see is that anyone who wants an animated avatar after the future approach is implemented will have to upload it again (which doesn't seem like much of a drawback).
I'm ok with "as you saw, we didn't give you your animated avatar when you uploaded it, and if we change how this works in the future you'll have to re-upload, so save it if you want it".
Are we able to intercept and convert animated images only for avatars, without restricting image uploads in posts? This might mean passing a flag to the code that processes uploads, so that code can either save as-is or convert.
A flag sounds good. I'm not familiar with the code that processes uploads but I would imagine we could modify it to take an extra flag and give it a default value, so we wouldn't have to modify any of the other places in the code that call it without the flag. So it still shouldn't be a big change.
Yeah, it should default to what we do now (i.e. not modify).