Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion swf/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
import Image
except ImportError:
from PIL import Image

# Fix Pillow 1.x -> 3.x incompatibility:
# (fromstring was renamed to frombytes)
if not hasattr(Image, 'frombytes'):
Image.frombytes = Image.fromstring

try:
from cStringIO import StringIO
except ImportError:
Expand Down Expand Up @@ -425,7 +431,7 @@ def export_define_bits(self, tag):
alpha = ord(tag.bitmapAlphaData.read(1))
rgb = list(image_data[i])
buff += struct.pack("BBBB", rgb[0], rgb[1], rgb[2], alpha)
image = Image.fromstring("RGBA", (image_width, image_height), buff)
image = Image.frombytes("RGBA", (image_width, image_height), buff)
elif isinstance(tag, TagDefineBitsJPEG2):
tag.bitmapData.seek(0)
image = Image.open(tag.bitmapData)
Expand Down
10 changes: 8 additions & 2 deletions swf/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import Image
except ImportError:
from PIL import Image

# Fix Pillow 1.x -> 3.x incompatibility:
# (fromstring was renamed to frombytes)
if not hasattr(Image, 'frombytes'):
Image.frombytes = Image.fromstring

import struct

try:
Expand Down Expand Up @@ -888,7 +894,7 @@ def parse(self, data, length, version=1):
self.image_buffer = s.getvalue()
s.close()

im = Image.fromstring("RGBA", (self.padded_width, self.bitmap_height), self.image_buffer)
im = Image.frombytes("RGBA", (self.padded_width, self.bitmap_height), self.image_buffer)
im = im.crop((0, 0, self.bitmap_width, self.bitmap_height))

elif self.bitmap_format == BitmapFormat.BIT_15:
Expand All @@ -907,7 +913,7 @@ def parse(self, data, length, version=1):
b = ord(temp.read(1))
s.write(struct.pack("BBBB", r, g, b, a))
self.image_buffer = s.getvalue()
im = Image.fromstring("RGBA", (self.bitmap_width, self.bitmap_height), self.image_buffer)
im = Image.frombytes("RGBA", (self.bitmap_width, self.bitmap_height), self.image_buffer)
else:
raise Exception("unhandled bitmap format! %s %d" % (BitmapFormat.tostring(self.bitmap_format), self.bitmap_format))

Expand Down