Image Module

Used to work with jpg images.

class py2facer.lib.image.Image(image_path)

A lazy Image object to make working with JPG images a bit easier. Image data is only read when it is actually required.

The Image object is iterable, but yields Image.ContainedPerson instances

Parameters:image_path – A path to the image file
Raises :InvalidConfig if the image_path does not exist
class ContainedPerson(google_id, x_pos=None, y_pos=None, width=None, height=None)

A generic contained person inside an image

Note

Bounding box coordinates are in pixels relative to the absolute size of the image and where the top left corner is 0,0

Parameters:
  • google_id (str) – The Google hash of the contained person
  • x_pos (int) – The top left x-coord of the bounding box
  • y_pos (int) – The top left y-coord of the bounding box
  • width (int) – The width of the bounding box in pixels
  • height (int) – The height of the bounding box in pixels
Variables:

google_idstr The Google hash of the contact

add_id(id, val)

This is used to add extra linking information to a Image.ContainedPerson. The flickr module uses it to attach the flickr_id as well as the flickr_username.

Before adding your id, it’s probably a good idea to check has_id() first.

Parameters:
  • id – Hashable key
  • val – Any object
Raises :

InvalidState if a non-unique ID is being used

get_id(id)

Return the value associated with an ID or None if that ID does not exist.

Note

A return value of None is not the same as checking the ID for existence. It is entirely possible to have an ID associated with None, which may have some special meaning.

Parameters:id – The key to lookup
Returns:The object stored with the ID or None
has_id(id)

Returns the dict equivalent of key in dict

Returns:True or False
has_position

A Boolean property to determine if the Image.ContainedPerson has a bounding box.

height

Property for getting the height of the bounding box in pixels

width

Property for getting the width of the bounding box in pixels

x_pos

Property for getting the top left x coord for the bounding box

y_pos

Property for getting the top left y coord for the bounding box

Image.add_face(google_id, x_pos=None, y_pos=None, width=None, height=None)
Parameters:
  • google_id (str) – The Google hash of the contained person
  • x_pos (int) – The top left x-coord of the bounding box
  • y_pos (int) – The top left y-coord of the bounding box
  • width (int) – The width of the bounding box in pixels
  • height (int) – The height of the bounding box in pixels
Image.checksum

The psuedo-fingerprint of the image

Image.date_taken

A datetime.datetime based on the DateTimeOriginal field of the exif data

Image.exif

Easy access to the EXIF data for an image

Image.filename

The normalized form of the filename for the image

Image.height

The height of the image in pixels

Image.iptc

Easy access to the IPTC data for an image

Image.path

The absolute directory of the image

Image.people

Get a shallow copy of the people contained in the photo that is safe for modification.

Returns:list of Image.ContainedPerson
Return type:list
Image.width

The width of the image in pixels

py2facer.lib.image.dir_images(path)

Return a list of Image instances for all images in a path

Parameters:path (str) – Path to return image instances for
Returns:list of Image instances
Return type:list

Previous topic

Flickr Module

Next topic

Picasa Module

This Page