Initial commit
This commit is contained in:
41
scratch/brighten_map.py
Normal file
41
scratch/brighten_map.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from PIL import Image
|
||||
|
||||
def brighten_alpha(input_path, output_path):
|
||||
img = Image.open(input_path).convert("RGBA")
|
||||
width, height = img.size
|
||||
pixels = img.load()
|
||||
|
||||
# First, find the maximum alpha value in the image
|
||||
max_alpha = 0
|
||||
for x in range(width):
|
||||
for y in range(height):
|
||||
r, g, b, a = pixels[x, y]
|
||||
if a > max_alpha:
|
||||
max_alpha = a
|
||||
|
||||
print(f"Original max alpha: {max_alpha}")
|
||||
if max_alpha == 0:
|
||||
print("Image is completely transparent!")
|
||||
return
|
||||
|
||||
# Scale alpha to make max_alpha equal to 255
|
||||
scale_factor = 255.0 / max_alpha
|
||||
changed_count = 0
|
||||
|
||||
for x in range(width):
|
||||
for y in range(height):
|
||||
r, g, b, a = pixels[x, y]
|
||||
if a > 0:
|
||||
new_a = min(int(a * scale_factor), 255)
|
||||
# Keep color as white, but set scaled alpha
|
||||
pixels[x, y] = (255, 255, 255, new_a)
|
||||
changed_count += 1
|
||||
|
||||
img.save(output_path, "PNG")
|
||||
print(f"Successfully scaled alpha for {changed_count} pixels and saved to {output_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
brighten_alpha(
|
||||
"public/images/slider-glob.png",
|
||||
"public/images/slider-glob.png"
|
||||
)
|
||||
Reference in New Issue
Block a user