mirror of
https://github.com/TomHodson/tomhodson.github.com.git
synced 2025-06-26 10:01:18 +02:00
fix micropython image night mode
This commit is contained in:
parent
ef0aaede49
commit
d19b058541
@ -3,8 +3,9 @@ title: MicroPython Simulator
|
||||
layout: post
|
||||
excerpt: A simulator for my USB C Power supply project using Micropython running in websassembly.
|
||||
|
||||
image: /assets/blog/micropython/simulated_display.png
|
||||
thumbnail: /assets/blog/micropython/simulated_display.png
|
||||
image: /assets/blog/micropython/simulated_display_transparent.png
|
||||
thumbnail: /assets/blog/micropython/simulated_display_transparent.png
|
||||
social_image: /assets/blog/micropython/simulated_display.png
|
||||
assets: /assets/blog/micropython
|
||||
alt: A 240x240 pixel (so low res) image of a slightly sci-fiesque looking circular display showing so linear and curved bars, 24.4 volts, in bigger font 213w and 8.7A.
|
||||
image_class: invertable
|
||||
|
28
assets/blog/micropython/convert_to_transparent.py
Normal file
28
assets/blog/micropython/convert_to_transparent.py
Normal file
@ -0,0 +1,28 @@
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def convert_image(input_path, output_path):
|
||||
# Open the image
|
||||
grey = np.array(Image.open(input_path).convert("L"))
|
||||
alpha_channel = 255 - grey
|
||||
|
||||
rgba_array = np.zeros((grey.shape[0], grey.shape[1], 4), dtype=np.uint8)
|
||||
rgba_array[..., 0] = 0 # Red channel
|
||||
rgba_array[..., 1] = 0 # Green channel
|
||||
rgba_array[..., 2] = 0 # Blue channel
|
||||
rgba_array[..., 3] = alpha_channel # Alpha channel
|
||||
|
||||
# Create a new image for the output
|
||||
rgba_img = Image.fromarray(rgba_array, mode="RGBA")
|
||||
|
||||
|
||||
|
||||
# Save the result
|
||||
rgba_img.save(output_path, "PNG")
|
||||
print(f"Image saved to {output_path}")
|
||||
|
||||
# Example usage
|
||||
input_file = "simulated_display.png"
|
||||
output_file = "simulated_display_transparent.png"
|
||||
convert_image(input_file, output_file)
|
BIN
assets/blog/micropython/simulated_display_transparent.png
Normal file
BIN
assets/blog/micropython/simulated_display_transparent.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Loading…
x
Reference in New Issue
Block a user