guillaumeboehm/wal-telegram

Theme exceeds size limit

Closed this issue · 8 comments

What happened

Some of the themes generated by this script failed to apply for me, falling back to the default theme. Even when I'd manually choose the theme file going to "Settings > Chat Settings", nothing happened.

Taking a look at the script, I noticed that after converting them from JPG to PNG, some of my background images had a significant increase in size (from ~2MB to ~15MB) and that seems to be preventing them from being applied, i.e., Telegram themes seem to have a size limit.

Watching their size, the largest theme that could be successfully applied had 3,8 MB and the smallest to fail had 6,9 MB (nothing in between, so I don't really know the exact limit).

One more thing I noticed is that, when themes failed, extracting the zip file and manually applying the palette and background image worked fine. Telegram probably deals with the size issue when the user directly selects an image.

The "fix"

The resize option is only being used to set 1920 as the minimum width.

wal-telegram/wal-telegram

Lines 415 to 421 in 63d9924

elif [[ "$bg_mode" = "background" ]]; then
size=$(magick identify -format "%w" ${bg_mode}.${bg_ext})
# shellcheck disable=SC2086
convert ${bg_mode}.${bg_ext} $blur -resize $(( size > 1920 ? size : 1920 )) ${bg_mode}.png
fi
zip -q ${mode}.tdesktop-theme colors.tdesktop-theme ${bg_mode}.png
cp ${mode}.tdesktop-theme "$dest"

Changing line 418 to resize the image to my screen resolution seems to work for me, as that also means a decrease in size:

convert ${bg_mode}.${bg_ext} $blur -resize 1920 ${bg_mode}.png

I'm writing this as a quick fix to anyone having the same issue, but it would be nice to have an option to either compress or resize the background image according to a value specified by the user (or automatically, by getting their screen resolution), so that people wouldn't have to manually change that in the script. Letting people know what's happening by printing a message or warning for large theme files would also be good.

Oh ok didn't think there would be a size limit, well I guess I'll simply convert to jpg instead. Quality should probably be good enough in most cases anyway.

Yeah, a lossy conversion would probably work, but without any compression option it would still be hard to guarantee the theme size is within the size limit, right?

Since we can't be sure about the limit, I think it'd be a good idea to add a note in the README.md

I was thinking about taking a somewhat heavy but I think pretty safe fix by reducing the image quality until hitting 1M filesize. It's not like this is a software that's to be called every seconds so I think it's fine if it take a couple seconds to convert the background.

Fixes are pushed to master, if you could test it out a bit and tell me if it works alright for you.

Fixes are pushed to master, if you could test it out a bit and tell me if it works alright for you.

It did work, but in some cases it took quite a few seconds to apply. I saw that you are decreasing the quality level by one after each try, maybe changing the step to 5 would help with that. I don't think it'd cause a significant loss of quality. Changing the size limit to ~3 MB would also be safe, I think.

Also, just a suggestion, but you can get the JPG quality level using magick identify and start decreasing from there instead of 100

Yeah I can maybe make bigger steps. For the size limit I've seen some warnings in the telegram logs about the size passed 1M so I'll keep it at that I think. And good call for the starting quality too thanks.

Oh, I see. Well, I think this this issue can be closed now, thank you for the fix.