Skip to content

Commit

Permalink
Merge pull request #33 from akash-akya/fix-image-headers
Browse files Browse the repository at this point in the history
Correct image header macro
  • Loading branch information
akash-akya authored Mar 8, 2022
2 parents 38c014e + 2213d41 commit bfb1527
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/vix/vips/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -289,26 +289,23 @@ defmodule Vix.Vips.Image do
end

for name <-
~w/width height bands xres yres xoffset yoffset filename mode scale offset page_height n_pages orientation interpretation coding format/ do
func_name = String.to_atom(name)
~w/width height bands xres yres xoffset yoffset filename mode scale offset page-height n-pages orientation interpretation coding format/ do
func_name = name |> String.replace("-", "_") |> String.to_atom()

@doc """
Get #{name} of the the image
Get "#{name}" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-#{String.replace(name, "_", "-")}
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-#{name}
"""
@spec unquote(func_name)(__MODULE__.t()) :: term() | no_return()
def unquote(func_name)(vips_image) do
case header_value(vips_image, normalize_meta(unquote(name))) do
case header_value(vips_image, unquote(name)) do
{:ok, value} -> value
{:error, error} -> raise to_string(error)
end
end
end

defp normalize_meta("n_pages"), do: "n-pages"
defp normalize_meta(meta), do: meta

defp normalize_string(str) when is_binary(str), do: str

defp normalize_string(str) when is_list(str), do: to_string(str)
Expand Down
Binary file added test/images/boats.tif
Binary file not shown.
3 changes: 3 additions & 0 deletions test/vix/vips/image_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ defmodule Vix.Vips.ImageTest do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
assert 518 == Image.width(im)
assert :VIPS_INTERPRETATION_sRGB == Image.interpretation(im)

{:ok, im} = Image.new_from_file(img_path("boats.tif"))
assert 2 == Image.n_pages(im)
end

test "write image to buffer", %{dir: _dir} do
Expand Down

0 comments on commit bfb1527

Please sign in to comment.