File: ImageFileIO.py

package info (click to toggle)
python-imaging 1.1.4-3.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,092 kB
  • ctags: 2,664
  • sloc: ansic: 16,119; python: 9,017; makefile: 161
file content (47 lines) | stat: -rw-r--r-- 1,219 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# The Python Imaging Library.
# $Id: //modules/pil/PIL/ImageFileIO.py#4 $
#
# kludge to get basic ImageFileIO functionality
#
# History:
# 1998-08-06 fl   Recreated
#
# Copyright (c) Secret Labs AB 1998-2002.
#
# See the README file for information on usage and redistribution.
#

from StringIO import StringIO

##
# The <b>ImageFileIO</b> module can be used to read an image from a
# socket, or any other stream device.
# <p>
# This module is deprecated. New code should use the <b>Parser</b>
# class in the <a href="imagefile">ImageFile</a> module instead.
#
# @see ImageFile#Parser

class ImageFileIO(StringIO):

    ##
    # Adds buffering to a stream file object, in order to
    # provide <b>seek</b> and <b>tell</b> methods required
    # by the <b>Image.open</b> method. The stream object must
    # implement <b>read</b> and <b>close</b> methods.
    #
    # @param fp Stream file handle.
    # @see Image#open

    def __init__(self, fp):
        data = fp.read()
        StringIO.__init__(self, data)

if __name__ == "__main__":

    import Image
    fp = open("/images/clenna.im", "rb")
    im = Image.open(ImageFileIO(fp))
    im.load() # make sure we can read the raster data
    print im.mode, im.size