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
12 changes: 6 additions & 6 deletions swf/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import base64
from six.moves import map
from six.moves import range
from six import unichr
try:
import Image
except ImportError:
from PIL import Image
from io import BytesIO
from six.moves import cStringIO
import math
import re
import copy
Expand Down Expand Up @@ -421,7 +421,7 @@ def export_define_bits(self, tag):
image_data = image.getdata()
image_data_len = len(image_data)
if num_alpha == image_data_len:
buff = ""
buff = b""
for i in range(0, num_alpha):
alpha = ord(tag.bitmapAlphaData.read(1))
rgb = list(image_data[i])
Expand Down Expand Up @@ -542,11 +542,11 @@ def export(self, swf, force_stroke=False):
self.bounds.width, self.bounds.height]
self.svg.set("viewBox", "%s" % " ".join(map(str,vb)))

# Return the SVG as StringIO
# Return the SVG as BytesIO
return self._serialize()

def _serialize(self):
return cStringIO(etree.tostring(self.svg,
return BytesIO(etree.tostring(self.svg,
encoding="UTF-8", xml_declaration=True))

def export_define_sprite(self, tag, parent=None):
Expand Down Expand Up @@ -1100,10 +1100,10 @@ def _push_transform(self, transform):
self._matrix = self._calc_combined_matrix()

def _encode_jpeg(data):
return "data:image/jpeg;base64," + base64.encodestring(data)[:-1]
return b"data:image/jpeg;base64," + base64.encodestring(data)[:-1]

def _encode_png(data):
return "data:image/png;base64," + base64.encodestring(data)[:-1]
return b"data:image/png;base64," + base64.encodestring(data)[:-1]

def _swf_matrix_to_matrix(swf_matrix=None, need_scale=False, need_translate=True, need_rotation=False, unit_div=20.0):

Expand Down
1 change: 0 additions & 1 deletion swf/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .tag import SWFTimelineContainer
from .stream import SWFStream
from .export import SVGExporter
from six.moves import cStringIO
from io import BytesIO

class SWFHeaderException(Exception):
Expand Down
10 changes: 10 additions & 0 deletions test/test_swf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import
from swf.movie import SWF
from swf.export import SVGExporter

def test_header():

Expand All @@ -8,3 +9,12 @@ def test_header():
swf = SWF(f)

assert swf.header.frame_count == 1

def test_export():
f = open('./test/data/test.swf', 'rb')
swf = SWF(f)

svg_exporter = SVGExporter()
svg = svg_exporter.export(swf)

assert b'<svg xmlns' in svg.read()