Skip to content

Commit 183b131

Browse files
feat(api): add no-enlarge crop modes and colorize transformation
- Add `maintain_ratio_no_enlarge` to `crop` enum - Add `pad_resize_no_enlarge` and `pad_extract_no_shrink` to `cropMode` enum - Add `colorize` transformation parameter for applying color tints
1 parent 4c8865c commit 183b131

8 files changed

Lines changed: 84 additions & 3 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 47
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc/imagekit-362d0336e8f52ab1beb7d9602a3665dbb0277700e8dc01ef4f96fc7651699349.yml
3-
openapi_spec_hash: f0d797a17b1e8e81707517700cd44b13
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc/imagekit-ad6dd3b4acf289708568a12574b997503059a47c4a4ca5ffefe64f40f3d3dbf3.yml
3+
openapi_spec_hash: 7c103e2dff0edcbeea82057e62f58d4d
44
config_hash: 94f48fd13b7d41b8b6a203a3a8cee9ed

image-kit-java-core/src/main/kotlin/io/imagekit/models/Transformation.kt

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private constructor(
5353
private val background: JsonField<String>,
5454
private val blur: JsonField<Double>,
5555
private val border: JsonField<String>,
56+
private val colorize: JsonField<String>,
5657
private val colorProfile: JsonField<Boolean>,
5758
private val colorReplace: JsonField<String>,
5859
private val contrastStretch: JsonField<ContrastStretch>,
@@ -132,6 +133,7 @@ private constructor(
132133
background: JsonField<String> = JsonMissing.of(),
133134
@JsonProperty("blur") @ExcludeMissing blur: JsonField<Double> = JsonMissing.of(),
134135
@JsonProperty("border") @ExcludeMissing border: JsonField<String> = JsonMissing.of(),
136+
@JsonProperty("colorize") @ExcludeMissing colorize: JsonField<String> = JsonMissing.of(),
135137
@JsonProperty("colorProfile")
136138
@ExcludeMissing
137139
colorProfile: JsonField<Boolean> = JsonMissing.of(),
@@ -209,6 +211,7 @@ private constructor(
209211
background,
210212
blur,
211213
border,
214+
colorize,
212215
colorProfile,
213216
colorReplace,
214217
contrastStretch,
@@ -399,6 +402,17 @@ private constructor(
399402
*/
400403
fun border(): Optional<String> = border.getOptional("border")
401404

405+
/**
406+
* Applies a color tint to the image. Accepts color and intensity as optional parameters.
407+
* - `co-color` - Color to apply (e.g., `red`, `blue`, `FF0022`). Default is gray color.
408+
* - `in-intensity` - Intensity of the color (0-100). Default is 35. See
409+
* [Colorize](https://imagekit.io/docs/effects-and-enhancements#colorize---e-colorize).
410+
*
411+
* @throws ImageKitInvalidDataException if the JSON field has an unexpected type (e.g. if the
412+
* server responded with an unexpected value).
413+
*/
414+
fun colorize(): Optional<String> = colorize.getOptional("colorize")
415+
402416
/**
403417
* Indicates whether the output image should retain the original color profile. See
404418
* [Color profile](https://imagekit.io/docs/image-optimization#color-profile---cp).
@@ -932,6 +946,13 @@ private constructor(
932946
*/
933947
@JsonProperty("border") @ExcludeMissing fun _border(): JsonField<String> = border
934948

949+
/**
950+
* Returns the raw JSON value of [colorize].
951+
*
952+
* Unlike [colorize], this method doesn't throw if the JSON field has an unexpected type.
953+
*/
954+
@JsonProperty("colorize") @ExcludeMissing fun _colorize(): JsonField<String> = colorize
955+
935956
/**
936957
* Returns the raw JSON value of [colorProfile].
937958
*
@@ -1273,6 +1294,7 @@ private constructor(
12731294
private var background: JsonField<String> = JsonMissing.of()
12741295
private var blur: JsonField<Double> = JsonMissing.of()
12751296
private var border: JsonField<String> = JsonMissing.of()
1297+
private var colorize: JsonField<String> = JsonMissing.of()
12761298
private var colorProfile: JsonField<Boolean> = JsonMissing.of()
12771299
private var colorReplace: JsonField<String> = JsonMissing.of()
12781300
private var contrastStretch: JsonField<ContrastStretch> = JsonMissing.of()
@@ -1331,6 +1353,7 @@ private constructor(
13311353
background = transformation.background
13321354
blur = transformation.blur
13331355
border = transformation.border
1356+
colorize = transformation.colorize
13341357
colorProfile = transformation.colorProfile
13351358
colorReplace = transformation.colorReplace
13361359
contrastStretch = transformation.contrastStretch
@@ -1625,6 +1648,22 @@ private constructor(
16251648
*/
16261649
fun border(border: JsonField<String>) = apply { this.border = border }
16271650

1651+
/**
1652+
* Applies a color tint to the image. Accepts color and intensity as optional parameters.
1653+
* - `co-color` - Color to apply (e.g., `red`, `blue`, `FF0022`). Default is gray color.
1654+
* - `in-intensity` - Intensity of the color (0-100). Default is 35. See
1655+
* [Colorize](https://imagekit.io/docs/effects-and-enhancements#colorize---e-colorize).
1656+
*/
1657+
fun colorize(colorize: String) = colorize(JsonField.of(colorize))
1658+
1659+
/**
1660+
* Sets [Builder.colorize] to an arbitrary JSON value.
1661+
*
1662+
* You should usually call [Builder.colorize] with a well-typed [String] value instead. This
1663+
* method is primarily for setting the field to an undocumented or not yet supported value.
1664+
*/
1665+
fun colorize(colorize: JsonField<String>) = apply { this.colorize = colorize }
1666+
16281667
/**
16291668
* Indicates whether the output image should retain the original color profile. See
16301669
* [Color profile](https://imagekit.io/docs/image-optimization#color-profile---cp).
@@ -2510,6 +2549,7 @@ private constructor(
25102549
background,
25112550
blur,
25122551
border,
2552+
colorize,
25132553
colorProfile,
25142554
colorReplace,
25152555
contrastStretch,
@@ -2583,6 +2623,7 @@ private constructor(
25832623
background()
25842624
blur()
25852625
border()
2626+
colorize()
25862627
colorProfile()
25872628
colorReplace()
25882629
contrastStretch().ifPresent { it.validate() }
@@ -2655,6 +2696,7 @@ private constructor(
26552696
(if (background.asKnown().isPresent) 1 else 0) +
26562697
(if (blur.asKnown().isPresent) 1 else 0) +
26572698
(if (border.asKnown().isPresent) 1 else 0) +
2699+
(if (colorize.asKnown().isPresent) 1 else 0) +
26582700
(if (colorProfile.asKnown().isPresent) 1 else 0) +
26592701
(if (colorReplace.asKnown().isPresent) 1 else 0) +
26602702
(contrastStretch.asKnown().getOrNull()?.validity() ?: 0) +
@@ -4124,6 +4166,8 @@ private constructor(
41244166

41254167
@JvmField val MAINTAIN_RATIO = of("maintain_ratio")
41264168

4169+
@JvmField val MAINTAIN_RATIO_NO_ENLARGE = of("maintain_ratio_no_enlarge")
4170+
41274171
@JvmStatic fun of(value: String) = Crop(JsonField.of(value))
41284172
}
41294173

@@ -4134,6 +4178,7 @@ private constructor(
41344178
AT_MAX_ENLARGE,
41354179
AT_LEAST,
41364180
MAINTAIN_RATIO,
4181+
MAINTAIN_RATIO_NO_ENLARGE,
41374182
}
41384183

41394184
/**
@@ -4151,6 +4196,7 @@ private constructor(
41514196
AT_MAX_ENLARGE,
41524197
AT_LEAST,
41534198
MAINTAIN_RATIO,
4199+
MAINTAIN_RATIO_NO_ENLARGE,
41544200
/** An enum member indicating that [Crop] was instantiated with an unknown value. */
41554201
_UNKNOWN,
41564202
}
@@ -4169,6 +4215,7 @@ private constructor(
41694215
AT_MAX_ENLARGE -> Value.AT_MAX_ENLARGE
41704216
AT_LEAST -> Value.AT_LEAST
41714217
MAINTAIN_RATIO -> Value.MAINTAIN_RATIO
4218+
MAINTAIN_RATIO_NO_ENLARGE -> Value.MAINTAIN_RATIO_NO_ENLARGE
41724219
else -> Value._UNKNOWN
41734220
}
41744221

@@ -4188,6 +4235,7 @@ private constructor(
41884235
AT_MAX_ENLARGE -> Known.AT_MAX_ENLARGE
41894236
AT_LEAST -> Known.AT_LEAST
41904237
MAINTAIN_RATIO -> Known.MAINTAIN_RATIO
4238+
MAINTAIN_RATIO_NO_ENLARGE -> Known.MAINTAIN_RATIO_NO_ENLARGE
41914239
else -> throw ImageKitInvalidDataException("Unknown Crop: $value")
41924240
}
41934241

@@ -4278,6 +4326,10 @@ private constructor(
42784326

42794327
@JvmField val PAD_EXTRACT = of("pad_extract")
42804328

4329+
@JvmField val PAD_RESIZE_NO_ENLARGE = of("pad_resize_no_enlarge")
4330+
4331+
@JvmField val PAD_EXTRACT_NO_SHRINK = of("pad_extract_no_shrink")
4332+
42814333
@JvmStatic fun of(value: String) = CropMode(JsonField.of(value))
42824334
}
42834335

@@ -4286,6 +4338,8 @@ private constructor(
42864338
PAD_RESIZE,
42874339
EXTRACT,
42884340
PAD_EXTRACT,
4341+
PAD_RESIZE_NO_ENLARGE,
4342+
PAD_EXTRACT_NO_SHRINK,
42894343
}
42904344

42914345
/**
@@ -4301,6 +4355,8 @@ private constructor(
43014355
PAD_RESIZE,
43024356
EXTRACT,
43034357
PAD_EXTRACT,
4358+
PAD_RESIZE_NO_ENLARGE,
4359+
PAD_EXTRACT_NO_SHRINK,
43044360
/** An enum member indicating that [CropMode] was instantiated with an unknown value. */
43054361
_UNKNOWN,
43064362
}
@@ -4317,6 +4373,8 @@ private constructor(
43174373
PAD_RESIZE -> Value.PAD_RESIZE
43184374
EXTRACT -> Value.EXTRACT
43194375
PAD_EXTRACT -> Value.PAD_EXTRACT
4376+
PAD_RESIZE_NO_ENLARGE -> Value.PAD_RESIZE_NO_ENLARGE
4377+
PAD_EXTRACT_NO_SHRINK -> Value.PAD_EXTRACT_NO_SHRINK
43204378
else -> Value._UNKNOWN
43214379
}
43224380

@@ -4334,6 +4392,8 @@ private constructor(
43344392
PAD_RESIZE -> Known.PAD_RESIZE
43354393
EXTRACT -> Known.EXTRACT
43364394
PAD_EXTRACT -> Known.PAD_EXTRACT
4395+
PAD_RESIZE_NO_ENLARGE -> Known.PAD_RESIZE_NO_ENLARGE
4396+
PAD_EXTRACT_NO_SHRINK -> Known.PAD_EXTRACT_NO_SHRINK
43374397
else -> throw ImageKitInvalidDataException("Unknown CropMode: $value")
43384398
}
43394399

@@ -8726,6 +8786,7 @@ private constructor(
87268786
background == other.background &&
87278787
blur == other.blur &&
87288788
border == other.border &&
8789+
colorize == other.colorize &&
87298790
colorProfile == other.colorProfile &&
87308791
colorReplace == other.colorReplace &&
87318792
contrastStretch == other.contrastStretch &&
@@ -8785,6 +8846,7 @@ private constructor(
87858846
background,
87868847
blur,
87878848
border,
8849+
colorize,
87888850
colorProfile,
87898851
colorReplace,
87908852
contrastStretch,
@@ -8833,5 +8895,5 @@ private constructor(
88338895
override fun hashCode(): Int = hashCode
88348896

88358897
override fun toString() =
8836-
"Transformation{aiChangeBackground=$aiChangeBackground, aiDropShadow=$aiDropShadow, aiEdit=$aiEdit, aiRemoveBackground=$aiRemoveBackground, aiRemoveBackgroundExternal=$aiRemoveBackgroundExternal, aiRetouch=$aiRetouch, aiUpscale=$aiUpscale, aiVariation=$aiVariation, aspectRatio=$aspectRatio, audioCodec=$audioCodec, background=$background, blur=$blur, border=$border, colorProfile=$colorProfile, colorReplace=$colorReplace, contrastStretch=$contrastStretch, crop=$crop, cropMode=$cropMode, defaultImage=$defaultImage, distort=$distort, dpr=$dpr, duration=$duration, endOffset=$endOffset, flip=$flip, focus=$focus, format=$format, gradient=$gradient, grayscale=$grayscale, height=$height, lossless=$lossless, metadata=$metadata, named=$named, opacity=$opacity, original=$original, overlay=$overlay, page=$page, progressive=$progressive, quality=$quality, radius=$radius, raw=$raw, rotation=$rotation, shadow=$shadow, sharpen=$sharpen, startOffset=$startOffset, streamingResolutions=$streamingResolutions, trim=$trim, unsharpMask=$unsharpMask, videoCodec=$videoCodec, width=$width, x=$x, xCenter=$xCenter, y=$y, yCenter=$yCenter, zoom=$zoom, additionalProperties=$additionalProperties}"
8898+
"Transformation{aiChangeBackground=$aiChangeBackground, aiDropShadow=$aiDropShadow, aiEdit=$aiEdit, aiRemoveBackground=$aiRemoveBackground, aiRemoveBackgroundExternal=$aiRemoveBackgroundExternal, aiRetouch=$aiRetouch, aiUpscale=$aiUpscale, aiVariation=$aiVariation, aspectRatio=$aspectRatio, audioCodec=$audioCodec, background=$background, blur=$blur, border=$border, colorize=$colorize, colorProfile=$colorProfile, colorReplace=$colorReplace, contrastStretch=$contrastStretch, crop=$crop, cropMode=$cropMode, defaultImage=$defaultImage, distort=$distort, dpr=$dpr, duration=$duration, endOffset=$endOffset, flip=$flip, focus=$focus, format=$format, gradient=$gradient, grayscale=$grayscale, height=$height, lossless=$lossless, metadata=$metadata, named=$named, opacity=$opacity, original=$original, overlay=$overlay, page=$page, progressive=$progressive, quality=$quality, radius=$radius, raw=$raw, rotation=$rotation, shadow=$shadow, sharpen=$sharpen, startOffset=$startOffset, streamingResolutions=$streamingResolutions, trim=$trim, unsharpMask=$unsharpMask, videoCodec=$videoCodec, width=$width, x=$x, xCenter=$xCenter, y=$y, yCenter=$yCenter, zoom=$zoom, additionalProperties=$additionalProperties}"
88378899
}

image-kit-java-core/src/test/kotlin/io/imagekit/models/GetImageAttributesOptionsTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal class GetImageAttributesOptionsTest {
3939
.background("red")
4040
.blur(10.0)
4141
.border("5_FF0000")
42+
.colorize("colorize")
4243
.colorProfile(true)
4344
.colorReplace("colorReplace")
4445
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -159,6 +160,7 @@ internal class GetImageAttributesOptionsTest {
159160
.background("red")
160161
.blur(10.0)
161162
.border("5_FF0000")
163+
.colorize("colorize")
162164
.colorProfile(true)
163165
.colorReplace("colorReplace")
164166
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -277,6 +279,7 @@ internal class GetImageAttributesOptionsTest {
277279
.background("red")
278280
.blur(10.0)
279281
.border("5_FF0000")
282+
.colorize("colorize")
280283
.colorProfile(true)
281284
.colorReplace("colorReplace")
282285
.contrastStretch(Transformation.ContrastStretch.TRUE)

image-kit-java-core/src/test/kotlin/io/imagekit/models/ImageOverlayTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ internal class ImageOverlayTest {
4343
.background("red")
4444
.blur(10.0)
4545
.border("5_FF0000")
46+
.colorize("colorize")
4647
.colorProfile(true)
4748
.colorReplace("colorReplace")
4849
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -162,6 +163,7 @@ internal class ImageOverlayTest {
162163
.background("red")
163164
.blur(10.0)
164165
.border("5_FF0000")
166+
.colorize("colorize")
165167
.colorProfile(true)
166168
.colorReplace("colorReplace")
167169
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -277,6 +279,7 @@ internal class ImageOverlayTest {
277279
.background("red")
278280
.blur(10.0)
279281
.border("5_FF0000")
282+
.colorize("colorize")
280283
.colorProfile(true)
281284
.colorReplace("colorReplace")
282285
.contrastStretch(Transformation.ContrastStretch.TRUE)

image-kit-java-core/src/test/kotlin/io/imagekit/models/OverlayTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ internal class OverlayTest {
139139
.background("red")
140140
.blur(10.0)
141141
.border("5_FF0000")
142+
.colorize("colorize")
142143
.colorProfile(true)
143144
.colorReplace("colorReplace")
144145
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -272,6 +273,7 @@ internal class OverlayTest {
272273
.background("red")
273274
.blur(10.0)
274275
.border("5_FF0000")
276+
.colorize("colorize")
275277
.colorProfile(true)
276278
.colorReplace("colorReplace")
277279
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -399,6 +401,7 @@ internal class OverlayTest {
399401
.background("red")
400402
.blur(10.0)
401403
.border("5_FF0000")
404+
.colorize("colorize")
402405
.colorProfile(true)
403406
.colorReplace("colorReplace")
404407
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -532,6 +535,7 @@ internal class OverlayTest {
532535
.background("red")
533536
.blur(10.0)
534537
.border("5_FF0000")
538+
.colorize("colorize")
535539
.colorProfile(true)
536540
.colorReplace("colorReplace")
537541
.contrastStretch(Transformation.ContrastStretch.TRUE)

image-kit-java-core/src/test/kotlin/io/imagekit/models/SrcOptionsTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal class SrcOptionsTest {
3939
.background("red")
4040
.blur(10.0)
4141
.border("5_FF0000")
42+
.colorize("colorize")
4243
.colorProfile(true)
4344
.colorReplace("colorReplace")
4445
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -153,6 +154,7 @@ internal class SrcOptionsTest {
153154
.background("red")
154155
.blur(10.0)
155156
.border("5_FF0000")
157+
.colorize("colorize")
156158
.colorProfile(true)
157159
.colorReplace("colorReplace")
158160
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -264,6 +266,7 @@ internal class SrcOptionsTest {
264266
.background("red")
265267
.blur(10.0)
266268
.border("5_FF0000")
269+
.colorize("colorize")
267270
.colorProfile(true)
268271
.colorReplace("colorReplace")
269272
.contrastStretch(Transformation.ContrastStretch.TRUE)

image-kit-java-core/src/test/kotlin/io/imagekit/models/TransformationTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal class TransformationTest {
2727
.background("red")
2828
.blur(10.0)
2929
.border("5_FF0000")
30+
.colorize("colorize")
3031
.colorProfile(true)
3132
.colorReplace("colorReplace")
3233
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -120,6 +121,7 @@ internal class TransformationTest {
120121
assertThat(transformation.background()).contains("red")
121122
assertThat(transformation.blur()).contains(10.0)
122123
assertThat(transformation.border()).contains("5_FF0000")
124+
assertThat(transformation.colorize()).contains("colorize")
123125
assertThat(transformation.colorProfile()).contains(true)
124126
assertThat(transformation.colorReplace()).contains("colorReplace")
125127
assertThat(transformation.contrastStretch()).contains(Transformation.ContrastStretch.TRUE)
@@ -219,6 +221,7 @@ internal class TransformationTest {
219221
.background("red")
220222
.blur(10.0)
221223
.border("5_FF0000")
224+
.colorize("colorize")
222225
.colorProfile(true)
223226
.colorReplace("colorReplace")
224227
.contrastStretch(Transformation.ContrastStretch.TRUE)

image-kit-java-core/src/test/kotlin/io/imagekit/models/VideoOverlayTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ internal class VideoOverlayTest {
4343
.background("red")
4444
.blur(10.0)
4545
.border("5_FF0000")
46+
.colorize("colorize")
4647
.colorProfile(true)
4748
.colorReplace("colorReplace")
4849
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -162,6 +163,7 @@ internal class VideoOverlayTest {
162163
.background("red")
163164
.blur(10.0)
164165
.border("5_FF0000")
166+
.colorize("colorize")
165167
.colorProfile(true)
166168
.colorReplace("colorReplace")
167169
.contrastStretch(Transformation.ContrastStretch.TRUE)
@@ -277,6 +279,7 @@ internal class VideoOverlayTest {
277279
.background("red")
278280
.blur(10.0)
279281
.border("5_FF0000")
282+
.colorize("colorize")
280283
.colorProfile(true)
281284
.colorReplace("colorReplace")
282285
.contrastStretch(Transformation.ContrastStretch.TRUE)

0 commit comments

Comments
 (0)