Changeset 5780 for branches


Ignore:
Timestamp:
Jul 29, 2015 9:25:28 PM (9 years ago)
Author:
mmh
Message:

compatibility fixes for older python PIL libraries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/uq/examples/zoo/image/image.py

    r5778 r5780  
    1616from Rappture.encoding import decode, encode
    1717
     18
    1819# uncomment these for debugging
    1920# sys.stdout = open('image.out', 'w')
    2021# sys.stderr = open('image.err', 'w')
     22
     23
     24# rotate image data
     25def rotate_image(data, angle):
     26
     27    # bug workaround in some PIL versions
     28    def fileno():
     29        raise AttributeError
     30
     31    # open image from data and rotate
     32    image = Image.open(BytesIO(data))
     33    rot = image.rotate(angle, expand=True)
     34    # save image to a file in memory
     35    memfile = BytesIO()
     36    memfile.fileno = fileno  # required in some broken PILs
     37    rot.save(memfile, image.format)
     38    return memfile.getvalue()
     39
    2140
    2241# open the XML file containing the run parameters
     
    3049angle = float(Rappture.Units.convert(angle, to='deg', units='off'))
    3150
     51rx['output.image(outi).about.label'] = "Rotated Image"
    3252
    33 rx['output.image(outi).about.label'] = "Rotated Image"
    34 image = Image.open(BytesIO(data))
    35 image = image.rotate(angle, expand=True)
    36 
    37 # save image to a file in memory
    38 memfile = BytesIO()
    39 image.save(memfile, 'GIF')
    40 data = memfile.getvalue()
     53data = rotate_image(data, angle)
    4154
    4255# Image data must be B64 or ZB64 encoded.
Note: See TracChangeset for help on using the changeset viewer.