diff --git a/_posts/2024-09-09-micropython-simulator.md b/_posts/2024-09-09-micropython-simulator.md index 8a7a77b..1b8394e 100644 --- a/_posts/2024-09-09-micropython-simulator.md +++ b/_posts/2024-09-09-micropython-simulator.md @@ -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 diff --git a/assets/blog/micropython/convert_to_transparent.py b/assets/blog/micropython/convert_to_transparent.py new file mode 100644 index 0000000..763e856 --- /dev/null +++ b/assets/blog/micropython/convert_to_transparent.py @@ -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) \ No newline at end of file diff --git a/assets/blog/micropython/simulated_display_transparent.png b/assets/blog/micropython/simulated_display_transparent.png new file mode 100644 index 0000000..561a465 Binary files /dev/null and b/assets/blog/micropython/simulated_display_transparent.png differ