On Fri, Mar 6, 2015 at 7:37 PM, Garo Atberger <[email protected]> wrote:
> Hello there. I ran into an issue with trying to get image data from two
> images, to then combine and save as a PNG. I'm not exactly sure how to
> address this problem directly, other than saying that the resulting data is
> usually a garbled mess.
> I'm including the small script with example images to demonstrate what I
> tried to do so far. Is there any way to fix that? Or maybe is there a
> better way to do that?
>
> Thank you in advance.
>
They are at least two problems in the script:
1. the pitch parameter in .get_data should be the number of bytes per
row, Negative values indicate a top-to-bottom arrangement. Normally width
* len(format). The script is passing len(format)
2. the implementation of the interleave functionality does not work; a
variant that works can be
def interleave(image, alpha):
image_iterator = iter(image)
alpha_iterator = iter(alpha)
while 1:
yield image_iterator.next()
yield image_iterator.next()
yield image_iterator.next()
yield alpha_iterator.next()
image = b"123"*16
alpha = b"7"*16
print "image:", repr(image)
print "alpha:", repr(alpha)
interleaved = ''.join(interleave(image, alpha))
print "interleaved:", interleaved
If you only care about getting the image on disk, then using pillow (
https://pypi.python.org/pypi/Pillow/2.7.0) would be faster and simpler:
from PIL import Image
mask = Image.open("test3_a.bmp")
mask = mask.convert("L")
bar = Image.open("test3.bmp")
bar.putalpha(mask)
bar.save("test3_with_alpha.png")
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.