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

Animated sticker import #6

Open
tulir opened this issue Sep 5, 2020 · 16 comments
Open

Animated sticker import #6

tulir opened this issue Sep 5, 2020 · 16 comments
Labels
enhancement New feature or request

Comments

@tulir
Copy link
Member

tulir commented Sep 5, 2020

Lottie files can be converted using https://github.com/sot-tech/LottieConverter like mautrix-telegram does. Probably need to convert to gif to make it work, even though that's not such a nice format

@tulir tulir added the enhancement New feature or request label Sep 5, 2020
@Ai-rin
Copy link

Ai-rin commented Feb 2, 2021

convert to gif

Why not apng?

@Bubu
Copy link

Bubu commented Mar 17, 2021

What about keeping them as lottie files and rendering them via https://github.com/airbnb/lottie-web?

(And then of course shoving lottie support into all the clients as well... eventually)

@tulir
Copy link
Member Author

tulir commented Mar 17, 2021

(And then of course shoving lottie support into all the clients as well... eventually)

That would have to be the first step, not the eventually step

@Bubu
Copy link

Bubu commented Mar 17, 2021

That would have to be the first step, not the eventually step

🤷 This is a bit of a chicken/egg problem isn't it? I think this would be useful to have even with partial client support.

@Bubu
Copy link

Bubu commented Jul 14, 2021

Fluffychat can now render lottie files: https://gitlab.com/famedly/fluffychat/-/blob/main/CHANGELOG.md#v0340-2021-07-13

@williamkray
Copy link

the comments on here sound unrelated, but the existing pack command leverages the convert_image function, both of which assume that the image packs should only include .png files. is this the right issue to request that those functions be updated to include logic that allows for animated gif sticker pack creation and import?

@Trendyne
Copy link

I don't understand why the images are force converted at all. If it supports the original image format, which from the thread it seems like it, then use it. I was encoding my stickers as lossless webps so they'd be better compressed, but apparently that's useless. Stickers are easily made 2x the size for no good reason. And if lossy formats are used, it would be even worse

@tulir
Copy link
Member Author

tulir commented Oct 26, 2021

webp support is fairly recent on iOS, and the original format in question in this issue (lottie) isn't supported anywhere. The conversion could probably be removed now, but it won't help with this issue.

@Trendyne
Copy link

Webps do support animations

@Oha-you
Copy link

Oha-you commented Dec 27, 2021

You can actually upload an APNG/WebP image as a GIF so that it's stored with image/gif mime type.
And then describe it as image/gif in your json too, like so: test.json#L12
Thanks to this, an isGif check in Element will return true and your sticker will be treated as a normal GIF.
If people enabled "Autoplay GIFs", a source image will be displayed instead of a static preview: MImageBody.tsx#L550

Example sticker pack: https://oha-you.github.io/stickerpicker/web/?theme=$theme
Live demo: https://matrix.to/#/!stickerpicker:maunium.net/$p5lFnqaeTJxCTssiMEZx6Gv4Dh3NQeQWWvSlhe_tz9o?via=maunium.net&via=matrix.org&via=envs.net

You also need to disable PNG conversion, of course. Here's how I patched it: Oha-you@3eb61e4
I didn't touch stickerimport.py since I don't plan to convert any stickers (I'll prepare them manually).
You can probably add fancy detection of animated webp/apng images, but since I'll probably have separate animated sticker packs, I just added a lazy one-liner to force image/gif here: pack.py#L58

Note: currently such animations won't play on mobile, at least in Element Android. It's an upstream issue (even for actual GIFs)

@LuckyTurtleDev
Copy link

LuckyTurtleDev commented Jan 27, 2022

The sticker picker itself does support gifs. You can upload a pack with gifs and it work fine. The only issue is that their is now moved preview.

Because the import program of this repo does not support converting tgs to gif you need a different tool for this.
I have written an alternative import program, witch does support tgs: Lukas1818/mstickereditor

@HerrFrutti
Copy link

HerrFrutti commented Mar 14, 2023

I've played around with your suggestions and have implemented the changes from @Oha-you.

I've added a stupid option to argparse so now you can add --animated 1 and it assumes the png's are animated. It's not super clean to use a global var to check if the animated var is true, but I did not want to waste to much time...

https://github.com/HerrFrutti/stickerpicker/blob/a9e7783263f6b92e782aff296a54a70f62dea421/sticker/pack.py#L142-L143

@HerrFrutti
Copy link

Oh and one weird thing is, that my stickers are not animated on my pack in the web, but if I send them in my chat, they are animated. Maybe my file format is wrong? I tried with webp and apng, both are not animated on the website, but in matrix chat they are.

like in the example from @Oha-you :

Example sticker pack: https://oha-you.github.io/stickerpicker/web/?theme=$theme

@Oha-you
Copy link

Oha-you commented Mar 14, 2023

@HerrFrutti Ah, that's probably because I've added this commit as well Oha-you@f71cce9
Replaces thumbs with source images on mouse hover. Maybe that's not desirable for static stickers, but in my use case it worked fine.

@LuckyTurtleDev
Copy link

stickers are not animated on my pack in the web, but if I send them in my chat, they are animated

The preview is created by the selected matrix home server. It does only created a static image preview.

lxndrbnsv added a commit to lxndrbnsv/stickerpicker that referenced this issue May 10, 2023
@Nannk
Copy link

Nannk commented Feb 15, 2024

Default solution did not work for me, animated stickers were converted to still pngs. I had to modify stickers/pack.py to not convert gifs, but upload them as is.
A solution was posted in stickerpicker matrix room, but i had to modify it too.
here is my solution:

from PIL import Image

in sticker/pack.py:
in upload_sticker:
else of if sticker_id in old_stickers:

else:
        # dont convert only if its a gif
        if path.endswith('.gif'):
            with Image.open(path) as img:
                width, height = img.size
        else:
            image_data, width, height = util.convert_image(image_data)
        print(".", end="", flush=True)
        mxc = await matrix.upload(image_data, "image/png", file)
        print(".", end="", flush=True)
        sticker = util.make_sticker(mxc, width, height, len(image_data), name)
        sticker["id"] = sticker_id
        print(" uploaded", flush=True)
    return sticker

Now the only problem is that .gif are sent as .png event. It works on matrix, but discord bridge bridges those as .png. So i had to manually change generated json file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants