1
0
Fork 0
mirror of https://github.com/walkxcode/dashboard-icons.git synced 2024-11-25 12:49:26 +01:00

Adds processing of PNG-only files

This commit is contained in:
Bjorn Lammers 2024-10-20 20:46:29 +02:00
parent 89a666b999
commit 85683471ea
No known key found for this signature in database
3 changed files with 34 additions and 10 deletions

View file

@ -26,7 +26,9 @@ def file_size_readable(size_bytes):
for unit in ['B', 'KB', 'MB', 'GB']:
if size_bytes < 1024:
return f"{size_bytes:.2f} {unit}"
#size_bytes /= 1024
size_bytes /= 1024
return f"{size_bytes:.2f} TB"
def hash_file(file_path):
"""Generate an MD5 hash for a file."""
@ -83,11 +85,11 @@ def convert_svg_to_png(svg_path, png_path):
print(f"Failed to convert {svg_path} to PNG: {e}")
failed_files.append(svg_path)
def convert_png_to_webp(png_path, webp_path):
"""Convert PNG to WEBP."""
def convert_image_to_webp(image_path, webp_path):
"""Convert an image (PNG or other) to WEBP."""
global converted_webps
try:
image = Image.open(png_path)
image = Image.open(image_path).convert("RGBA")
if needs_conversion(webp_path):
image.save(webp_path, format='WEBP')
@ -97,11 +99,11 @@ def convert_png_to_webp(png_path, webp_path):
print(f"WEBP already up-to-date: {webp_path}")
except Exception as e:
print(f"Failed to convert {png_path} to WEBP: {e}")
failed_files.append(png_path)
print(f"Failed to convert {image_path} to WEBP: {e}")
failed_files.append(image_path)
def clean_up_files(folder, valid_basenames):
"""Remove files that no longer have corresponding SVG files."""
"""Remove files that no longer have corresponding SVG or PNG files."""
removed_files = 0
for file_path in folder.glob('*'):
if file_path.stem not in valid_basenames:
@ -111,7 +113,7 @@ def clean_up_files(folder, valid_basenames):
return removed_files
if __name__ == "__main__":
# Track valid basenames (existing SVG files)
# Track valid basenames (from SVG and PNG files)
valid_basenames = set()
# Process all SVG files
@ -137,10 +139,30 @@ if __name__ == "__main__":
# Convert PNG to WEBP
if png_path.exists():
convert_png_to_webp(png_path, webp_path)
convert_image_to_webp(png_path, webp_path)
# Clean up unused files
removed_pngs = clean_up_files(PNG_DIR, valid_basenames)
# Process PNG-only files
for png_file in PNG_DIR.glob("*.png"):
if png_file.stem not in valid_basenames:
# Ensure the filename is in kebab-case
try:
png_path = rename_if_needed(png_file)
except Exception as e:
print(f"Error renaming {png_file}: {e}")
failed_files.append(png_file)
continue
valid_basenames.add(png_path.stem)
# Set path for WEBP
webp_path = WEBP_DIR / f"{png_path.stem}.webp"
# Convert PNG to WEBP
convert_image_to_webp(png_path, webp_path)
# Clean up unused files in PNG and WEBP directories
# Only remove files that don't have corresponding SVG or PNG files
removed_pngs = clean_up_files(PNG_DIR, valid_basenames.union({p.stem for p in SVG_DIR.glob("*.svg")}))
removed_webps = clean_up_files(WEBP_DIR, valid_basenames)
# Display summary

