From b9c23cd03bccd54be3a4e77c62ffc7730706ac30 Mon Sep 17 00:00:00 2001 From: Eirini Galati Date: Wed, 4 Nov 2026 10:45:31 +0100 Subject: [PATCH] feat: add Format constants for convert media types, release 1.9.0 Adds a Format namespace of media-type string constants so the types accepted by convert() are discoverable via autocomplete, including JPEG XL (image/jxl), which the API already accepts. String constants rather than a language-level enum: the JSON body must carry the media type verbatim, and an enum would serialize as its name. Existing callers passing raw strings are unaffected. JPG documents image/jpg as the alternative spelling the API also accepts. It normalises to image/jpeg before conversion, so the two constants hold different strings but select the same format. Bumps to 1.9.0 and promotes the changelog entry out of Unreleased. The change is additive, so this is a minor release; nothing is published until the matching tag is pushed. --- CHANGES.md | 4 ++ pom.xml | 2 +- src/main/java/com/tinify/Format.java | 50 ++++++++++++++++++++++++ src/test/java/com/tinify/FormatTest.java | 34 ++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/tinify/Format.java create mode 100644 src/test/java/com/tinify/FormatTest.java diff --git a/CHANGES.md b/CHANGES.md index 2d078e7..6bef7ca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +## 1.9.0 + +* Added `Format` constants for the media types `convert` accepts, including JPEG XL (`image/jxl`). + ## 1.8.9 * Upgraded dependencies (okio 3.12.0, gson 2.13.1, commons-codec 1.21.0) * Upgraded all Maven plugins to latest stable versions diff --git a/pom.xml b/pom.xml index caf2d10..b5fbaec 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.tinify tinify - 1.8.9 + 1.9.0 Tinify Java client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com. https://tinify.com diff --git a/src/main/java/com/tinify/Format.java b/src/main/java/com/tinify/Format.java new file mode 100644 index 0000000..8d2186a --- /dev/null +++ b/src/main/java/com/tinify/Format.java @@ -0,0 +1,50 @@ +package com.tinify; + +/** + * Media types that images can be converted to. + * + *

Use these constants with {@link Source#convert(Options)}: + * + *

{@code
+ * Tinify.fromFile("input.png")
+ *       .convert(new Options().with("type", Format.JXL))
+ *       .toFile("output.jxl");
+ * }
+ * + *

Multiple types may be supplied, in which case the API returns the + * smallest result: + * + *

{@code
+ * new Options().with("type", new String[]{Format.JXL, Format.WEBP});
+ * }
+ */ +public final class Format { + /** WebP, {@code image/webp}. */ + public static final String WEBP = "image/webp"; + + /** PNG, {@code image/png}. */ + public static final String PNG = "image/png"; + + /** JPEG, {@code image/jpeg}. */ + public static final String JPEG = "image/jpeg"; + + /** + * JPEG, under the alternative {@code image/jpg} media type the API also + * accepts. The API normalises this to {@code image/jpeg}, so the result is + * identical to {@link #JPEG}. The two constants hold different strings but + * select the same format. + */ + public static final String JPG = "image/jpg"; + + /** AVIF, {@code image/avif}. */ + public static final String AVIF = "image/avif"; + + /** JPEG XL, {@code image/jxl}. */ + public static final String JXL = "image/jxl"; + + /** Wildcard, {@code */*}. Returns the smallest of the supported types. */ + public static final String ANY = "*/*"; + + private Format() { + } +} diff --git a/src/test/java/com/tinify/FormatTest.java b/src/test/java/com/tinify/FormatTest.java new file mode 100644 index 0000000..acd94eb --- /dev/null +++ b/src/test/java/com/tinify/FormatTest.java @@ -0,0 +1,34 @@ +package com.tinify; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.equalTo; + +public class FormatTest { + @Test + public void formatShouldExposeSupportedMediaTypes() { + assertThat(Format.WEBP, is(equalTo("image/webp"))); + assertThat(Format.PNG, is(equalTo("image/png"))); + assertThat(Format.JPEG, is(equalTo("image/jpeg"))); + assertThat(Format.JPG, is(equalTo("image/jpg"))); + assertThat(Format.AVIF, is(equalTo("image/avif"))); + assertThat(Format.JXL, is(equalTo("image/jxl"))); + assertThat(Format.ANY, is(equalTo("*/*"))); + } + + @Test + public void convertWithFormatShouldSerializeMediaType() { + Options options = new Options().with("convert", new Options().with("type", Format.JXL)); + assertThat(options.toJson(), is(equalTo("{\"convert\":{\"type\":\"image/jxl\"}}"))); + } + + @Test + public void convertWithMultipleFormatsShouldSerializeMediaTypes() { + Options options = new Options().with("convert", + new Options().with("type", new String[]{Format.JXL, Format.WEBP})); + assertThat(options.toJson(), + is(equalTo("{\"convert\":{\"type\":[\"image/jxl\",\"image/webp\"]}}"))); + } +}