Skip to content

Commit

Permalink
[Palette] allow alpha channels on output images
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchinWeb committed Jul 14, 2015
1 parent d56aa78 commit 0377e23
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions colourettu/_palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,24 @@ def from_list(self, list_of_colours, normalized_rgb=False):
self._start = self._colours[0]
self._end = self._colours[-1]

def to_image(self, filename='palette.png', band_width=1, length=60, max_width=0, vertical=True):
def to_image(self, filename='palette.png', band_width=1, length=60,
max_width=0, vertical=True, alpha_channel=False):
"""Creates an image from the palette.
Args:
filename(optional[string]): filename of saved file. Defaults to
filename(Optional[string]): filename of saved file. Defaults to
``palette.png`` in the current working directory.
band_width(optional[int]): how wide each colour band should be.
Defaults to 1 pixel.
length(optional[int]): the length of the overall image in pixels.
length(Optional[int]): the length of the overall image in pixels.
This is the dimension orthogonal to ``band_width``. Defaults
to 60 pixels.
max_width(optional[int]): if ``band_width`` is not set and this is,
max_width(Optional[int]): if ``band_width`` is not set and this is,
this determines how wide the whole image should be.
vertical(optional[bool]): if the image runs vertical (``True``,
vertical(Optional[bool]): if the image runs vertical (``True``,
default) or horizontal (``False``).
alpha_channel(Optional[bool]): if ``True``, the created image will
have an Alpha channel. Defaults to ``False``.
"""
# max_width is approximate
# generate output pictures for documentation automatically
Expand All @@ -135,7 +138,10 @@ def to_image(self, filename='palette.png', band_width=1, length=60, max_width=0,
else:
band_width = int(max_width/len(self._colours))

my_image = Image.new('RGB', (max_width, length))
if alpha_channel:
my_image = Image.new('RGBA', (max_width, length))
else:
my_image = Image.new('RGB', (max_width, length))
image_loaded = my_image.load()

x = 0
Expand Down

0 comments on commit 0377e23

Please sign in to comment.