Skip to content

Commit

Permalink
Resolves #51 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 authored Nov 25, 2022
1 parent 7c10777 commit 0c205fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pillow_heif/heif.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,17 +666,18 @@ def save(self, fp, **kwargs) -> None:
(default = ``True``)
``append_images`` - do the same as in Pillow.
Accept ``HeifFile``, ``HeifImage`` and ``PIL.Image``
Accepts ``HeifFile``, ``HeifImage`` and ``PIL.Image``
.. note:: Appended images always will have ``info["primary"]=False``
``quality`` - see :py:attr:`~pillow_heif._options.PyLibHeifOptions.quality`
``enc_params`` - dictionary with key:value to pass to :ref:`x265 <hevc-encoder>` encoder.
``exif`` - override primary image's EXIF with specified. Accept ``None`` or ``bytes``.
``exif`` - override primary image's EXIF with specified.
Accepts ``None``, ``bytes`` or ``PIL.Image.Exif`` class.
``xmp`` - override primary image's XMP with specified. Accept ``None`` or ``bytes``.
``xmp`` - override primary image's XMP with specified. Accepts ``None`` or ``bytes``.
``primary_index`` - ignore ``info["primary"]`` and set `PrimaryImage` by index.
Expand Down Expand Up @@ -772,6 +773,8 @@ def _save(ctx: LibHeifCtxWrite, img_list: List[HeifImage], primary_index: int, *
lib.heif_context_set_primary_image(ctx.ctx, new_img_handle)
if kwargs.get("exif", -1) != -1:
exif = kwargs["exif"]
if isinstance(exif, Image.Exif):
exif = exif.tobytes()
if kwargs.get("xmp", -1) != -1:
xmp = kwargs["xmp"]
set_exif(ctx, new_img_handle, exif)
Expand Down
15 changes: 15 additions & 0 deletions tests/metadata_exif_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,18 @@ def test_corrupted_exif():
with pytest.raises(SyntaxError):
im.getexif()
assert im.info["exif"] == exif_data


@pytest.mark.skipif(not helpers.hevc_enc(), reason="Requires HEVC encoder.")
def test_exif_as_class():
exif = Image.Exif()
exif[258] = 8
exif[40963] = 455
exif[305] = "exif test"
out_im = BytesIO()
helpers.gradient_rgb().save(out_im, format="HEIF", exif=exif)
im = Image.open(out_im)
exif = im.getexif()
assert exif[258] == 8
assert exif[40963] == 455
assert exif[305] == "exif test"

0 comments on commit 0c205fd

Please sign in to comment.