Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Experimental GIF Thumbnailing support #9705

Conversation

ShadowJonathan
Copy link
Contributor

@ShadowJonathan ShadowJonathan commented Mar 27, 2021

Hopefully resolves #1278

Adds in some fixes and refactors to synapse.rest.media.v1.thumbnailer.Thumbnailer that makes it able to recognise image/gif as an output type and transform images accordingly.

This is experimental for the following reasons;

  • Currently no GIF resources are expected on the Element client, allowing this to be on by default will cause people to be able to "visually spam" others by setting their avatars, room icons, or just sending specific "emoji" images as GIFs.
    • The solution would be a better awareness in the Element repos for animated images, which this PR calls for.
  • Processing GIFs might be heavy on servers, as each individual frame has to be transformed.
  • In it's current state, there can be some thumbnailing codepaths and transformations that might be missed by unit testing, so this hasn't been "really" tested.

For these reasons, GIF thumbnailing support is experimental and disabled by default.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
  • Pull request includes a sign off
  • Code style is correct (run the linters)

Signed-off-by: Jonathan de Jong <[email protected]>

@@ -70,6 +70,7 @@ def parse_thumbnail_requirements(thumbnail_sizes):
method = size["method"]
jpeg_thumbnail = ThumbnailRequirement(width, height, method, "image/jpeg")
png_thumbnail = ThumbnailRequirement(width, height, method, "image/png")
gif_thumbnail = ThumbnailRequirement(width, height, method, "image/gif")
Copy link
Contributor Author

@ShadowJonathan ShadowJonathan Mar 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea how to go further with this, as this happens in a .config. file, and to "enable" this, you'd need to grab something from the "experimental" config section (as is custom for experimental stuff), however, i dunno how to do this without messing up imports or something

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other interdependencies between config sections (see for example ApiConfig which checks self.spaces_enabled, which is part of ExperimentalConfig). As long as ContentRepositoryConfig appears after ExperimentalConfig in the HomeServerConfig definition, this will work. It's not particularly elegant, but 🤷‍♂️

@@ -93,27 +93,16 @@ def aspect(self, max_width: int, max_height: int) -> Tuple[int, int]:
else:
return (max_height * self.width) // self.height, max_height

def _resize(self, width: int, height: int) -> Image:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(reordering public methods above private ones)

self.image, output_type, lambda i: self._crop(i, width, height)
)

def _process_animated_aware(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rule of three should apply here, but this piece is a bit complex, and the only thing that'd really change between the two functions is changing _resize with _crop, thus the abstraction

else:
return self._encode_image(transform(image), output_type)

def _crop(self, image: Image, width: int, height: int) -> Image:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to-private and addition of image to decouple it and make it able to be used as a generic image transformer

@clokep
Copy link
Member

clokep commented Mar 29, 2021

Are you hoping to get feedback for this or still tweaking it? (Are you looking for a review?)

@ShadowJonathan
Copy link
Contributor Author

On above self-reviews, yes, I'm inviting comments, because i need some direction on this before i actually finish this, i wish I could communicate that clearer, but i think putting it on "ready" isn't one of them, as then the PR would be considered done, which it certainly isn't.

@clokep clokep requested a review from a team March 29, 2021 16:11
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant about the concept here, even behind an experimental option, unless it's a thing that the matrix protocol actually wants to support. In the best case it becomes a maintenance burden in Synapse; in the worst case lots of people start using gifs (animated or otherwise) and it becomes a thing the matrix protocol has to support forever.

In the interest of trying to stimulate discussion on this from the spec POV, I've commented at https://github.com/matrix-org/matrix-doc/issues/1938#issuecomment-810968551.

@ShadowJonathan
Copy link
Contributor Author

I agree, I sorta found the way thumbnails are identified/retrieved fairly weird, maybe a comprehensive thumbnail endpoint (f.e. one that supports multiple representations of the same media, animated or not) could definitively solve this.

I'll wait for a resolution/MSC, until then, this PR is probably stalled.

@erikjohnston erikjohnston added the z-blocked (Deprecated Label) label Nov 1, 2021
@ShadowJonathan
Copy link
Contributor Author

This PR almost certainly has bitrotted, and it is still blocked on matrix-org/matrix-spec#453, so i'll close this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
z-blocked (Deprecated Label)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thumbnailing animated GIFs (or showing they're an animation) (SYN-251)
4 participants