Skip to content

Commit

Permalink
Added map pics for the new maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Kataiser committed Jul 13, 2023
1 parent c82cc78 commit a477888
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 33 deletions.
48 changes: 30 additions & 18 deletions TF2 Rich Presence/generate_map_pics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ def main():
map_datas = [('background01', '/wiki/Background01'), ('devtest', '/wiki/Devtest')]
excluded = ('cp_granary', 'arena_nucleus', 'arena_sawmill', 'arena_badlands', 'koth_badlands', 'tr_dustbowl', 'ctf_thundermountain', 'ctf_well', 'arena_well')
overrides = {'mvm_coaltown': '/wiki/File:Coal_Town_base.png', 'mvm_decoy': '/wiki/File:Decoy_left_lane.png', 'mvm_mannworks': '/wiki/File:Mannworks_left_lane.jpg'}
local_images = ('koth_sharkbay', 'koth_rotunda', 'pl_phoenix', 'pl_cashworks', 'pl_venice', 'cp_reckoner', 'cp_sulfur', 'cp_hardwood_final', 'ctf_pelican_peak', 'pd_selbyen',
'vsh_tinyrock', 'vsh_distillery', 'vsh_skirmish', 'vsh_nucleus')

for local_image in local_images:
print(local_image, end='')

with open(f'local_map_pics\\{local_image}.png', 'rb') as local_image_file:
process_and_save_image(local_image_file.read(), local_image)
print()

list_page_r = requests.get('https://wiki.teamfortress.com/wiki/List_of_maps')
list_page = BeautifulSoup(list_page_r.text, 'lxml')
Expand Down Expand Up @@ -67,24 +76,7 @@ def main():
image_url = f"https://wiki.teamfortress.com{a2.get('href')}"
print(image_url, end='')
image_dl = requests.get(image_url).content
image_loaded = Image.open(io.BytesIO(image_dl)).convert('RGB')
print(f" {len(image_dl)} b {image_loaded.size}", end='')
crop_left = (image_loaded.size[0] / 2) - (image_loaded.size[1] / 2)
crop_right = (image_loaded.size[0] / 2) + (image_loaded.size[1] / 2)
image_cropped = image_loaded.crop((crop_left, 0, crop_right, (image_loaded.size[1])))
color_mean = sum(ImageStat.Stat(image_cropped).mean)

if color_mean < 300:
brighten = 1 + ((300 - color_mean) / 300)
brightener = ImageEnhance.Brightness(image_cropped)
image_cropped = brightener.enhance(brighten)
print(f" {int(color_mean)}", end='')

image_scaled_gui = image_cropped.resize((240, 240), resample=Image.LANCZOS)
image_scaled_discord = image_cropped.resize((512, 512), resample=Image.LANCZOS)
image_scaled_gui.save(f'gui_images\\fg_maps\\{map_file}.webp', lossless=False, quality=85, method=6)
image_scaled_discord.save(f'map_pics_discord\\z_{map_file}.jpg', quality=95, optimize=True, progressive=True, subsampling=0)

process_and_save_image(image_dl, map_file)
break

break
Expand All @@ -93,5 +85,25 @@ def main():
raise SystemError


def process_and_save_image(image_data: bytes, map_file: str):
image_loaded = Image.open(io.BytesIO(image_data)).convert('RGB')
print(f" {len(image_data)} b {image_loaded.size}", end='')
crop_left = (image_loaded.size[0] / 2) - (image_loaded.size[1] / 2)
crop_right = (image_loaded.size[0] / 2) + (image_loaded.size[1] / 2)
image_cropped = image_loaded.crop((crop_left, 0, crop_right, (image_loaded.size[1])))
color_mean = sum(ImageStat.Stat(image_cropped).mean)

if color_mean < 300:
brighten = 1 + ((300 - color_mean) / 300)
brightener = ImageEnhance.Brightness(image_cropped)
image_cropped = brightener.enhance(brighten)
print(f" {int(color_mean)}", end='')

image_scaled_gui = image_cropped.resize((240, 240), resample=Image.LANCZOS)
image_scaled_discord = image_cropped.resize((512, 512), resample=Image.LANCZOS)
image_scaled_gui.save(f'gui_images\\fg_maps\\{map_file}.webp', lossless=False, quality=85, method=6)
image_scaled_discord.save(f'map_pics_discord\\z_{map_file}.jpg', quality=95, optimize=True, progressive=True, subsampling=0)


if __name__ == '__main__':
main()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 16 additions & 15 deletions TF2 Rich Presence/webp_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@


def main():
path = "gui_images\\" + input("Image or dir path: ")
lossless = input("Lossless (y/n): ").lower()
quality = int(input("Quality (0-100): ")) # see the PIL docs for webp saving
while True:
path = "gui_images\\" + input("Image or dir path: ")
lossless = input("Lossless (y/n): ").lower()
quality = int(input("Quality (0-100): ")) # see the PIL docs for webp saving

if lossless not in ('y', 'n') or not (0 <= quality <= 100):
raise SystemError("nah b")
if lossless not in ('y', 'n') or not (0 <= quality <= 100):
raise SystemError("nah b")

if os.path.isdir(path):
for file_name in os.listdir(path):
file_path = os.path.join(path, file_name)
path_out = os.path.splitext(file_path)[0] + '.webp'
Image.open(file_path).convert('RGBA').save(path_out, lossless=lossless == 'y', quality=quality, method=6)
print(f"{file_path} -> {path_out}")
else:
path_out = os.path.splitext(path)[0] + '.webp'
Image.open(path).convert('RGBA').save(path_out, lossless=lossless == 'y', quality=quality, method=6)
print(f"{path} -> {path_out}")
if os.path.isdir(path):
for file_name in os.listdir(path):
file_path = os.path.join(path, file_name)
path_out = os.path.splitext(file_path)[0] + '.webp'
Image.open(file_path).convert('RGBA').save(path_out, lossless=lossless == 'y', quality=quality, method=6)
print(f"{file_path} -> {path_out}")
else:
path_out = os.path.splitext(path)[0] + '.webp'
Image.open(path).convert('RGBA').save(path_out, lossless=lossless == 'y', quality=quality, method=6)
print(f"{path} -> {path_out}")


if __name__ == '__main__':
Expand Down

0 comments on commit a477888

Please sign in to comment.