HeifFile object¶
The HeifFile provide all necessary methods for HEIF image manipulations.
- class pillow_heif.HeifFile(fp=None, convert_hdr_to_8bit=True, bgr_mode=False, **kwargs)[source]¶
Representation of the
HeifImageclasses container.To create
HeifFileobject, use the appropriate factory functions.- Exceptions that can be raised when working with methods:
ValueError, EOFError, SyntaxError, RuntimeError, OSError
- property size¶
sizeproperty of the primaryHeifImage.- Raises:
IndexError – If there are no images.
- property mode¶
modeproperty of the primaryHeifImage.- Raises:
IndexError – If there are no images.
- property has_alpha¶
has_alphaproperty of the primaryHeifImage.- Raises:
IndexError – If there are no images.
- property premultiplied_alpha¶
premultiplied_alphaproperty of the primaryHeifImage.- Raises:
IndexError – If there are no images.
- property data¶
dataproperty of the primaryHeifImage.- Raises:
IndexError – If there are no images.
- property stride¶
strideproperty of the primaryHeifImage.- Raises:
IndexError – If there are no images.
- property info¶
info` dict of the primary
HeifImagein the container.- Raises:
IndexError – If there are no images.
- to_pillow() Image[source]¶
Helper method to create Pillow
Image.- Returns:
Imageclass created from the primary image.
- save(fp, **kwargs) None[source]¶
Saves image(s) under the given fp.
Keyword options can be used to provide additional instructions to the writer. If a writer does not recognize an option, it is silently ignored.
- Supported options:
save_all- boolean. Should all images fromHeiFilebe saved? (default =True)append_images- do the same as in Pillow. Accepts the list ofHeifImageNote
Appended images always will have
info["primary"]=Falsequality- seeQUALITYenc_params- dictionary with key:value to pass to x265 encoder.exif- override primary image’s EXIF with specified. AcceptsNone,bytesorPIL.Image.Exifclass.xmp- override primary image’s XMP with specified. AcceptsNoneorbytes.primary_index- ignoreinfo["primary"]and set PrimaryImage by index.chroma- custom subsampling value. Possible values:444,422or420(x265default).subsampling- synonym for chroma. Format is string, compatible with Pillow:x:x:x, e.g. ‘4:4:4’.save_nclx_profile- boolean, seeSAVE_NCLX_PROFILEmatrix_coefficients- int, nclx profile: color conversion matrix coefficients, default=6 (see h.273)color_primaries- int, nclx profile: color primaries (see h.273)transfer_characteristic- int, nclx profile: transfer characteristics (see h.273)full_range_flag- nclx profile: full range flag, default: 1
- Parameters:
fp – A filename (string), pathlib.Path object or an object with write method.
- add_frombytes(mode: str, size: tuple[int, int], data, **kwargs)[source]¶
Adds image from bytes to container.
Note
Supports
stridevalue if needed.
- get_aux_image(aux_id)[source]¶
get_aux_image` method of the primary
HeifImagein the container.- Raises:
IndexError – If there are no images.