diff options
| author | Fuwn <[email protected]> | 2024-05-14 22:27:00 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-05-14 22:27:00 +0000 |
| commit | 51c9a8fadb2ef5647d55a0323a7761b72416031e (patch) | |
| tree | c4687a4e4e59941aafd28ef8dde6af0d6d376c78 /src/image.gleam | |
| parent | fix(database): use sqlite timestamp format (diff) | |
| download | mayu-0.1.3.tar.xz mayu-0.1.3.zip | |
refactor(image): deduce extension from informationv0.1.3
Diffstat (limited to 'src/image.gleam')
| -rw-r--r-- | src/image.gleam | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/image.gleam b/src/image.gleam index 6672b46..c1ba7cf 100644 --- a/src/image.gleam +++ b/src/image.gleam @@ -1,10 +1,10 @@ import gleam/int -pub type ImageDimensions { - ImageDimensions(width: Int, height: Int) +pub type ImageInformation { + ImageInformation(width: Int, height: Int, extension: String) } -pub fn get_image_dimensions(image) { +pub fn get_image_information(image) { case image { <<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, _:bits>> -> parse_png_chunks(image, 8) @@ -20,7 +20,7 @@ pub fn get_image_dimensions(image) { height_1:8, _rest:bits, >> -> - Ok(ImageDimensions( + Ok(ImageInformation( width_0 |> int.bitwise_or( width_1 @@ -31,6 +31,7 @@ pub fn get_image_dimensions(image) { height_1 |> int.bitwise_shift_left(8), ), + "gif", )) _ -> Error("Invalid PNG signature") } @@ -47,7 +48,7 @@ fn parse_png_chunks(image, offset) { width:32, height:32, _:bits, - >> -> Ok(ImageDimensions(width, height)) + >> -> Ok(ImageInformation(width, height, "png")) <<_:size(offset), length:32, _:4, _:bits>> -> parse_png_chunks(image, offset + length + 12) _ -> Error("Invalid PNG chunk") |