1
svg/5etools-dark.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><defs fill="#000000"><style>.b7b679e6-ada4-4402-bdd2-d1b005a1536e{fill:none;}.a4896c5b-92b1-4ea7-9c97-9102875be579{fill:#000000;}.e1d7225d-187f-4ddd-b945-099d3499f195{fill:#006bc4;}</style></defs><g id="be500154-a894-4e84-ae56-73817aeecc3d" data-name="Layer 2"><g id="af849f92-0daa-4adb-aa72-60933fc8c170" data-name="favicon- lighter"><rect class="b7b679e6-ada4-4402-bdd2-d1b005a1536e" width="128" height="128" fill="#000000"/><g id="b0c362e5-aa47-42ee-a6c1-79a930aaa54b" data-name="5"><path class="a4896c5b-92b1-4ea7-9c97-9102875be579" d="M20.27,72.68a29.45,29.45,0,0,1,7.64-15.11q5.72-5.79,14.72-5.79,10.77,0,15.11,11.42,2.73,7.23,2.73,20.26,0,14.48-4.18,22.35-5.46,10.45-18.49,10.45a25.63,25.63,0,0,1-10-2.25q-6.6-2.73-6.59-6.59c0-.54,1.77-2.09,5.3-4.67s5.31-5.73,5.31-9.48a10.94,10.94,0,0,0-3.13-7.8,10.14,10.14,0,0,0-7.64-3.3A12.07,12.07,0,0,0,11.75,86a13.73,13.73,0,0,0-3.54,9.65q0,11.75,10,18.81a35.23,35.23,0,0,0,20.91,6.27,43,43,0,0,0,29.67-11.17,36,36,0,0,0,12.46-27.9q0-14.31-10.87-24.68A35.57,35.57,0,0,0,45,46.63a26.58,26.58,0,0,0-11.83,2.42A46.28,46.28,0,0,0,22.62,56.6L25.4,27.5c3.65.49,7.48,1,11.5,1.41a96.37,96.37,0,0,0,10.54.68q11.42,0,18.5-5.43T75.43,7.87l-4.18-.63a12.65,12.65,0,0,1-5.39,6.31,17.76,17.76,0,0,1-8.6,1.89,68.2,68.2,0,0,1-12.38-1.1q-6-1.1-22.36-5.33L15.77,72.2Z" fill="#000000"/><path class="e1d7225d-187f-4ddd-b945-099d3499f195" d="M71.25,7.24l4.18.63Q73,18.73,65.94,24.16t-18.5,5.43a96.37,96.37,0,0,1-10.54-.68c-4-.44-7.85-.92-11.5-1.41L22.62,56.6a46.28,46.28,0,0,1,10.54-7.55A26.58,26.58,0,0,1,45,46.63,35.57,35.57,0,0,1,70.35,57Q81.21,67.38,81.22,81.69a36,36,0,0,1-12.46,27.9,43,43,0,0,1-29.67,11.17,35.23,35.23,0,0,1-20.91-6.27q-10-7.06-10-18.81A13.73,13.73,0,0,1,11.75,86a12.07,12.07,0,0,1,9.33-3.86,10.14,10.14,0,0,1,7.64,3.3,10.94,10.94,0,0,1,3.13,7.8q0,5.63-5.31,9.48c-3.53,2.58-5.3,4.13-5.3,4.67q0,3.85,6.59,6.59a25.63,25.63,0,0,0,10,2.25q13,0,18.49-10.45,4.18-7.87,4.18-22.35,0-13-2.73-20.26Q53.41,51.79,42.63,51.78q-9,0-14.72,5.79a29.45,29.45,0,0,0-7.64,15.11l-4.5-.48L22.52,9q16.41,4.23,22.36,5.33a68.2,68.2,0,0,0,12.38,1.1,17.76,17.76,0,0,0,8.6-1.89,12.65,12.65,0,0,0,5.39-6.31m0-7.24a7.23,7.23,0,0,0-6.62,4.34C63.68,6.49,62.71,7,62.39,7.2a11,11,0,0,1-5.13,1,61,61,0,0,1-11.07-1C42.42,6.53,35.07,4.77,24.33,2a7.36,7.36,0,0,0-1.81-.23,7.23,7.23,0,0,0-7.19,6.47L8.58,71.43a7.22,7.22,0,0,0,2.3,6.11,18.91,18.91,0,0,0-4.47,3.6A20.86,20.86,0,0,0,1,95.68c0,10.13,4.5,18.67,13,24.71A42.39,42.39,0,0,0,39.09,128a50.15,50.15,0,0,0,34.5-13A43,43,0,0,0,88.45,81.69c0-11.55-4.41-21.62-13.1-29.92A42.77,42.77,0,0,0,45,39.4,34.65,34.65,0,0,0,31.29,42l.6-6.33,4.21.49a105.28,105.28,0,0,0,11.34.71c9.21,0,16.91-2.32,22.9-6.92S80.51,18.36,82.49,9.44a7.24,7.24,0,0,0-6-8.72L72.34.08A8.14,8.14,0,0,0,71.24,0ZM26.78,75.85a7,7,0,0,0,.58-1.7,22.2,22.2,0,0,1,5.7-11.5C35.51,60.17,38.55,59,42.63,59c3,0,6.09.81,8.35,6.75,1.5,4,2.26,9.92,2.26,17.69,0,8.41-1.12,14.78-3.34,19l0,0c-1.6,3.05-4.42,6.57-12.08,6.57a17.47,17.47,0,0,1-6-1.21A18.34,18.34,0,0,0,34,80.48a17.66,17.66,0,0,0-7.18-4.63Z" fill="#000000"/></g><g id="ecd5d70c-6053-4658-bded-73554bf48031" data-name="e"><path class="a4896c5b-92b1-4ea7-9c97-9102875be579" d="M119.79,78q-1-12-7.46-19.68-7.08-8.49-18.66-8.49a26.51,26.51,0,0,0-20.26,8.62,29.44,29.44,0,0,0-8,20.84,33.5,33.5,0,0,0,7.82,22.12,25.24,25.24,0,0,0,20.36,9.39,25,25,0,0,0,17.77-7,26.63,26.63,0,0,0,8.47-17.33h-3.73a28.57,28.57,0,0,1-6.18,13.38,16.44,16.44,0,0,1-12.86,6q-11.46,0-15.44-7.59Q78.75,93,78.75,80.43L78.62,78Zm-41-3.6q0-9,2.86-14.41Q85.24,53,93.68,53a11.75,11.75,0,0,1,10.26,5.28,19.47,19.47,0,0,1,3.11,11.32v4.76Z" fill="#000000"/><path class="e1d7225d-187f-4ddd-b945-099d3499f195" d="M93.67,49.82q11.58,0,18.66,8.49Q118.75,66,119.79,78H78.62l.13,2.44q0,12.61,2.83,17.88,4,7.6,15.44,7.59a16.44,16.44,0,0,0,12.86-6,28.57,28.57,0,0,0,6.18-13.38h3.73a26.63,26.63,0,0,1-8.47,17.33,25,25,0,0,1-17.77,7,25.24,25.24,0,0,1-20.36-9.39,33.5,33.5,0,0,1-7.82-22.12,29.44,29.44,0,0,1,8-20.84,26.51,26.51,0,0,1,20.26-8.62M78.75,74.39h28.3V69.63a19.47,19.47,0,0,0-3.11-11.32A11.75,11.75,0,0,0,93.68,53Q85.23,53,81.61,60q-2.86,5.4-2.86,14.41M93.67,42.58A33.61,33.61,0,0,0,68.12,53.5a36.58,36.58,0,0,0-10,25.78A40.68,40.68,0,0,0,67.63,106c6.63,8,15.35,12,25.92,12a32.18,32.18,0,0,0,22.73-9A33.81,33.81,0,0,0,127,87.2a7.32,7.32,0,0,0-1.34-5A7.24,7.24,0,0,0,127,77.37c-.82-9.44-3.88-17.42-9.12-23.7a30.43,30.43,0,0,0-10.76-8.32,32.2,32.2,0,0,0-13.45-2.77Zm-7,24.57A15.41,15.41,0,0,1,88,63.36l0,0c1-1.84,2.29-3.06,5.66-3.06A4.58,4.58,0,0,1,98,62.41a10.68,10.68,0,0,1,1.68,4.74Zm-.56,18.08h22.82a21.53,21.53,0,0,1-4.49,9.86A9.23,9.23,0,0,1,97,98.67c-7.08,0-8.5-2.7-9-3.72l0-.06c-.49-.9-1.49-3.47-1.85-9.66Z" fill="#000000"/></g></g></g></svg>

After

Width:  |  Height:  |  Size: 4.6 KiB

1
svg/5etools.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><defs><style>.b7b679e6-ada4-4402-bdd2-d1b005a1536e{fill:none;}.a4896c5b-92b1-4ea7-9c97-9102875be579{fill:#fff;}.e1d7225d-187f-4ddd-b945-099d3499f195{fill:#006bc4;}</style></defs><g id="be500154-a894-4e84-ae56-73817aeecc3d" data-name="Layer 2"><g id="af849f92-0daa-4adb-aa72-60933fc8c170" data-name="favicon- lighter"><rect class="b7b679e6-ada4-4402-bdd2-d1b005a1536e" width="128" height="128"/><g id="b0c362e5-aa47-42ee-a6c1-79a930aaa54b" data-name="5"><path class="a4896c5b-92b1-4ea7-9c97-9102875be579" d="M20.27,72.68a29.45,29.45,0,0,1,7.64-15.11q5.72-5.79,14.72-5.79,10.77,0,15.11,11.42,2.73,7.23,2.73,20.26,0,14.48-4.18,22.35-5.46,10.45-18.49,10.45a25.63,25.63,0,0,1-10-2.25q-6.6-2.73-6.59-6.59c0-.54,1.77-2.09,5.3-4.67s5.31-5.73,5.31-9.48a10.94,10.94,0,0,0-3.13-7.8,10.14,10.14,0,0,0-7.64-3.3A12.07,12.07,0,0,0,11.75,86a13.73,13.73,0,0,0-3.54,9.65q0,11.75,10,18.81a35.23,35.23,0,0,0,20.91,6.27,43,43,0,0,0,29.67-11.17,36,36,0,0,0,12.46-27.9q0-14.31-10.87-24.68A35.57,35.57,0,0,0,45,46.63a26.58,26.58,0,0,0-11.83,2.42A46.28,46.28,0,0,0,22.62,56.6L25.4,27.5c3.65.49,7.48,1,11.5,1.41a96.37,96.37,0,0,0,10.54.68q11.42,0,18.5-5.43T75.43,7.87l-4.18-.63a12.65,12.65,0,0,1-5.39,6.31,17.76,17.76,0,0,1-8.6,1.89,68.2,68.2,0,0,1-12.38-1.1q-6-1.1-22.36-5.33L15.77,72.2Z"/><path class="e1d7225d-187f-4ddd-b945-099d3499f195" d="M71.25,7.24l4.18.63Q73,18.73,65.94,24.16t-18.5,5.43a96.37,96.37,0,0,1-10.54-.68c-4-.44-7.85-.92-11.5-1.41L22.62,56.6a46.28,46.28,0,0,1,10.54-7.55A26.58,26.58,0,0,1,45,46.63,35.57,35.57,0,0,1,70.35,57Q81.21,67.38,81.22,81.69a36,36,0,0,1-12.46,27.9,43,43,0,0,1-29.67,11.17,35.23,35.23,0,0,1-20.91-6.27q-10-7.06-10-18.81A13.73,13.73,0,0,1,11.75,86a12.07,12.07,0,0,1,9.33-3.86,10.14,10.14,0,0,1,7.64,3.3,10.94,10.94,0,0,1,3.13,7.8q0,5.63-5.31,9.48c-3.53,2.58-5.3,4.13-5.3,4.67q0,3.85,6.59,6.59a25.63,25.63,0,0,0,10,2.25q13,0,18.49-10.45,4.18-7.87,4.18-22.35,0-13-2.73-20.26Q53.41,51.79,42.63,51.78q-9,0-14.72,5.79a29.45,29.45,0,0,0-7.64,15.11l-4.5-.48L22.52,9q16.41,4.23,22.36,5.33a68.2,68.2,0,0,0,12.38,1.1,17.76,17.76,0,0,0,8.6-1.89,12.65,12.65,0,0,0,5.39-6.31m0-7.24a7.23,7.23,0,0,0-6.62,4.34C63.68,6.49,62.71,7,62.39,7.2a11,11,0,0,1-5.13,1,61,61,0,0,1-11.07-1C42.42,6.53,35.07,4.77,24.33,2a7.36,7.36,0,0,0-1.81-.23,7.23,7.23,0,0,0-7.19,6.47L8.58,71.43a7.22,7.22,0,0,0,2.3,6.11,18.91,18.91,0,0,0-4.47,3.6A20.86,20.86,0,0,0,1,95.68c0,10.13,4.5,18.67,13,24.71A42.39,42.39,0,0,0,39.09,128a50.15,50.15,0,0,0,34.5-13A43,43,0,0,0,88.45,81.69c0-11.55-4.41-21.62-13.1-29.92A42.77,42.77,0,0,0,45,39.4,34.65,34.65,0,0,0,31.29,42l.6-6.33,4.21.49a105.28,105.28,0,0,0,11.34.71c9.21,0,16.91-2.32,22.9-6.92S80.51,18.36,82.49,9.44a7.24,7.24,0,0,0-6-8.72L72.34.08A8.14,8.14,0,0,0,71.24,0ZM26.78,75.85a7,7,0,0,0,.58-1.7,22.2,22.2,0,0,1,5.7-11.5C35.51,60.17,38.55,59,42.63,59c3,0,6.09.81,8.35,6.75,1.5,4,2.26,9.92,2.26,17.69,0,8.41-1.12,14.78-3.34,19l0,0c-1.6,3.05-4.42,6.57-12.08,6.57a17.47,17.47,0,0,1-6-1.21A18.34,18.34,0,0,0,34,80.48a17.66,17.66,0,0,0-7.18-4.63Z"/></g><g id="ecd5d70c-6053-4658-bded-73554bf48031" data-name="e"><path class="a4896c5b-92b1-4ea7-9c97-9102875be579" d="M119.79,78q-1-12-7.46-19.68-7.08-8.49-18.66-8.49a26.51,26.51,0,0,0-20.26,8.62,29.44,29.44,0,0,0-8,20.84,33.5,33.5,0,0,0,7.82,22.12,25.24,25.24,0,0,0,20.36,9.39,25,25,0,0,0,17.77-7,26.63,26.63,0,0,0,8.47-17.33h-3.73a28.57,28.57,0,0,1-6.18,13.38,16.44,16.44,0,0,1-12.86,6q-11.46,0-15.44-7.59Q78.75,93,78.75,80.43L78.62,78Zm-41-3.6q0-9,2.86-14.41Q85.24,53,93.68,53a11.75,11.75,0,0,1,10.26,5.28,19.47,19.47,0,0,1,3.11,11.32v4.76Z"/><path class="e1d7225d-187f-4ddd-b945-099d3499f195" d="M93.67,49.82q11.58,0,18.66,8.49Q118.75,66,119.79,78H78.62l.13,2.44q0,12.61,2.83,17.88,4,7.6,15.44,7.59a16.44,16.44,0,0,0,12.86-6,28.57,28.57,0,0,0,6.18-13.38h3.73a26.63,26.63,0,0,1-8.47,17.33,25,25,0,0,1-17.77,7,25.24,25.24,0,0,1-20.36-9.39,33.5,33.5,0,0,1-7.82-22.12,29.44,29.44,0,0,1,8-20.84,26.51,26.51,0,0,1,20.26-8.62M78.75,74.39h28.3V69.63a19.47,19.47,0,0,0-3.11-11.32A11.75,11.75,0,0,0,93.68,53Q85.23,53,81.61,60q-2.86,5.4-2.86,14.41M93.67,42.58A33.61,33.61,0,0,0,68.12,53.5a36.58,36.58,0,0,0-10,25.78A40.68,40.68,0,0,0,67.63,106c6.63,8,15.35,12,25.92,12a32.18,32.18,0,0,0,22.73-9A33.81,33.81,0,0,0,127,87.2a7.32,7.32,0,0,0-1.34-5A7.24,7.24,0,0,0,127,77.37c-.82-9.44-3.88-17.42-9.12-23.7a30.43,30.43,0,0,0-10.76-8.32,32.2,32.2,0,0,0-13.45-2.77Zm-7,24.57A15.41,15.41,0,0,1,88,63.36l0,0c1-1.84,2.29-3.06,5.66-3.06A4.58,4.58,0,0,1,98,62.41a10.68,10.68,0,0,1,1.68,4.74Zm-.56,18.08h22.82a21.53,21.53,0,0,1-4.49,9.86A9.23,9.23,0,0,1,97,98.67c-7.08,0-8.5-2.7-9-3.72l0-.06c-.49-.9-1.49-3.47-1.85-9.66Z"/></g></g></g></svg>

After

Width:  |  Height:  |  Size: 4.5 KiB