-module(ansel@image). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([from_bit_array/1, to_bit_array/2, new/3, extract_area/2, composite_over/4, fill/3, outline/4, blur/2, rotate/2, round/2, get_width/1, get_height/1, fit_bounding_box/2, border/3, to_bounding_box/1, scale/2, scale_width/2, scale_height/2, write/3, read/1, create_thumbnail/2]). -export_type([image_format/0]). -type image_format() :: {jpeg, integer(), boolean()} | {jpeg2000, integer(), boolean()} | {jpegxl, integer(), boolean()} | png | {web_p, integer(), boolean()} | {avif, integer(), boolean()} | {tiff, integer(), boolean()} | {heic, integer(), boolean()} | fits | matlab | pdf | svg | hdr | ppm | csv | gif | analyze | n_if_ti | deep_zoom | {custom, binary()}. -file("/home/john/Repos/ansel/src/ansel/image.gleam", 101). -spec format_common_options(integer(), boolean()) -> binary(). format_common_options(Quality, Keep_metadata) -> <<<<<<<<"[Q="/utf8, (gleam@int:to_string(Quality))/binary>>/binary, ",strip="/utf8>>/binary, (begin _pipe = gleam@bool:to_string(not Keep_metadata), gleam@string:lowercase(_pipe) end)/binary>>/binary, "]"/utf8>>. -file("/home/john/Repos/ansel/src/ansel/image.gleam", 69). -spec image_format_to_string(image_format()) -> binary(). image_format_to_string(Format) -> case Format of {jpeg, Quality, Keep_metadata} -> <<".jpeg"/utf8, (format_common_options(Quality, Keep_metadata))/binary>>; {jpeg2000, Quality@1, Keep_metadata@1} -> <<".jp2"/utf8, (format_common_options(Quality@1, Keep_metadata@1))/binary>>; {jpegxl, Quality@2, Keep_metadata@2} -> <<".jxl"/utf8, (format_common_options(Quality@2, Keep_metadata@2))/binary>>; png -> <<".png"/utf8>>; {web_p, Quality@3, Keep_metadata@3} -> <<".webp"/utf8, (format_common_options(Quality@3, Keep_metadata@3))/binary>>; {avif, Quality@4, Keep_metadata@4} -> <<".avif"/utf8, (format_common_options(Quality@4, Keep_metadata@4))/binary>>; {tiff, Quality@5, Keep_metadata@5} -> <<".tiff"/utf8, (format_common_options(Quality@5, Keep_metadata@5))/binary>>; {heic, Quality@6, Keep_metadata@6} -> <<".heic"/utf8, (format_common_options(Quality@6, Keep_metadata@6))/binary>>; fits -> <<".fits"/utf8>>; matlab -> <<".mat"/utf8>>; pdf -> <<".pdf"/utf8>>; svg -> <<".svg"/utf8>>; hdr -> <<".hdr"/utf8>>; ppm -> <<".ppm"/utf8>>; csv -> <<".csv"/utf8>>; gif -> <<".gif"/utf8>>; analyze -> <<".analyze"/utf8>>; n_if_ti -> <<".nii"/utf8>>; deep_zoom -> <<".dzi"/utf8>>; {custom, Format@1} -> Format@1 end. -file("/home/john/Repos/ansel/src/ansel/image.gleam", 151). -spec from_bit_array(bitstring()) -> {ok, ansel:image()} | {error, snag:snag()}. from_bit_array(Bin) -> _pipe = 'Elixir.Vix.Vips.Image':new_from_buffer(Bin), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to read image from bit array"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 169). -spec to_bit_array(ansel:image(), image_format()) -> bitstring(). to_bit_array(Img, Format) -> 'Elixir.Ansel':to_bit_array(Img, image_format_to_string(Format)). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 183). -spec new(integer(), integer(), ansel@color:color()) -> {ok, ansel:image()} | {error, snag:snag()}. new(Width, Height, Color) -> _pipe = 'Elixir.Ansel':new_image(Width, Height, ansel@color:to_bands(Color)), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to create new image"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 202). -spec extract_area(ansel:image(), ansel@bounding_box:bounding_box()) -> {ok, ansel:image()} | {error, snag:snag()}. extract_area(Image, Bounding_box) -> {Left, Top, Width, Height} = ansel@bounding_box:to_ltwh_tuple(Bounding_box), _pipe = 'Elixir.Vix.Vips.Operation':extract_area( Image, Left, Top, Width, Height ), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to extract area from image"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 224). -spec composite_over(ansel:image(), ansel:image(), integer(), integer()) -> {ok, ansel:image()} | {error, snag:snag()}. composite_over(Base, Overlay, L, T) -> _pipe = 'Elixir.Ansel':composite_over(Base, Overlay, L, T), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context( _pipe@1, <<"Unable to composite overlay image over base image"/utf8>> ). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 244). -spec fill( ansel:image(), ansel@bounding_box:bounding_box(), ansel@color:color() ) -> {ok, ansel:image()} | {error, snag:snag()}. fill(Image, Bounding_box, Color) -> {Left, Top, Width, Height} = ansel@bounding_box:to_ltwh_tuple(Bounding_box), _pipe = new(Width, Height, Color), gleam@result:'try'( _pipe, fun(_capture) -> composite_over(Image, _capture, Left, Top) end ). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 257). -spec outline( ansel:image(), ansel@bounding_box:bounding_box(), ansel@color:color(), integer() ) -> {ok, ansel:image()} | {error, snag:snag()}. outline(Image, Bounding_box, Color, Thickness) -> {Left, Top, Width, Height} = ansel@bounding_box:to_ltwh_tuple(Bounding_box), Original_bb = begin _pipe = Bounding_box, ansel@bounding_box:shrink(_pipe, Thickness) end, gleam@result:'try'( new(Width, Height, Color), fun(Outline) -> gleam@result:'try'( composite_over(Image, Outline, Left, Top), fun(Filled) -> case Original_bb of {ok, Original_bb@1} -> {Original_left, Original_top, _, _} = ansel@bounding_box:to_ltwh_tuple( Original_bb@1 ), gleam@result:'try'( extract_area(Image, Original_bb@1), fun(Original_area) -> composite_over( Filled, Original_area, Original_left, Original_top ) end ); {error, nil} -> {ok, Filled} end end ) end ). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 318). -spec blur(ansel:image(), float()) -> {ok, ansel:image()} | {error, snag:snag()}. blur(Image, Sigma) -> _pipe = 'Elixir.Vix.Vips.Operation':gaussblur(Image, Sigma), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to blur image"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 331). -spec rotate(ansel:image(), float()) -> {ok, ansel:image()} | {error, snag:snag()}. rotate(Image, Degrees) -> _pipe = case Degrees of +0.0 -> {ok, Image}; 90.0 -> 'Elixir.Ansel':rotate90(Image); 180.0 -> 'Elixir.Ansel':rotate180(Image); 270.0 -> 'Elixir.Ansel':rotate270(Image); _ -> 'Elixir.Vix.Vips.Operation':rotate(Image, Degrees) end, _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to rotate image"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 365). -spec round(ansel:image(), float()) -> {ok, ansel:image()} | {error, snag:snag()}. round(Image, Radius) -> _pipe = 'Elixir.Ansel':round(Image, Radius), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to round image"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 379). -spec get_width(ansel:image()) -> integer(). get_width(Image) -> 'Elixir.Vix.Vips.Image':width(Image). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 383). -spec get_height(ansel:image()) -> integer(). get_height(Image) -> 'Elixir.Vix.Vips.Image':height(Image). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 120). -spec fit_bounding_box(ansel@bounding_box:bounding_box(), ansel:image()) -> {ok, ansel@bounding_box:bounding_box()} | {error, snag:snag()}. fit_bounding_box(Bounding_box, Image) -> Width = 'Elixir.Vix.Vips.Image':width(Image), Height = 'Elixir.Vix.Vips.Image':height(Image), {Left, Top, Right, Bottom} = ansel@bounding_box:to_ltrb_tuple(Bounding_box), case {Left < Width, Top < Height} of {true, true} -> ansel@bounding_box:ltrb( Left, Top, gleam@int:min(Right, Width), gleam@int:min(Bottom, Height) ); {_, _} -> snag:error( <<"Passed bounding box is completely outside the image to fit"/utf8>> ) end. -file("/home/john/Repos/ansel/src/ansel/image.gleam", 299). -spec border(ansel:image(), ansel@color:color(), integer()) -> {ok, ansel:image()} | {error, snag:snag()}. border(Image, Color, Thickness) -> Height = 'Elixir.Vix.Vips.Image':height(Image), Width = 'Elixir.Vix.Vips.Image':width(Image), gleam@result:'try'( begin _pipe = ansel@bounding_box:ltwh(0, 0, Width, Height), _pipe@1 = gleam@result:map( _pipe, fun(_capture) -> ansel@bounding_box:expand(_capture, Thickness) end ), gleam@result:map(_pipe@1, fun ansel@bounding_box:to_ltwh_tuple/1) end, fun(_use0) -> {_, _, Outline_width, Outline_height} = _use0, _pipe@2 = new(Outline_width, Outline_height, Color), gleam@result:'try'( _pipe@2, fun(_capture@1) -> composite_over(_capture@1, Image, Thickness, Thickness) end ) end ). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 387). -spec to_bounding_box(ansel:image()) -> ansel@bounding_box:bounding_box(). to_bounding_box(Image) -> ansel@bounding_box:unchecked_ltwh( 0, 0, 'Elixir.Vix.Vips.Image':width(Image), 'Elixir.Vix.Vips.Image':height(Image) ). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 413). -spec scale(ansel:image(), float()) -> {ok, ansel:image()} | {error, snag:snag()}. scale(Img, Scale) -> _pipe = 'Elixir.Vix.Vips.Operation':resize(Img, Scale), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to resize image"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 397). -spec scale_width(ansel:image(), integer()) -> {ok, ansel:image()} | {error, snag:snag()}. scale_width(Img, Target) -> scale(Img, case gleam@int:to_float('Elixir.Vix.Vips.Image':width(Img)) of +0.0 -> +0.0; -0.0 -> -0.0; Gleam@denominator -> gleam@int:to_float(Target) / Gleam@denominator end). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 405). -spec scale_height(ansel:image(), integer()) -> {ok, ansel:image()} | {error, snag:snag()}. scale_height(Img, Target) -> scale(Img, case gleam@int:to_float('Elixir.Vix.Vips.Image':height(Img)) of +0.0 -> +0.0; -0.0 -> -0.0; Gleam@denominator -> gleam@int:to_float(Target) / Gleam@denominator end). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 426). -spec write(ansel:image(), binary(), image_format()) -> {ok, nil} | {error, snag:snag()}. write(Img, Path, Format) -> _pipe = 'Elixir.Ansel':write_to_file( Img, <> ), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to write image to file"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 440). -spec read(binary()) -> {ok, ansel:image()} | {error, snag:snag()}. read(Path) -> _pipe = 'Elixir.Ansel':read(Path), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to read image from file"/utf8>>). -file("/home/john/Repos/ansel/src/ansel/image.gleam", 450). -spec create_thumbnail(binary(), integer()) -> {ok, ansel:image()} | {error, snag:snag()}. create_thumbnail(Path, Width) -> _pipe = 'Elixir.Vix.Vips.Operation':thumbnail(Path, Width), _pipe@1 = gleam@result:map_error(_pipe, fun snag:new/1), snag:context(_pipe@1, <<"Unable to create thumbnail from file"/utf8>>).