From 7e7050d30e8f48f1a805fdfc34a679fe8696db5d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 23 Jul 2024 13:53:02 +0530 Subject: [PATCH] DRYer --- tools/utils/images/convert.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tools/utils/images/convert.go b/tools/utils/images/convert.go index b108f685e..901155259 100644 --- a/tools/utils/images/convert.go +++ b/tools/utils/images/convert.go @@ -57,21 +57,15 @@ func convert_image(input io.ReadSeeker, output io.Writer, format string) (err er return fmt.Errorf("Image has no frames") } img := image_data.Frames[0].Img - switch strings.ToUpper(format) { - case "RGBA": + q := strings.ToLower(format) + if q == "rgba" { return encode_rgba(output, img) - case "JPEG", "JPG": - return Encode(output, img, "image/jpeg") - case "PNG": - return Encode(output, img, "image/png") - case "GIF": - return Encode(output, img, "image/gif") - case "BMP": - return Encode(output, img, "image/bmp") - case "TIFF": - return Encode(output, img, "image/tiff") } - return fmt.Errorf("Unknown image output format: %s", format) + mt := utils.GuessMimeType("file." + q) + if mt == "" { + return fmt.Errorf("Unknown image output format: %s", format) + } + return Encode(output, img, mt) } func ConvertEntryPoint(root *cli.Command) {