Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-akya committed Jan 3, 2025
1 parent e3f0c06 commit 21f0609
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions test/vix/vips/image_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,45 @@ defmodule Vix.Vips.ImageTest do
assert File.read!(img_buf_out_path) == File.read!(img_file_out_path)
end

test "write_to_file", %{dir: dir} do
path = img_path("puppies.jpg")
describe "write_to_file" do
test "write_to_file", %{dir: dir} do
path = img_path("puppies.jpg")

{:ok, %Image{ref: ref} = im} = Image.new_from_file(path)
assert is_reference(ref)
{:ok, %Image{ref: ref} = im} = Image.new_from_file(path)
assert is_reference(ref)

out_path = Temp.path!(suffix: ".png", basedir: dir)
assert :ok == Image.write_to_file(im, out_path)
out_path = Temp.path!(suffix: ".png", basedir: dir)
assert :ok == Image.write_to_file(im, out_path)

stat = File.stat!(out_path)
assert stat.size > 0 and stat.type == :regular
stat = File.stat!(out_path)
assert stat.size > 0 and stat.type == :regular
end

test "write_to_file supports optional arguments", %{dir: dir} do
{:ok, img} = Image.new_from_file(img_path("puppies.jpg"))

out_path1 = Temp.path!(suffix: ".png", basedir: dir)
assert :ok = Image.write_to_file(img, out_path1, compression: 0)

out_path2 = Temp.path!(suffix: ".png", basedir: dir)
assert :ok = Image.write_to_file(img, out_path2, compression: 9)

# currently I only found this option to be verifiable easily!
assert File.stat!(out_path1).size > File.stat!(out_path2).size
end

test "write_to_file supports optional options suffix", %{dir: dir} do
{:ok, img} = Image.new_from_file(img_path("puppies.jpg"))

out_path1 = Temp.path!(suffix: ".png", basedir: dir)
assert :ok = Image.write_to_file(img, out_path1 <> "[compression=0]")

out_path2 = Temp.path!(suffix: ".png", basedir: dir)
assert :ok = Image.write_to_file(img, out_path2 <> "[compression=9]")

# currently I only found this option to be verifiable easily!
assert File.stat!(out_path1).size > File.stat!(out_path2).size
end
end

test "new_matrix_from_array", %{dir: _dir} do
Expand Down

0 comments on commit 21f0609

Please sign in to comment.