Reload Uninstalled image when installed image reloaded
This commit is contained in:
parent
c3ee315e02
commit
9b1c068a07
|
@ -61,6 +61,7 @@ def download_image(game, force=False):
|
||||||
else:
|
else:
|
||||||
json_data = json.load(open(f"{image_dir}/{game.app_name}/image.json", "r"))
|
json_data = json.load(open(f"{image_dir}/{game.app_name}/image.json", "r"))
|
||||||
# Download
|
# Download
|
||||||
|
download = False
|
||||||
for image in game.metadata["keyImages"]:
|
for image in game.metadata["keyImages"]:
|
||||||
if image["type"] == "DieselGameBoxTall" or image["type"] == "DieselGameBoxLogo" or image["type"] == "Thumbnail":
|
if image["type"] == "DieselGameBoxTall" or image["type"] == "DieselGameBoxLogo" or image["type"] == "Thumbnail":
|
||||||
if image["type"] not in json_data.keys():
|
if image["type"] not in json_data.keys():
|
||||||
|
@ -79,51 +80,57 @@ def download_image(game, force=False):
|
||||||
img = Image.open(f"{image_dir}/{game.app_name}/{image['type']}.png")
|
img = Image.open(f"{image_dir}/{game.app_name}/{image['type']}.png")
|
||||||
img = img.resize((200, int(200 * 4 / 3)))
|
img = img.resize((200, int(200 * 4 / 3)))
|
||||||
img.save(f"{image_dir}/{game.app_name}/{image['type']}.png")
|
img.save(f"{image_dir}/{game.app_name}/{image['type']}.png")
|
||||||
|
download = True
|
||||||
except UnidentifiedImageError as e:
|
except UnidentifiedImageError as e:
|
||||||
logger.warning(e)
|
logger.warning(e)
|
||||||
|
|
||||||
# scale and grey
|
# scale and grey
|
||||||
if not os.path.exists(os.path.join(image_dir, game.app_name + '/UninstalledArt.png')):
|
uninstalled_image = os.path.join(image_dir, game.app_name + '/UninstalledArt.png')
|
||||||
|
if download and os.path.exists(uninstalled_image):
|
||||||
|
os.remove(uninstalled_image)
|
||||||
|
elif os.path.exists(uninstalled_image):
|
||||||
|
return
|
||||||
|
|
||||||
if os.path.exists(os.path.join(image_dir, f"{game.app_name}/DieselGameBoxTall.png")):
|
if os.path.exists(os.path.join(image_dir, f"{game.app_name}/DieselGameBoxTall.png")):
|
||||||
# finalArt = Image.open(f'{image_dir}/' + game.app_name + '/DieselGameBoxTall.png')
|
# finalArt = Image.open(f'{image_dir}/' + game.app_name + '/DieselGameBoxTall.png')
|
||||||
# finalArt.save(f'{image_dir}/{game.app_name}/FinalArt.png')
|
# finalArt.save(f'{image_dir}/{game.app_name}/FinalArt.png')
|
||||||
# And same with the grayscale one
|
# And same with the grayscale one
|
||||||
try:
|
try:
|
||||||
bg = Image.open(os.path.join(image_dir, f"{game.app_name}/DieselGameBoxTall.png"))
|
bg = Image.open(os.path.join(image_dir, f"{game.app_name}/DieselGameBoxTall.png"))
|
||||||
except UnidentifiedImageError:
|
except UnidentifiedImageError:
|
||||||
logger.warning("Reload image for " + game.app_title)
|
logger.warning("Reload image for " + game.app_title)
|
||||||
# avoid endless recursion
|
# avoid endless recursion
|
||||||
if not force:
|
if not force:
|
||||||
download_image(game, True)
|
download_image(game, True)
|
||||||
return
|
return
|
||||||
uninstalledArt = bg.convert('L')
|
uninstalledArt = bg.convert('L')
|
||||||
uninstalledArt = uninstalledArt.resize((200, int(200 * 4 / 3)))
|
uninstalledArt = uninstalledArt.resize((200, int(200 * 4 / 3)))
|
||||||
uninstalledArt.save(f'{image_dir}/{game.app_name}/UninstalledArt.png')
|
uninstalledArt.save(f'{image_dir}/{game.app_name}/UninstalledArt.png')
|
||||||
elif os.path.isfile(f"{image_dir}/{game.app_name}/DieselGameBoxLogo.png"):
|
|
||||||
bg: Image.Image = Image.open(f"{image_dir}/{game.app_name}/DieselGameBoxLogo.png")
|
elif os.path.isfile(f"{image_dir}/{game.app_name}/DieselGameBoxLogo.png"):
|
||||||
bg = bg.resize((int(bg.size[1] * 3 / 4), bg.size[1]))
|
bg: Image.Image = Image.open(f"{image_dir}/{game.app_name}/DieselGameBoxLogo.png")
|
||||||
logo = Image.open(f'{image_dir}/{game.app_name}/DieselGameBoxLogo.png').convert('RGBA')
|
bg = bg.resize((int(bg.size[1] * 3 / 4), bg.size[1]))
|
||||||
wpercent = ((bg.size[0] * (3 / 4)) / float(logo.size[0]))
|
logo = Image.open(f'{image_dir}/{game.app_name}/DieselGameBoxLogo.png').convert('RGBA')
|
||||||
hsize = int((float(logo.size[1]) * float(wpercent)))
|
wpercent = ((bg.size[0] * (3 / 4)) / float(logo.size[0]))
|
||||||
logo = logo.resize((int(bg.size[0] * (3 / 4)), hsize), Image.ANTIALIAS)
|
hsize = int((float(logo.size[1]) * float(wpercent)))
|
||||||
# Calculate where the image has to be placed
|
logo = logo.resize((int(bg.size[0] * (3 / 4)), hsize), Image.ANTIALIAS)
|
||||||
pasteX = int((bg.size[0] - logo.size[0]) / 2)
|
# Calculate where the image has to be placed
|
||||||
pasteY = int((bg.size[1] - logo.size[1]) / 2)
|
pasteX = int((bg.size[0] - logo.size[0]) / 2)
|
||||||
# And finally copy the background and paste in the image
|
pasteY = int((bg.size[1] - logo.size[1]) / 2)
|
||||||
# finalArt = bg.copy()
|
# And finally copy the background and paste in the image
|
||||||
# finalArt.paste(logo, (pasteX, pasteY), logo)
|
# finalArt = bg.copy()
|
||||||
# Write out the file
|
# finalArt.paste(logo, (pasteX, pasteY), logo)
|
||||||
# finalArt.save(f'{image_dir}/' + game.app_name + '/FinalArt.png')
|
# Write out the file
|
||||||
logoCopy = logo.copy()
|
# finalArt.save(f'{image_dir}/' + game.app_name + '/FinalArt.png')
|
||||||
logoCopy.putalpha(int(256 * 3 / 4))
|
logoCopy = logo.copy()
|
||||||
logo.paste(logoCopy, logo)
|
logoCopy.putalpha(int(256 * 3 / 4))
|
||||||
uninstalledArt = bg.copy()
|
logo.paste(logoCopy, logo)
|
||||||
uninstalledArt.paste(logo, (pasteX, pasteY), logo)
|
uninstalledArt = bg.copy()
|
||||||
uninstalledArt = uninstalledArt.convert('L')
|
uninstalledArt.paste(logo, (pasteX, pasteY), logo)
|
||||||
uninstalledArt.save(f'{image_dir}/' + game.app_name + '/UninstalledArt.png')
|
uninstalledArt = uninstalledArt.convert('L')
|
||||||
else:
|
uninstalledArt.save(f'{image_dir}/' + game.app_name + '/UninstalledArt.png')
|
||||||
logger.warning(f"File {image_dir}/{game.app_name}/DieselGameBoxTall.png doesn't exist")
|
else:
|
||||||
|
logger.warning(f"File {image_dir}/{game.app_name}/DieselGameBoxTall.png doesn't exist")
|
||||||
|
|
||||||
|
|
||||||
color_role_map = {
|
color_role_map = {
|
||||||
|
|
Loading…
Reference in a new issue