Is it possible to edit images programmatically with the Blender API?
Within blender's image class you can access the raw pixel data at image.pixels as an array of floats, 4 floats per pixel (RGBA). image.size[0] is the width in pixels image.size[1] for height.

This answer shows how to crop an image, while this one about performance might be useful.