def getCropRect(d, prefix=''):
    """Returns the crop rect as (x0, y0, x1, y1) from the given dictionary of tags.
    Assumes tags are named 'CROP_RECT_TOP_LEFT_{X,Y} and CROP_RECT_{WIDTH,HEIGHT}.
    You can give an optional prefix if you want (e.g., ACTUAL_).
    On error, returns None"""
    try:
        x0 = int(d[prefix+'CROP_RECT_TOP_LEFT_X'])
        y0 = int(d[prefix+'CROP_RECT_TOP_LEFT_Y'])
        w = int(d[prefix+'CROP_RECT_WIDTH'])
        h = int(d[prefix+'CROP_RECT_HEIGHT'])
        return (x0, y0, x0+w, y0+h)
    except KeyError:
        return None