Files
limoka/SunnexGB/Heroku-Modules/Assets/TgTheme/TgThemeLib.py
2026-06-21 02:58:54 +00:00

827 lines
44 KiB
Python

# requires: Pillow
import io
from PIL import Image
from .. import loader
class ThemeLib(loader.Library):
developer = "@SunnexGB"
def extract_colors(self, img, count=10):
small = img.copy().convert("RGB")
if max(small.size) > 200:
scale = 200 / max(small.size)
small = small.resize(
(int(small.size[0] * scale), int(small.size[1] * scale)),
Image.LANCZOS,
)
buckets = {}
for r, g, b in small.getdata():
key = (r >> 4, g >> 4, b >> 4)
if key not in buckets:
buckets[key] = [r, g, b, 1]
else:
buckets[key][0] += r
buckets[key][1] += g
buckets[key][2] += b
buckets[key][3] += 1
top = sorted(buckets.values(), key=lambda x: x[3], reverse=True)
colors = [(sr // c, sg // c, sb // c) for sr, sg, sb, c in top[:count]]
return tuple(f"{c[0]:02x}{c[1]:02x}{c[2]:02x}" for c in colors[:3])
def darken(self, h, factor=0.7):
return (
f"{int(int(h[0:2], 16) * factor):02x}"
f"{int(int(h[2:4], 16) * factor):02x}"
f"{int(int(h[4:6], 16) * factor):02x}"
)
def blend(self, h1, h2, ratio=0.15):
r1, g1, b1 = int(h1[0:2], 16), int(h1[2:4], 16), int(h1[4:6], 16)
r2, g2, b2 = int(h2[0:2], 16), int(h2[2:4], 16), int(h2[4:6], 16)
return (
f"{int(r1 * (1 - ratio) + r2 * ratio):02x}"
f"{int(g1 * (1 - ratio) + g2 * ratio):02x}"
f"{int(b1 * (1 - ratio) + b2 * ratio):02x}"
)
def build_theme(self, bg_color, text_color, accent_color, alpha="ff"):
tr = lambda c, a: f"#{a}{bg_color if c == 'f' else text_color if c == 't' else accent_color}"
dsel = f"#{alpha}{self.blend(bg_color, accent_color, 0.25)}"
return (
f"actionBarActionModeDefault={tr('f', alpha)}\n"
f"actionBarActionModeDefaultIcon=#{text_color}\n"
f"actionBarActionModeDefaultSelector=#{accent_color}\n"
f"actionBarActionModeDefaultTop=#{accent_color}\n"
f"actionBarActionModeReaction=#{accent_color}\n"
f"actionBarActionModeReactionText=#{text_color}\n"
f"actionBarActionModeReactionDot=#{text_color}\n"
f"actionBarBrowser=#{accent_color}\n"
f"actionBarDefault={tr('f', alpha)}\n"
f"actionBarDefaultArchived=#{accent_color}\n"
f"actionBarDefaultArchivedIcon=#{accent_color}\n"
f"actionBarDefaultArchivedSearch=#{accent_color}\n"
f"actionBarDefaultArchivedSelector=#{accent_color}\n"
f"actionBarDefaultArchivedTitle=#{accent_color}\n"
f"actionBarDefaultIcon=#{text_color}\n"
f"actionBarDefaultSearch=#{accent_color}\n"
f"actionBarDefaultSearchArchivedPlaceholder=#{accent_color}\n"
f"actionBarDefaultSearchPlaceholder=#{accent_color}\n"
f"actionBarDefaultSelector=#{accent_color}\n"
f"actionBarDefaultSubmenuBackground={tr('f', alpha)}\n"
f"actionBarDefaultSubmenuItem=#{text_color}\n"
f"actionBarDefaultSubmenuItemIcon=#{text_color}\n"
f"actionBarDefaultSubmenuSeparator=#{text_color}\n"
f"actionBarDefaultSubtitle=#{text_color}\n"
f"actionBarDefaultTitle=#{text_color}\n"
f"actionBarTabActiveText=#{accent_color}\n"
f"actionBarTabLine=#{accent_color}\n"
f"actionBarTabSelector=#{accent_color}\n"
f"actionBarTabUnactiveText=#{text_color}\n"
f"actionBarWhiteSelector=#{accent_color}\n"
f"avatar_actionBarIconBlue=#{text_color}\n"
f"avatar_actionBarSelectorBlue=#{accent_color}\n"
f"avatar_backgroundActionBarBlue=#{accent_color}\n"
f"avatar_backgroundArchived=#{accent_color}\n"
f"avatar_backgroundArchivedHidden=#{accent_color}\n"
f"avatar_backgroundBlue=#{accent_color}\n"
f"avatar_backgroundCyan=#{accent_color}\n"
f"avatar_backgroundGreen=#{accent_color}\n"
f"avatar_backgroundInProfileBlue=#{text_color}\n"
f"avatar_backgroundOrange=#{accent_color}\n"
f"avatar_backgroundPink=#{accent_color}\n"
f"avatar_backgroundRed=#{accent_color}\n"
f"avatar_backgroundSaved=#{accent_color}\n"
f"avatar_backgroundViolet=#{accent_color}\n"
f"avatar_background2Blue=#{accent_color}\n"
f"avatar_background2Cyan=#{accent_color}\n"
f"avatar_background2Green=#{accent_color}\n"
f"avatar_background2Orange=#{accent_color}\n"
f"avatar_background2Pink=#{accent_color}\n"
f"avatar_background2Red=#{accent_color}\n"
f"avatar_background2Saved=#{accent_color}\n"
f"avatar_background2Violet=#{accent_color}\n"
f"avatar_nameInMessageBlue=#{accent_color}\n"
f"avatar_nameInMessageCyan=#{accent_color}\n"
f"avatar_nameInMessageGreen=#{accent_color}\n"
f"avatar_nameInMessageOrange=#{accent_color}\n"
f"avatar_nameInMessagePink=#{accent_color}\n"
f"avatar_nameInMessageRed=#{accent_color}\n"
f"avatar_nameInMessageViolet=#{accent_color}\n"
f"avatar_subtitleInProfileBlue=#{text_color}\n"
f"avatar_text={tr('f', alpha)}\n"
f"bot_loadingIcon=#{text_color}\n"
f"calls_callReceivedGreenIcon=#{accent_color}\n"
f"calls_callReceivedRedIcon=#{text_color}\n"
f"changephoneinfo_image2=#{text_color}\n"
f"chats_actionBackground=#{accent_color}\n"
f"chats_actionIcon={tr('f', alpha)}\n"
f"chats_actionMessage=#{accent_color}\n"
f"chats_actionPressedBackground=#{accent_color}\n"
f"chats_archiveBackground=#{accent_color}\n"
f"chats_archiveIcon={tr('f', alpha)}\n"
f"chats_archivePinBackground=#{accent_color}\n"
f"chats_archivePullDownBackground=#{accent_color}\n"
f"chats_archivePullDownBackgroundActive=#{accent_color}\n"
f"chats_archiveText={tr('f', alpha)}\n"
f"chats_attachMessage=#{accent_color}\n"
f"chats_date=#{text_color}\n"
f"chats_draft=#{accent_color}\n"
f"chats_mentionIcon={tr('f', alpha)}\n"
f"chats_menuBackground={tr('f', alpha)}\n"
f"chats_menuItemCheck=#{text_color}\n"
f"chats_menuItemIcon=#{text_color}\n"
f"chats_menuItemText=#{text_color}\n"
f"chats_menuName=#{accent_color}\n"
f"chats_menuPhone=#{text_color}\n"
f"chats_menuPhoneCats=#{text_color}\n"
f"chats_menuTopBackground=#{accent_color}\n"
f"chats_menuTopBackgroundCats=#{accent_color}\n"
f"chats_menuTopShadow=#00000000\n"
f"chats_menuTopShadowCats=#00000000\n"
f"chats_message=#{text_color}\n"
f"chats_messageArchived=#{text_color}\n"
f"chats_message_threeLines=#{text_color}\n"
f"chats_muteIcon=#{text_color}\n"
f"chats_name=#{text_color}\n"
f"chats_nameArchived=#{text_color}\n"
f"chats_nameMessage=#{accent_color}\n"
f"chats_nameMessageArchived=#{accent_color}\n"
f"chats_nameMessageArchived_threeLines=#{accent_color}\n"
f"chats_nameMessage_threeLines=#{accent_color}\n"
f"chats_onlineCircle=#{accent_color}\n"
f"chats_pinnedIcon=#{text_color}\n"
f"chats_pinnedOverlay=#00000000\n"
f"chats_secretIcon=#{accent_color}\n"
f"chats_secretName=#{accent_color}\n"
f"chats_sentCheck=#{accent_color}\n"
f"chats_sentClock=#{text_color}\n"
f"chats_sentError=#{text_color}\n"
f"chats_sentErrorIcon={tr('f', alpha)}\n"
f"chats_sentReadCheck=#{accent_color}\n"
f"chats_tabUnreadActiveBackground=#{accent_color}\n"
f"chats_tabUnreadUnactiveBackground=#{accent_color}\n"
f"chats_tabletSelectedOverlay=#00000000\n"
f"chats_unreadCounter=#{accent_color}\n"
f"chats_unreadCounterMuted=#{text_color}\n"
f"chats_unreadCounterText={tr('f', alpha)}\n"
f"chats_verifiedBackground=#{accent_color}\n"
f"chats_verifiedCheck={tr('f', alpha)}\n"
f"chat_addContact=#{accent_color}\n"
f"chat_adminSelectedText=#{text_color}\n"
f"chat_adminText=#{text_color}\n"
f"chat_attachActiveTab=#{accent_color}\n"
f"chat_attachAudioBackground=#{accent_color}\n"
f"chat_attachAudioText={tr('f', alpha)}\n"
f"chat_attachCheckBoxBackground=#{accent_color}\n"
f"chat_attachCheckBoxCheck={tr('f', alpha)}\n"
f"chat_attachContactBackground=#{accent_color}\n"
f"chat_attachContactText={tr('f', alpha)}\n"
f"chat_attachEmptyImage=#{text_color}\n"
f"chat_attachFileBackground=#{accent_color}\n"
f"chat_attachFileText={tr('f', alpha)}\n"
f"chat_attachGalleryBackground=#{accent_color}\n"
f"chat_attachGalleryText={tr('f', alpha)}\n"
f"chat_attachIcon={tr('f', alpha)}\n"
f"chat_attachLocationBackground=#{accent_color}\n"
f"chat_attachLocationText={tr('f', alpha)}\n"
f"chat_attachPermissionImage=#{text_color}\n"
f"chat_attachPermissionMark=#{text_color}\n"
f"chat_attachPermissionText=#{text_color}\n"
f"chat_attachPhotoBackground=#00000000\n"
f"chat_attachPollBackground=#{accent_color}\n"
f"chat_attachPollText={tr('f', alpha)}\n"
f"chat_attachUnactiveTab=#{text_color}\n"
f"chat_BlurAlpha=#be000000\n"
f"chat_BlurAlphaSlow=#be000000\n"
f"chat_botButtonText=#{accent_color}\n"
f"chat_botKeyboardButtonBackground={tr('f', alpha)}\n"
f"chat_botKeyboardButtonBackgroundPressed=#{accent_color}\n"
f"chat_botKeyboardButtonText=#{accent_color}\n"
f"chat_botSwitchToInlineText=#{accent_color}\n"
f"chat_editMediaButton=#{accent_color}\n"
f"chat_emojiBottomPanelIcon=#{text_color}\n"
f"chat_emojiPanelBackground={tr('f', alpha)}\n"
f"chat_emojiPanelBackspace=#{text_color}\n"
f"chat_emojiPanelEmptyText=#{text_color}\n"
f"chat_emojiPanelIcon=#{text_color}\n"
f"chat_emojiPanelIconSelected=#{accent_color}\n"
f"chat_emojiPanelNewTrending=#{accent_color}\n"
f"chat_emojiPanelShadowLine=#{accent_color}\n"
f"chat_emojiPanelStickerPackSelector=#{accent_color}\n"
f"chat_emojiPanelStickerPackSelectorLine=#{accent_color}\n"
f"chat_emojiPanelStickerSetName=#{text_color}\n"
f"chat_emojiPanelStickerSetNameHighlight=#{accent_color}\n"
f"chat_emojiPanelStickerSetNameIcon=#{text_color}\n"
f"chat_emojiPanelTrendingDescription=#{text_color}\n"
f"chat_emojiPanelTrendingTitle=#{text_color}\n"
f"chat_emojiSearchBackground={tr('f', alpha)}\n"
f"chat_emojiSearchIcon=#{text_color}\n"
f"chat_fieldOverlayText=#{accent_color}\n"
f"chat_gifSaveHintBackground=#{accent_color}\n"
f"chat_gifSaveHintText={tr('f', alpha)}\n"
f"chat_goDownButton={tr('f', alpha)}\n"
f"chat_goDownButtonCounter={tr('f', alpha)}\n"
f"chat_goDownButtonCounterBackground=#{accent_color}\n"
f"chat_goDownButtonIcon=#{text_color}\n"
f"chat_inAudioCacheSeekbar=#{text_color}\n"
f"chat_inAudioDurationSelectedText=#{text_color}\n"
f"chat_inAudioDurationText=#{text_color}\n"
f"chat_inAudioPerfomerSelectedText=#{text_color}\n"
f"chat_inAudioPerfomerText=#{text_color}\n"
f"chat_inAudioProgress={tr('f', alpha)}\n"
f"chat_inAudioSeekbar=#{text_color}\n"
f"chat_inAudioSeekbarFill=#{accent_color}\n"
f"chat_inAudioSeekbarSelected=#{accent_color}\n"
f"chat_inAudioSelectedProgress=#{accent_color}\n"
f"chat_inAudioTitleText=#{text_color}\n"
f"chat_inBubble={tr('f', alpha)}\n"
f"chat_inBubbleSelected={dsel}\n"
f"chat_inBubbleShadow=#00000000\n"
f"chat_inContactBackground=#{accent_color}\n"
f"chat_inContactIcon={tr('f', alpha)}\n"
f"chat_inContactNameText=#{text_color}\n"
f"chat_inContactPhoneSelectedText=#{text_color}\n"
f"chat_inContactPhoneText=#{text_color}\n"
f"chat_inDownCall=#{text_color}\n"
f"chat_inFileBackground={tr('f', alpha)}\n"
f"chat_inFileBackgroundSelected=#{accent_color}\n"
f"chat_inFileInfoSelectedText=#{text_color}\n"
f"chat_inFileInfoText=#{text_color}\n"
f"chat_inFileNameText=#{text_color}\n"
f"chat_inFileProgress={tr('f', alpha)}\n"
f"chat_inFileProgressSelected=#{accent_color}\n"
f"chat_inForwardedNameText=#{accent_color}\n"
f"chat_inInstant=#{accent_color}\n"
f"chat_inInstantSelected=#{accent_color}\n"
f"chat_inlineResultIcon=#{accent_color}\n"
f"chat_inLoader=#{accent_color}\n"
f"chat_inLoaderPhoto=#{text_color}\n"
f"chat_inLoaderSelected=#{accent_color}\n"
f"chat_inLocationBackground=#{accent_color}\n"
f"chat_inLocationIcon=#{text_color}\n"
f"chat_inMediaIcon=#{text_color}\n"
f"chat_inMediaIconSelected=#{text_color}\n"
f"chat_inMenu=#{text_color}\n"
f"chat_inMenuSelected=#{text_color}\n"
f"chat_inPollCorrectAnswer=#{accent_color}\n"
f"chat_inPollWrongAnswer=#{text_color}\n"
f"chat_inPreviewInstantText=#{text_color}\n"
f"chat_inPreviewLine=#{accent_color}\n"
f"chat_inPsaNameText=#{text_color}\n"
f"chat_inReactionButtonBackground=#{accent_color}\n"
f"chat_inReactionButtonText=#{text_color}\n"
f"chat_inReactionButtonTextSelected=#{text_color}\n"
f"chat_inReplyLine=#{accent_color}\n"
f"chat_inReplyMediaMessageSelectedText=#{text_color}\n"
f"chat_inReplyMediaMessageText=#{text_color}\n"
f"chat_inReplyMessageText=#{text_color}\n"
f"chat_inReplyNameText=#{accent_color}\n"
f"chat_inSentClock=#{text_color}\n"
f"chat_inSentClockSelected=#{text_color}\n"
f"chat_inSiteNameText=#{accent_color}\n"
f"chat_inTextSelectionHighlight={tr('p', '44')}\n"
f"chat_inTimeSelectedText=#{text_color}\n"
f"chat_inTimeText=#{text_color}\n"
f"chat_inVenueInfoSelectedText=#{text_color}\n"
f"chat_inVenueInfoText=#{text_color}\n"
f"chat_inViaBotNameText=#{accent_color}\n"
f"chat_inViews=#{text_color}\n"
f"chat_inViewsSelected=#{text_color}\n"
f"chat_inVoiceSeekbar=#{text_color}\n"
f"chat_inVoiceSeekbarFill=#{accent_color}\n"
f"chat_inVoiceSeekbarSelected=#{accent_color}\n"
f"chat_linkSelectBackground={tr('p', '44')}\n"
f"chat_lockIcon=#{text_color}\n"
f"chat_mediaInfoText=#{text_color}\n"
f"chat_mediaLoaderPhoto=#00000000\n"
f"chat_mediaLoaderPhotoIcon=#{text_color}\n"
f"chat_mediaLoaderPhotoIconSelected=#{text_color}\n"
f"chat_mediaLoaderPhotoSelected=#00000000\n"
f"chat_mediaMenu=#{text_color}\n"
f"chat_mediaProgress={tr('f', alpha)}\n"
f"chat_mediaSentCheck=#{text_color}\n"
f"chat_mediaSentClock=#{text_color}\n"
f"chat_mediaTimeBackground={tr('p', '88')}\n"
f"chat_mediaTimeText={tr('f', alpha)}\n"
f"chat_mediaViews=#{text_color}\n"
f"chat_messageLinkIn=#{accent_color}\n"
f"chat_messageLinkOut=#{accent_color}\n"
f"chat_messagePanelBackground={tr('f', alpha)}\n"
f"chat_messagePanelCancelInlineBot={tr('f', alpha)}\n"
f"chat_messagePanelCursor=#{accent_color}\n"
f"chat_messagePanelHint=#{text_color}\n"
f"chat_messagePanelIcons=#{text_color}\n"
f"chat_messagePanelSend=#{accent_color}\n"
f"chat_messagePanelShadow=#{accent_color}\n"
f"chat_messagePanelText=#{text_color}\n"
f"chat_messagePanelVoiceBackground=#{accent_color}\n"
f"chat_messagePanelVoiceDelete=#{text_color}\n"
f"chat_messagePanelVoiceDuration={tr('f', alpha)}\n"
f"chat_messagePanelVoicePressed=#{accent_color}\n"
f"chat_messageTextIn=#{text_color}\n"
f"chat_messageTextOut=#{text_color}\n"
f"chat_muteIcon=#{text_color}\n"
f"chat_outAdminSelectedText=#{text_color}\n"
f"chat_outAdminText=#{text_color}\n"
f"chat_outAudioCacheSeekbar=#{text_color}\n"
f"chat_outAudioDurationSelectedText=#{text_color}\n"
f"chat_outAudioDurationText=#{text_color}\n"
f"chat_outAudioPerfomerSelectedText=#{text_color}\n"
f"chat_outAudioPerfomerText=#{text_color}\n"
f"chat_outAudioProgress=#{accent_color}\n"
f"chat_outAudioSeekbar=#{accent_color}\n"
f"chat_outAudioSeekbarFill=#{accent_color}\n"
f"chat_outAudioSeekbarSelected=#{accent_color}\n"
f"chat_outAudioSelectedProgress=#{accent_color}\n"
f"chat_outAudioTitleText=#{text_color}\n"
f"chat_outBubble={tr('f', alpha)}\n"
f"noGradient=#{accent_color}\n"
f"noGradient2=#{accent_color}\n"
f"noGradient3=#{accent_color}\n"
f"chat_outBubbleGradientAnimated=#{accent_color}\n"
f"chat_outBubbleGradientSelectedOverlay=#{accent_color}\n"
f"chat_outBubbleSelected={dsel}\n"
f"chat_outBubbleShadow=#00000000\n"
f"chat_outContactBackground={tr('f', alpha)}\n"
f"chat_outContactIcon=#{text_color}\n"
f"chat_outContactNameText=#{text_color}\n"
f"chat_outContactPhoneSelectedText=#{text_color}\n"
f"chat_outContactPhoneText=#{text_color}\n"
f"chat_outFileBackground={tr('f', alpha)}\n"
f"chat_outFileBackgroundSelected=#{accent_color}\n"
f"chat_outFileInfoSelectedText=#{text_color}\n"
f"chat_outFileInfoText=#{text_color}\n"
f"chat_outFileNameText=#{text_color}\n"
f"chat_outFileProgress=#{accent_color}\n"
f"chat_outFileProgressSelected=#{accent_color}\n"
f"chat_outForwardedNameText=#{text_color}\n"
f"chat_outInstant=#{text_color}\n"
f"chat_outInstantSelected=#{text_color}\n"
f"chat_outLinkSelectBackground={tr('p', '44')}\n"
f"chat_outLoader=#{text_color}\n"
f"chat_outLoaderSelected=#{text_color}\n"
f"chat_outLocationIcon=#{text_color}\n"
f"chat_outMediaIcon=#{accent_color}\n"
f"chat_outMediaIconSelected=#{accent_color}\n"
f"chat_outMenu=#{text_color}\n"
f"chat_outMenuSelected=#{text_color}\n"
f"chat_outPollCorrectAnswer=#{accent_color}\n"
f"chat_outPollWrongAnswer=#{text_color}\n"
f"chat_outPreviewInstantText=#{text_color}\n"
f"chat_outPreviewLine=#{accent_color}\n"
f"chat_outPsaNameText=#{text_color}\n"
f"chat_outReactionButtonBackground={tr('p', '88')}\n"
f"chat_outReactionButtonText=#{text_color}\n"
f"chat_outReactionButtonTextSelected=#{text_color}\n"
f"chat_outReplyLine=#{accent_color}\n"
f"chat_outReplyMediaMessageSelectedText=#{text_color}\n"
f"chat_outReplyMediaMessageText=#{text_color}\n"
f"chat_outReplyMessageText=#{text_color}\n"
f"chat_outReplyNameText=#{text_color}\n"
f"chat_outSentCheck=#{text_color}\n"
f"chat_outSentCheckRead=#{text_color}\n"
f"chat_outSentCheckReadSelected=#{text_color}\n"
f"chat_outSentCheckSelected=#{text_color}\n"
f"chat_outSentClock=#{text_color}\n"
f"chat_outSentClockSelected=#{text_color}\n"
f"chat_outSiteNameText=#{text_color}\n"
f"chat_outTextSelectionCursor=#{text_color}\n"
f"chat_outTextSelectionHighlight={tr('p', '44')}\n"
f"chat_outTimeSelectedText=#{text_color}\n"
f"chat_outTimeText=#{text_color}\n"
f"chat_outUpCall=#{text_color}\n"
f"chat_outVenueInfoSelectedText=#{text_color}\n"
f"chat_outVenueInfoText=#{text_color}\n"
f"chat_outViaBotNameText=#{text_color}\n"
f"chat_outViews=#{text_color}\n"
f"chat_outViewsSelected=#{text_color}\n"
f"chat_outVoiceSeekbar=#{accent_color}\n"
f"chat_outVoiceSeekbarFill=#{accent_color}\n"
f"chat_outVoiceSeekbarSelected=#{accent_color}\n"
f"chat_previewDurationText={tr('f', alpha)}\n"
f"chat_previewGameText={tr('f', alpha)}\n"
f"chat_recordedVoiceBackground=#{accent_color}\n"
f"chat_recordedVoiceDarkerBackground=#{accent_color}\n"
f"chat_recordedVoiceDot=#{text_color}\n"
f"chat_recordedVoicePlayPause={tr('f', alpha)}\n"
f"chat_recordedVoiceProgress=#{accent_color}\n"
f"chat_recordedVoiceProgressInner={tr('f', alpha)}\n"
f"chat_recordTime=#{text_color}\n"
f"chat_recordVoiceCancel=#{text_color}\n"
f"chat_replyPanelClose=#{text_color}\n"
f"chat_replyPanelIcons=#{accent_color}\n"
f"chat_replyPanelLine=#{accent_color}\n"
f"chat_replyPanelName=#{accent_color}\n"
f"chat_searchPanelIcons=#{text_color}\n"
f"chat_searchPanelText=#{text_color}\n"
f"chat_secretChatStatusText=#{text_color}\n"
f"chat_secretTimeText=#{text_color}\n"
f"chat_selectedBackground={tr('p', '55')}\n"
f"chat_sentError=#{text_color}\n"
f"chat_sentErrorIcon={tr('f', alpha)}\n"
f"chat_serviceBackground={tr('f', '88')}\n"
f"chat_serviceBackgroundSelected=#{accent_color}\n"
f"chat_serviceBackgroundSelector=#{accent_color}\n"
f"chat_serviceIcon=#{text_color}\n"
f"chat_serviceLink=#{accent_color}\n"
f"chat_serviceText=#{text_color}\n"
f"chat_status=#{accent_color}\n"
f"chat_stickerNameText={tr('f', alpha)}\n"
f"chat_stickerReplyLine=#{accent_color}\n"
f"chat_stickerReplyMessageText=#{text_color}\n"
f"chat_stickerReplyNameText=#{accent_color}\n"
f"chat_stickerViaBotNameText={tr('f', alpha)}\n"
f"chat_stickersHintPanel={tr('f', alpha)}\n"
f"chat_textSelectBackground={tr('p', '55')}\n"
f"chat_TextSelectionCursor=#{text_color}\n"
f"chat_topPanelBackground={tr('f', alpha)}\n"
f"chat_topPanelClose=#{text_color}\n"
f"chat_topPanelLine=#{accent_color}\n"
f"chat_topPanelMessage=#{text_color}\n"
f"chat_topPanelTitle=#{accent_color}\n"
f"chat_unreadMessagesStartArrowIcon=#{text_color}\n"
f"chat_unreadMessagesStartBackground=#{accent_color}\n"
f"chat_unreadMessagesStartText={tr('f', alpha)}\n"
f"checkbox=#{accent_color}\n"
f"checkboxCheck={tr('f', alpha)}\n"
f"checkboxDisabled=#{text_color}\n"
f"checkboxSquareBackground=#{accent_color}\n"
f"checkboxSquareCheck={tr('f', alpha)}\n"
f"checkboxSquareDisabled=#{text_color}\n"
f"checkboxSquareUnchecked=#{text_color}\n"
f"color_blue=#{accent_color}\n"
f"color_green=#{accent_color}\n"
f"color_lightblue=#{accent_color}\n"
f"color_lightgreen=#{accent_color}\n"
f"color_orange=#{accent_color}\n"
f"color_purple=#{accent_color}\n"
f"color_red=#{text_color}\n"
f"color_yellow=#{accent_color}\n"
f"contacts_inviteBackground=#{accent_color}\n"
f"contacts_inviteText={tr('f', alpha)}\n"
f"contextProgressInner1=#{accent_color}\n"
f"contextProgressInner2=#{accent_color}\n"
f"contextProgressInner3=#{accent_color}\n"
f"contextProgressInner4=#{accent_color}\n"
f"contextProgressOuter1=#{accent_color}\n"
f"contextProgressOuter2=#{accent_color}\n"
f"contextProgressOuter3=#{accent_color}\n"
f"contextProgressOuter4=#{accent_color}\n"
f"dialogBackground={tr('f', alpha)}\n"
f"dialogBackgroundGray={tr('f', alpha)}\n"
f"dialogButton=#{accent_color}\n"
f"dialogButtonSelector=#{accent_color}\n"
f"dialogCardShadow=#00000000\n"
f"dialogCameraIcon={tr('f', alpha)}\n"
f"dialogCheckboxSquareBackground=#{accent_color}\n"
f"dialogCheckboxSquareCheck={tr('f', alpha)}\n"
f"dialogCheckboxSquareDisabled=#{text_color}\n"
f"dialogCheckboxSquareUnchecked=#{text_color}\n"
f"dialogEmptyImage=#{text_color}\n"
f"dialogEmptyText=#{text_color}\n"
f"dialogFloatingButton=#{accent_color}\n"
f"dialogFloatingButtonPressed=#{accent_color}\n"
f"dialogFloatingIcon={tr('f', alpha)}\n"
f"dialogGiftsBackground=#{accent_color}\n"
f"dialogGiftsTabText=#{text_color}\n"
f"dialogGrayLine=#{text_color}\n"
f"dialogIcon=#{text_color}\n"
f"dialogInputField=#{text_color}\n"
f"dialogInputFieldActivated=#{accent_color}\n"
f"dialogLineProgress=#{accent_color}\n"
f"dialogLineProgressBackground=#{accent_color}\n"
f"dialogLinkSelection={tr('p', '44')}\n"
f"dialogRadioBackground=#{text_color}\n"
f"dialogRadioBackgroundChecked=#{accent_color}\n"
f"dialogReactionMentionBackground=#{accent_color}\n"
f"dialogRoundCheckBox=#{accent_color}\n"
f"dialogRoundCheckBoxCheck={tr('f', alpha)}\n"
f"dialogScrollGlow={tr('f', alpha)}\n"
f"dialogSearchBackground={tr('f', alpha)}\n"
f"dialogSearchHint=#{text_color}\n"
f"dialogSearchIcon=#{text_color}\n"
f"dialogSearchText=#{text_color}\n"
f"dialogShadowLine=#{text_color}\n"
f"dialogSwipeRemove=#{text_color}\n"
f"dialogTextBlack=#{text_color}\n"
f"dialogTextBlue=#{accent_color}\n"
f"dialogTextBlue2=#{accent_color}\n"
f"dialogTextBlue4=#{accent_color}\n"
f"dialogTextGray=#{accent_color}\n"
f"dialogTextGray2=#{text_color}\n"
f"dialogTextGray3=#{text_color}\n"
f"dialogTextGray4=#{text_color}\n"
f"dialogTextHint=#{text_color}\n"
f"dialogTextLink=#{accent_color}\n"
f"dialogTopBackground=#{accent_color}\n"
f"dialog_inlineProgress=#{accent_color}\n"
f"dialog_inlineProgressBackground=#{text_color}\n"
f"dialog_liveLocationProgress=#{accent_color}\n"
f"divider={tr('f', '66')}\n"
f"emptyListPlaceholder=#{text_color}\n"
f"fastScrollActive=#{accent_color}\n"
f"fastScrollInactive=#{text_color}\n"
f"fastScrollText={tr('f', alpha)}\n"
f"featuredStickers_addButton=#{accent_color}\n"
f"featuredStickers_addButtonPressed=#{accent_color}\n"
f"featuredStickers_addedIcon=#{accent_color}\n"
f"featuredStickers_buttonProgress=#{accent_color}\n"
f"featuredStickers_buttonText={tr('f', alpha)}\n"
f"featuredStickers_removeButtonText=#{text_color}\n"
f"featuredStickers_unread=#{accent_color}\n"
f"files_folderIcon=#{text_color}\n"
f"files_folderIconBackground=#{accent_color}\n"
f"files_iconText=#{text_color}\n"
f"fill_RedNormal=#{text_color}\n"
f"fill_RedDark=#{text_color}\n"
f"gift_ribbon=#{accent_color}\n"
f"gift_ribbon_soldout=#{accent_color}\n"
f"graySection=#{text_color}\n"
f"groupcreate_cursor=#{accent_color}\n"
f"groupcreate_hintText=#{text_color}\n"
f"groupcreate_sectionShadow=#{accent_color}\n"
f"groupcreate_sectionText=#{text_color}\n"
f"groupcreate_spanBackground={tr('f', alpha)}\n"
f"groupcreate_spanDelete=#{accent_color}\n"
f"groupcreate_spanText=#{text_color}\n"
f"inappPlayerBackground={tr('f', alpha)}\n"
f"inappPlayerClose=#{text_color}\n"
f"inappPlayerPerformer=#{text_color}\n"
f"inappPlayerPlayPause=#{accent_color}\n"
f"inappPlayerTitle=#{text_color}\n"
f"iv_ab_progress=#{accent_color}\n"
f"iv_background=#00000000\n"
f"iv_backgroundGray=#00000000\n"
f"iv_navigationBackground=#00000000\n"
f"key_chat_messagePanelVoiceLock=#{text_color}\n"
f"key_chat_messagePanelVoiceLockBackground=#{accent_color}\n"
f"key_chat_messagePanelVoiceLockShadow=#00000000\n"
f"key_graySectionText=#{text_color}\n"
f"key_player_progressCachedBackground=#{text_color}\n"
f"key_sheet_other=#{text_color}\n"
f"key_sheet_scrollUp=#{accent_color}\n"
f"listSelectorSDK21={tr('f', '88')}\n"
f"location_actionActiveIcon=#{accent_color}\n"
f"location_actionBackground=#{accent_color}\n"
f"location_actionIcon=#{text_color}\n"
f"location_actionPressedBackground=#{accent_color}\n"
f"location_liveLocationProgress=#{accent_color}\n"
f"location_placeLocationBackground=#{accent_color}\n"
f"location_sendLiveLocationBackground=#{accent_color}\n"
f"location_sendLiveLocationIcon={tr('f', alpha)}\n"
f"location_sendLiveLocationText={tr('f', alpha)}\n"
f"location_sendLocationBackground=#{accent_color}\n"
f"location_sendLocationIcon={tr('f', alpha)}\n"
f"location_sendLocationText={tr('f', alpha)}\n"
f"login_progressInner=#{accent_color}\n"
f"login_progressOuter=#{accent_color}\n"
f"passport_authorizeBackground=#{accent_color}\n"
f"passport_authorizeBackgroundSelected=#{accent_color}\n"
f"passport_authorizeText={tr('f', alpha)}\n"
f"picker_badge=#{accent_color}\n"
f"picker_badgeText={tr('f', alpha)}\n"
f"picker_disabledButton=#{text_color}\n"
f"picker_enabledButton=#{accent_color}\n"
f"player_actionBarItems=#{text_color}\n"
f"player_actionBarSelector=#{accent_color}\n"
f"player_actionBarSubtitle=#{text_color}\n"
f"player_actionBarTitle=#{text_color}\n"
f"player_background={tr('f', alpha)}\n"
f"player_button=#{text_color}\n"
f"player_buttonActive=#{accent_color}\n"
f"player_progress=#{accent_color}\n"
f"player_progressBackground={tr('f', alpha)}\n"
f"player_time=#{text_color}\n"
f"premiumCoinGradient1=#{accent_color}\n"
f"premiumCoinGradient2=#{accent_color}\n"
f"premiumGradient0=#{accent_color}\n"
f"premiumGradient1=#{accent_color}\n"
f"premiumGradient2=#{accent_color}\n"
f"premiumGradient3=#{accent_color}\n"
f"premiumGradient4=#{accent_color}\n"
f"premiumGradientBackground1=#{accent_color}\n"
f"premiumGradientBackground2=#{accent_color}\n"
f"premiumGradientBackground3=#{accent_color}\n"
f"premiumGradientBackground4=#{accent_color}\n"
f"premiumGradientBackgroundOverlay=#{accent_color}\n"
f"premiumGradientBottomSheet1=#{accent_color}\n"
f"premiumGradientBottomSheet2=#{accent_color}\n"
f"premiumGradientBottomSheet3=#{accent_color}\n"
f"premiumStarGradient1=#{accent_color}\n"
f"premiumStarGradient2=#{accent_color}\n"
f"premiumStartSmallStarsColor=#{accent_color}\n"
f"premiumStartSmallStarsColor2=#{accent_color}\n"
f"profile_actionBackground=#{accent_color}\n"
f"profile_actionIcon={tr('f', alpha)}\n"
f"profile_actionPressedBackground=#{accent_color}\n"
f"profile_creatorIcon=#{accent_color}\n"
f"profile_status=#{accent_color}\n"
f"profile_tabSelectedLine=#{accent_color}\n"
f"profile_tabSelectedText=#{accent_color}\n"
f"profile_tabSelector=#{accent_color}\n"
f"profile_tabText=#{accent_color}\n"
f"profile_title=#{text_color}\n"
f"profile_verifiedBackground=#{accent_color}\n"
f"profile_verifiedCheck={tr('f', alpha)}\n"
f"progressCircle=#{accent_color}\n"
f"radioBackground=#{text_color}\n"
f"radioBackgroundChecked=#{accent_color}\n"
f"reactionStarSelector=#{accent_color}\n"
f"returnToCallBackground=#{accent_color}\n"
f"returnToCallMutedBackground=#{accent_color}\n"
f"returnToCallText={tr('f', alpha)}\n"
f"sessions_devicesImage=#{text_color}\n"
f"sharedMedia_linkPlaceholder={tr('f', alpha)}\n"
f"sharedMedia_linkPlaceholderText=#{text_color}\n"
f"sharedMedia_photoPlaceholder={tr('f', alpha)}\n"
f"sharedMedia_startStopLoadIcon=#{accent_color}\n"
f"statisticChartActiveLine=#{accent_color}\n"
f"statisticChartActivePickerChart=#{accent_color}\n"
f"statisticChartBackZoomColor=#{accent_color}\n"
f"statisticChartChevronColor=#{accent_color}\n"
f"statisticChartHintLine=#{accent_color}\n"
f"statisticChartInactivePickerChart=#{accent_color}\n"
f"statisticChartLineEmpty=#{accent_color}\n"
f"statisticChartLine_blue=#{accent_color}\n"
f"statisticChartLine_cyan=#{accent_color}\n"
f"statisticChartLine_golden=#{accent_color}\n"
f"statisticChartLine_green=#{accent_color}\n"
f"statisticChartLine_indigo=#{accent_color}\n"
f"statisticChartLine_lightblue=#{accent_color}\n"
f"statisticChartLine_lightgreen=#{accent_color}\n"
f"statisticChartLine_orange=#{accent_color}\n"
f"statisticChartLine_purple=#{accent_color}\n"
f"statisticChartLine_red=#{accent_color}\n"
f"statisticChartRipple=#{accent_color}\n"
f"statisticChartSignature=#{accent_color}\n"
f"statisticChartSignatureAlpha=#{accent_color}\n"
f"stickers_menu=#{text_color}\n"
f"stickers_menuSelector=#{text_color}\n"
f"stories_circle_closeFriends1=#{accent_color}\n"
f"stories_circle_closeFriends2=#{accent_color}\n"
f"stories_circle_dialog1=#{accent_color}\n"
f"stories_circle_dialog2=#{accent_color}\n"
f"stories_circle1=#{accent_color}\n"
f"stories_circle2=#{accent_color}\n"
f"switch2Track=#{text_color}\n"
f"switch2TrackChecked=#{accent_color}\n"
f"switchTrack=#{text_color}\n"
f"switchTrackBlue=#{accent_color}\n"
f"switchTrackBlueChecked=#{accent_color}\n"
f"switchTrackBlueSelector=#{accent_color}\n"
f"switchTrackBlueSelectorChecked=#{accent_color}\n"
f"switchTrackBlueThumb=#{accent_color}\n"
f"switchTrackBlueThumbChecked=#{accent_color}\n"
f"switchTrackChecked=#{accent_color}\n"
f"table_background=#{accent_color}\n"
f"table_border=#{text_color}\n"
f"text_RedBold=#{text_color}\n"
f"text_RedRegular=#{text_color}\n"
f"topics_unreadCounter=#{accent_color}\n"
f"topics_unreadCounterMuted=#{accent_color}\n"
f"undo_background={tr('f', '88')}\n"
f"undo_cancelColor=#{text_color}\n"
f"undo_infoColor=#{text_color}\n"
f"voipgroup_actionBar=#{accent_color}\n"
f"voipgroup_actionBarItems=#{text_color}\n"
f"voipgroup_actionBarItemsSelector=#{accent_color}\n"
f"voipgroup_actionBarUnscrolled=#{accent_color}\n"
f"voipgroup_checkMenu=#{accent_color}\n"
f"voipgroup_connectingProgress=#{accent_color}\n"
f"voipgroup_dialogBackground=#{accent_color}\n"
f"voipgroup_disabledButton=#{accent_color}\n"
f"voipgroup_disabledButtonActive=#{accent_color}\n"
f"voipgroup_disabledButtonActiveScrolled=#{accent_color}\n"
f"voipgroup_inviteMembersBackground=#{accent_color}\n"
f"voipgroup_lastSeenText=#{text_color}\n"
f"voipgroup_lastSeenTextUnscrolled=#{text_color}\n"
f"voipgroup_leaveButton=#{accent_color}\n"
f"voipgroup_leaveButtonScrolled=#{accent_color}\n"
f"voipgroup_leaveCallMenu=#{accent_color}\n"
f"voipgroup_listeningText=#{text_color}\n"
f"voipgroup_listSelector=#{accent_color}\n"
f"voipgroup_listViewBackground=#{accent_color}\n"
f"voipgroup_listViewBackgroundUnscrolled=#{accent_color}\n"
f"voipgroup_muteButton=#{accent_color}\n"
f"voipgroup_muteButton2=#{accent_color}\n"
f"voipgroup_muteButton3=#{accent_color}\n"
f"voipgroup_mutedByAdminGradient=#{accent_color}\n"
f"voipgroup_mutedByAdminGradient2=#{accent_color}\n"
f"voipgroup_mutedByAdminGradient3=#{accent_color}\n"
f"voipgroup_mutedByAdminIcon=#{text_color}\n"
f"voipgroup_mutedByAdminMuteButton=#{accent_color}\n"
f"voipgroup_mutedByAdminMuteButtonDisabled=#{accent_color}\n"
f"voipgroup_mutedIcon=#{text_color}\n"
f"voipgroup_mutedIconUnscrolled=#{text_color}\n"
f"voipgroup_nameText=#{text_color}\n"
f"voipgroup_overlayAlertGradientMuted=#{accent_color}\n"
f"voipgroup_overlayAlertGradientMuted2=#{accent_color}\n"
f"voipgroup_overlayAlertGradientUnmuted=#{accent_color}\n"
f"voipgroup_overlayAlertGradientUnmuted2=#{accent_color}\n"
f"voipgroup_overlayAlertMutedByAdmin=#{accent_color}\n"
f"voipgroup_overlayAlertMutedByAdmin2=#{accent_color}\n"
f"voipgroup_overlayBlue1=#{accent_color}\n"
f"voipgroup_overlayBlue2=#{accent_color}\n"
f"voipgroup_overlayGreen1=#{accent_color}\n"
f"voipgroup_overlayGreen2=#{accent_color}\n"
f"voipgroup_rtmpButton=#{accent_color}\n"
f"voipgroup_scrollUp=#{accent_color}\n"
f"voipgroup_searchBackground=#{accent_color}\n"
f"voipgroup_searchPlaceholder=#{text_color}\n"
f"voipgroup_searchText=#{text_color}\n"
f"voipgroup_soundButton=#{accent_color}\n"
f"voipgroup_soundButton2=#{accent_color}\n"
f"voipgroup_soundButtonActive=#{accent_color}\n"
f"voipgroup_soundButtonActive2=#{accent_color}\n"
f"voipgroup_soundButtonActive2Scrolled=#{accent_color}\n"
f"voipgroup_soundButtonActiveScrolled=#{accent_color}\n"
f"voipgroup_speakingText=#{text_color}\n"
f"voipgroup_topPanelBlue1=#{accent_color}\n"
f"voipgroup_topPanelBlue2=#{accent_color}\n"
f"voipgroup_topPanelGray=#{accent_color}\n"
f"voipgroup_topPanelGreen1=#{accent_color}\n"
f"voipgroup_topPanelGreen2=#{accent_color}\n"
f"voipgroup_unmuteButton=#{accent_color}\n"
f"voipgroup_unmuteButton2=#{accent_color}\n"
f"voipgroup_windowBackgroundWhiteInputField=#{accent_color}\n"
f"voipgroup_windowBackgroundWhiteInputFieldActivated=#{accent_color}\n"
f"windowBackgroundChecked=#{accent_color}\n"
f"windowBackgroundCheckText={tr('f', alpha)}\n"
f"windowBackgroundGray={tr('f', alpha)}\n"
f"windowBackgroundGrayShadow=#00000000\n"
f"windowBackgroundUnchecked=#{text_color}\n"
f"windowBackgroundWhite={tr('f', alpha)}\n"
f"windowBackgroundWhiteBlackText=#{text_color}\n"
f"windowBackgroundWhiteBlueButton=#{accent_color}\n"
f"windowBackgroundWhiteBlueHeader=#{accent_color}\n"
f"windowBackgroundWhiteBlueIcon=#{accent_color}\n"
f"windowBackgroundWhiteBlueText=#{accent_color}\n"
f"windowBackgroundWhiteBlueText2=#{accent_color}\n"
f"windowBackgroundWhiteBlueText3=#{accent_color}\n"
f"windowBackgroundWhiteBlueText4=#{accent_color}\n"
f"windowBackgroundWhiteBlueText5=#{accent_color}\n"
f"windowBackgroundWhiteBlueText6=#{accent_color}\n"
f"windowBackgroundWhiteBlueText7=#{accent_color}\n"
f"windowBackgroundWhiteGrayIcon=#{text_color}\n"
f"windowBackgroundWhiteGrayText=#{text_color}\n"
f"windowBackgroundWhiteGrayText2=#{text_color}\n"
f"windowBackgroundWhiteGrayText3=#{text_color}\n"
f"windowBackgroundWhiteGrayText4=#{text_color}\n"
f"windowBackgroundWhiteGrayText5=#{text_color}\n"
f"windowBackgroundWhiteGrayText6=#{text_color}\n"
f"windowBackgroundWhiteGrayText7=#{text_color}\n"
f"windowBackgroundWhiteGrayText8=#{text_color}\n"
f"windowBackgroundWhiteGreenText=#{accent_color}\n"
f"windowBackgroundWhiteGreenText2=#{accent_color}\n"
f"windowBackgroundWhiteHintText=#{text_color}\n"
f"windowBackgroundWhiteInputField=#{text_color}\n"
f"windowBackgroundWhiteInputFieldActivated=#{accent_color}\n"
f"windowBackgroundWhiteLinkSelection={tr('p', '44')}\n"
f"windowBackgroundWhiteLinkText=#{accent_color}\n"
f"windowBackgroundWhiteValueText=#{accent_color}\n"
f"chat_wallpaper=#00000000\n"
f"chat_wallpaper_gradient_to=#00000000\n"
f"key_chat_wallpaper_gradient_to2=#00000000\n"
f"key_chat_wallpaper_gradient_to3=#00000000\n"
f"dialogTextRed=#{text_color}\n"
f"dialogTextRed2=#{text_color}\n"
f"dialogTextBlue3=#{accent_color}\n"
f"dialogInputFieldText=#{text_color}\n"
f"dialogBadgeBackground=#{accent_color}\n"
f"dialogBadgeText={tr('f', alpha)}\n"
f"windowBackgroundWhiteRadius={tr('f', alpha)}\n"
f"windowBackgroundWhiteRedText=#{text_color}\n"
f"windowBackgroundWhiteRedText2=#{text_color}\n"
f"windowBackgroundWhiteRedText3=#{text_color}\n"
f"windowBackgroundWhiteRedText4=#{text_color}\n"
f"windowBackgroundWhiteRedText5=#{text_color}\n"
f"windowBackgroundWhiteRedText6=#{text_color}\n"
f"windowBackgroundWhiteGrayLine=#{text_color}\n"
f"windowBackgroundGrayLine=#{text_color}\n"
f"profile_adminIcon=#{accent_color}\n"
f"switchThumb=#{text_color}\n"
f"switchThumbChecked=#{accent_color}\n"
)
def process_photo(self, photo_bytes: bytes, alpha_hex: str = "ff") -> bytes:
img = Image.open(io.BytesIO(photo_bytes))
bg, text, accent = self.extract_colors(img)
theme = self.build_theme(bg, text, accent, alpha_hex)
wallpaper = self.theme_wallpaper(img)
return theme.encode("utf-8") + b"\n\nWPS\n" + wallpaper + b"\nWPE\n"
def theme_wallpaper(self, img: Image.Image) -> bytes:
wall_img = img.copy().convert("RGB")
if max(wall_img.size) > 1920:
scale = 1920 / max(wall_img.size)
wall_img = wall_img.resize(
(int(wall_img.size[0] * scale), int(wall_img.size[1] * scale)),
Image.LANCZOS,
)
buf = io.BytesIO()
wall_img.save(buf, format="JPEG", quality=100, optimize=True)
return buf.getvalue()