Skip to content

Commit be34f7a

Browse files
JonasGruenwaldjrstrunk
authored andcommitted
adjust custom image format syntax, document, and test
1 parent 5a2cf99 commit be34f7a

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/ansel/image.gleam

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ import snag
4242
/// own vips binary on the host system to. See the package readme for details.
4343
///
4444
/// The `Custom` constructor allows for advanced vips save options to be
45-
/// used, like `ansel.Custom(".png", "[compression=90,squash=true]")`, refer to the
46-
/// [Vix package documentation](https://hexdocs.pm/vix/Vix.Vips.Image.html#write_to_file/2)
47-
/// for details.
45+
/// used as a comma separated list, like `ansel.Custom(".png", "compression=90,squash=true")`,
46+
/// which is equivalent to the `.png[compression=90,squash=true]` syntax used in vips.
47+
///
48+
/// You can use the libvips CLI to print a list of all supported options for each image format,
49+
/// e.g. `vips pngsave`, `vips jpegsave`.
4850
pub type ImageFormat {
4951
JPEG(quality: Int, keep_metadata: Bool)
5052
JPEG2000(quality: Int, keep_metadata: Bool)
@@ -100,7 +102,8 @@ fn image_format_to_string(format: ImageFormat) -> FormatComponents {
100102
Analyze -> FormatComponents(".analyze", "")
101103
NIfTI -> FormatComponents(".nii", "")
102104
DeepZoom -> FormatComponents(".dzi", "")
103-
Custom(extension:, format:) -> FormatComponents(extension, format)
105+
Custom(extension:, format:) ->
106+
FormatComponents(extension, "[" <> format <> "]")
104107
}
105108
}
106109

test/image_test.gleam

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ pub fn write_test() {
4444
let assert Ok(_) = simplifile.delete(output_path)
4545
}
4646

47+
pub fn custom_options_test() {
48+
let assert Ok(reference_image) = image.new(6, 6, color.Grey)
49+
let output =
50+
reference_image
51+
|> image.to_bit_array(image.JPEG(quality: 50, keep_metadata: True))
52+
53+
reference_image
54+
|> image.to_bit_array(image.Custom(".jpeg", "Q=50,strip=false"))
55+
|> should.equal(output)
56+
}
57+
4758
pub fn new_solid_grey_test() {
4859
let assert Ok(bin) =
4960
simplifile.read_bits("test/resources/solid_grey_6x6.avif")

0 commit comments

Comments
 (0)