diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aca6d3..8ebd934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Image 0.54.0 -This is the changelog for Image version 0.54.0 released on ____, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-image/image/tags) +This is the changelog for Image version 0.54.0 released on July 24th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-image/image/tags) ### Bug Fixes @@ -10,6 +10,8 @@ This is the changelog for Image version 0.54.0 released on ____, 2024. For olde * Fix `Image.get_pixel/3` to ensure only integer values are returned when the image band format is integer. This is required because the underlying `Vix.Vips.Operation.getpoint/3` always returns floats. +* Fix using `Image.open/2` with binary HEIC files. HEIC magic numbers are now used to identify if a binary is an HEIC image (as is already done for other image types). + ### Enhancements * Adds `Image.vibrance/3` and `Image.vibrance!/3` following the [libvips discussion](https://github.com/libvips/libvips/discussions/4039). diff --git a/lib/image.ex b/lib/image.ex index ec68974..156cdc5 100644 --- a/lib/image.ex +++ b/lib/image.ex @@ -757,6 +757,21 @@ defmodule Image do from_binary(image, options) end + # 'heic': the usual HEIF images + # 'heix': 10bit images, or anything that uses h265 with range extension + # 'hevc', 'hevx': brands for image sequences + # 'heim': multiview + # 'heis': scalable + # 'hevm': multiview sequence + # 'hevs': sc + + @heic_types ["heic", "heix", "hevc", "hevx", "heim", "heis", "hevm", "hevs", "mif1"] + + def open(<<_::bytes-4, "ftyp", type::bytes-4, _rest::binary>> = image, options) + when type in @heic_types do + from_binary(image, options) + end + # A file path def open(image_path, options) when is_binary(image_path) do with {:ok, options} <- Options.Open.validate_options(options) do diff --git a/test/image_test.exs b/test/image_test.exs index 50613e6..524507e 100644 --- a/test/image_test.exs +++ b/test/image_test.exs @@ -327,4 +327,9 @@ defmodule Image.Test do joined = Image.join_bands!(bands) assert {:ok, +0.0, _} = Image.compare(image, joined) end + + test "Opening an HEIC binary" do + heic = File.read!("./test/support/images/sample1.heic") + assert {:ok, _image} = Image.open(heic) + end end diff --git a/test/support/images/sample1.heic b/test/support/images/sample1.heic new file mode 100644 index 0000000..00cc549 Binary files /dev/null and b/test/support/images/sample1.heic differ