Module eagle :: Class Image
[show private | hide private]
[frames | no frames]

Type Image

object --+    
         |    
 _EGObject --+
             |
object --+   |
         |   |
 AutoGenId --+
             |
            Image


An image that can be loaded from files or binary data and saved to files.
Method Summary
  __init__(self, **kargs)
Image constructor.
  __del__(self)
  __get_gtk_pixbuf__(self)
  get_bits_per_pixel(self)
Bits per pixel
  get_data(self)
Return raw data and information about this image.
  get_depth(self)
Bits per pixel
  get_formats(self)
Get supported image format information.
  get_height(self)
  get_n_channels(self)
Number of channels.
  get_rowstride(self)
Row stride is the allocated size of a row.
  get_size(self)
Return a tuple ( width, heigt )
  get_width(self)
  get_writable_formats(self)
Get formats that support saving/writing.
  has_alpha(self)
If it has an alpha channel
  load_data(self, data, width, height, depth, has_alpha, rowstride)
Load image from raw data.
  load_file(self, filename)
Load image from file given its filename.
  save(self, filename, format, **options)
Save image to a file.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Instance Method Details

__init__(self, **kargs)
(Constructor)

Image constructor.

Images can be constructed in 2 ways using keyword arguments:
  • from files, in this case you give it filename keyword:
    >>> Image( filename='myfile.png' )
  • from raw data, in this case you need to provide at least data, width and height as arguments. Optional arguments are depth, has_alpha and row_stride. See load_data() for more information:
    >>> Image( data=data, width=200, height=200, depth=32, has_alpha=False )
Overrides:
eagle._EGObject.__init__
See Also:
load_data(), load_file()

get_bits_per_pixel(self)

Bits per pixel

get_data(self)

Return raw data and information about this image.
Returns:
a tuple of:
  • width
  • height
  • depth
  • has alpha?
  • rowstride
  • raw pixel data

get_depth(self)

Bits per pixel

get_formats(self)

Get supported image format information.
Returns:
list of dicts with keys:
  • name: format name
  • description: format description
  • extensions: extensions that match format
  • mime_types: mime types that match format
  • is_writable: if it is possible to write in this format, otherwise it's just readable

get_n_channels(self)

Number of channels.

get_rowstride(self)

Row stride is the allocated size of a row.

Generally, rowstride is the number of elements in a row multiplied by the size of each element (bits per pixel).

But there are cases that there is more space left, a padding, to align it to some boundary, so you may get different value for row stride.

get_size(self)

Return a tuple ( width, heigt )

get_writable_formats(self)

Get formats that support saving/writing.

See Also: get_formats()

has_alpha(self)

If it has an alpha channel

load_data(self, data, width, height, depth=24, has_alpha=None, rowstride=None)

Load image from raw data.

If no value is provided as has_alpha, then it's set to False if depth is less or equal 24 or set to True if depth is 32.

If no value is provided as rowstride, then it's set to width * depth / bits_per_sample.
>>> i = Image()
>>> i.load_data( my_data1, 800, 600, depth=32, has_alpha=False )
>>> i.load_data( my_data2, 400, 300, depth=24 )

load_file(self, filename)

Load image from file given its filename.

filename may be a string or a tuple/list with path elements, this helps your program to stay portable across different platforms.
>>> i = Image()
>>> i.load_file( 'img.png' )
>>> i.load_file( ( 'test', 'img.png' ) )

save(self, filename, format=None, **options)

Save image to a file.

If format is not specified, it will be guessed from filename.

Format may be an extension or a mime type, see get_writable_formats().
Raises:
Exception - if errors happened during write
ValueError - if format is unsupported

See Also: get_writable_formats().


Generated by Epydoc 2.1 on Thu Apr 27 16:28:55 2006 http://epydoc.sf.net