How to create an image with same pixel color? #631
Answered
by
emcconville
druzhynin-oleksii
asked this question in
Q&A
-
|
Beta Was this translation helpful? Give feedback.
Answered by
emcconville
Sep 7, 2023
Replies: 1 comment
-
This more than a few ways to do this. Here are some examples. from wand.display import display
from wand.drawing import Drawing
from wand.image import Image
import numpy as np
one_pixel_color_rgba = [128, 128, 128, 255]
# Create a new image with a background color.
color_rgba = 'rgba({0}, {1}, {2}, {3})'.format(*one_pixel_color_rgba)
with Image(width=128, height=128, background=color_rgba) as img:
display(img)
# Read a canvas protocol
canvas = 'canvas:rgba({0}, {1}, {2}, {3})'.format(*one_pixel_color_rgba)
with Image(width=128, height=128, filename=canvas) as img:
display(img)
# Import raw pixels from Numpy
uniform_color_rgba = np.tile(np.array(one_pixel_color_rgba, dtype='u1'),
(128, 128, 1))
with Image.from_array(uniform_color_rgba) as img:
display(img)
# Flood-fill existing image.
with Image(width=128, height=128, filename='plasma:') as img:
with Drawing() as ctx:
ctx.fill_color = color_rgba
ctx.color(0, 0, 'reset')
ctx.draw(img)
display(img) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
druzhynin-oleksii
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This more than a few ways to do this. Here are some examples.