Skip to main content

get_image_dimensions

Return the (width, height) of an image, given an open file or a path. Set 'close' to True to close the file at the end if it is initially in an open state.

def get_image_dimensions(
file_or_path: file-like object or string,
close: boolean = False
) - > tuple

Return the (width, height) of an image, given an open file or a path. Set 'close' to True to close the file at the end if it is initially in an open state.

Parameters

NameTypeDescription
file_or_pathfile-like object or stringAn open file-like object or a filesystem path to the image file to be analyzed.
closeboolean = FalseWhether to close the file after reading; if False and a file-like object was provided, the file pointer is reset to its original position.

Returns

TypeDescription
tupleA tuple containing (width, height) in pixels, or (None, None) if the dimensions could not be determined or the file is invalid.