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

Class Image
source code

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

An image that can be loaded from files or binary data and saved to files.

Instance Methods [hide private]
  __init__(self, **kargs)
Image constructor.
  __get_gtk_pixbuf__(self)
  __del__(self)
  save(self, filename, format=None, **options)
Save image to a file.
  get_formats(self)
Get supported image format information.
  get_writable_formats(self)
Get formats that support saving/writing.
  load_file(self, filename)
Load image from file given its filename.
  load_data(self, data, width, height, depth=24, has_alpha=None, rowstride=None)
Load image from raw data.
  get_data(self)
Return raw data and information about this image.
  get_width(self)
  get_height(self)
  get_size(self)
Return a tuple ( width, heigt )
  get_rowstride(self)
Row stride is the allocated size of a row.
  get_n_channels(self)
Number of channels.
  get_bits_per_pixel(self)
Bits per pixel
  get_depth(self)
Bits per pixel
  has_alpha(self)
If it has an alpha channel

Inherited from _EGObject: __repr__, __str__

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__


Class Methods [hide private]
  __get_by_id__(klass, id)

Inherited from AutoGenId: __get_id__


Class Variables [hide private]
_id2obj_  

Inherited from _EGObject: id

Inherited from AutoGenId: last_id_num

Inherited from object: __class__


Method Details [hide private]

__init__(self, **kargs)
(Constructor)

source code 

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: _EGObject.__init__
See Also:
load_data(), load_file()

__get_gtk_pixbuf__(self)

source code 

__get_by_id__(klass, id)

source code 

__del__(self)
(Destructor)

source code 

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

source code 

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().

get_formats(self)

source code 
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_writable_formats(self)

source code 
Get formats that support saving/writing.

See Also: get_formats()

load_file(self, filename)

source code 

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' ) )

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

source code 

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 )

get_data(self)

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

get_width(self)

source code 

get_height(self)

source code 

get_size(self)

source code 
Return a tuple ( width, heigt )

get_rowstride(self)

source code 

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_n_channels(self)

source code 
Number of channels.

get_bits_per_pixel(self)

source code 
Bits per pixel

get_depth(self)

source code 
Bits per pixel

has_alpha(self)

source code 
If it has an alpha channel

Class Variable Details [hide private]

_id2obj_

Value:
weakref.WeakValueDictionary()