# Working with images

The pyglet.image.load function returns an AbstractImage. The actual class of the object depends on the decoder that was used, but all images support the following attributes:

width
  The width of the image, in pixels.
height
  The height of the image, in pixels.
anchor_x
  Distance of the anchor point from the left edge of the image, in pixels
anchor_y
  Distance of the anchor point from the bottom edge of the image, in pixels

The anchor point defaults to (0, 0), though some image formats may contain an intrinsic anchor point. The anchor point is used to align the image to a point in space when drawing it.

You may only want to use a portion of the complete image. You can use the get_region method to return an image of a rectangular region of a source image:

    image_part = kitten.get_region(x=10, y=10, width=100, height=100)

This returns an image with dimensions 100x100. The region extracted from kitten is aligned such that the bottom-left corner of the rectangle is 10 pixels from the left and 10 pixels from the bottom of the image.

Image regions can be used as if they were complete images. Note that changes to an image region may or may not be reflected on the source image, and changes to the source image may or may not be reflected on any region images. You should not assume either behaviour.