@@ -34,6 +34,7 @@ class ThumbnailV2Arg {
3434 protected final ThumbnailQuality quality ;
3535 @ Nullable
3636 protected final Boolean excludeMediaInfo ;
37+ protected final boolean preserveTransparency ;
3738
3839 /**
3940 * Use {@link newBuilder} to create instances of this class without
@@ -56,11 +57,15 @@ class ThumbnailV2Arg {
5657 * set for photo and video. When this flag is true, {@link
5758 * FileMetadata#getMediaInfo} is not populated. This improves latency
5859 * for use cases where `media_info` is not needed.
60+ * @param preserveTransparency Whether to preserve the original image's
61+ * transparency in the thumbnail. This is supported only when the output
62+ * format is PNG or WebP. Requests that set this flag with JPEG output
63+ * return an error.
5964 *
6065 * @throws IllegalArgumentException If any argument does not meet its
6166 * preconditions.
6267 */
63- public ThumbnailV2Arg (@ Nonnull PathOrLink resource , @ Nonnull ThumbnailFormat format , @ Nonnull ThumbnailSize size , @ Nonnull ThumbnailMode mode , @ Nonnull ThumbnailQuality quality , @ Nullable Boolean excludeMediaInfo ) {
68+ public ThumbnailV2Arg (@ Nonnull PathOrLink resource , @ Nonnull ThumbnailFormat format , @ Nonnull ThumbnailSize size , @ Nonnull ThumbnailMode mode , @ Nonnull ThumbnailQuality quality , @ Nullable Boolean excludeMediaInfo , boolean preserveTransparency ) {
6469 if (resource == null ) {
6570 throw new IllegalArgumentException ("Required value for 'resource' is null" );
6671 }
@@ -82,6 +87,7 @@ public ThumbnailV2Arg(@Nonnull PathOrLink resource, @Nonnull ThumbnailFormat for
8287 }
8388 this .quality = quality ;
8489 this .excludeMediaInfo = excludeMediaInfo ;
90+ this .preserveTransparency = preserveTransparency ;
8591 }
8692
8793 /**
@@ -98,7 +104,7 @@ public ThumbnailV2Arg(@Nonnull PathOrLink resource, @Nonnull ThumbnailFormat for
98104 * preconditions.
99105 */
100106 public ThumbnailV2Arg (@ Nonnull PathOrLink resource ) {
101- this (resource , ThumbnailFormat .JPEG , ThumbnailSize .W64H64 , ThumbnailMode .STRICT , ThumbnailQuality .QUALITY_80 , null );
107+ this (resource , ThumbnailFormat .JPEG , ThumbnailSize .W64H64 , ThumbnailMode .STRICT , ThumbnailQuality .QUALITY_80 , null , false );
102108 }
103109
104110 /**
@@ -173,6 +179,18 @@ public Boolean getExcludeMediaInfo() {
173179 return excludeMediaInfo ;
174180 }
175181
182+ /**
183+ * Whether to preserve the original image's transparency in the thumbnail.
184+ * This is supported only when the output format is PNG or WebP. Requests
185+ * that set this flag with JPEG output return an error.
186+ *
187+ * @return value for this field, or {@code null} if not present. Defaults to
188+ * false.
189+ */
190+ public boolean getPreserveTransparency () {
191+ return preserveTransparency ;
192+ }
193+
176194 /**
177195 * Returns a new builder for creating an instance of this class.
178196 *
@@ -201,6 +219,7 @@ public static class Builder {
201219 protected ThumbnailMode mode ;
202220 protected ThumbnailQuality quality ;
203221 protected Boolean excludeMediaInfo ;
222+ protected boolean preserveTransparency ;
204223
205224 protected Builder (PathOrLink resource ) {
206225 if (resource == null ) {
@@ -212,6 +231,7 @@ protected Builder(PathOrLink resource) {
212231 this .mode = ThumbnailMode .STRICT ;
213232 this .quality = ThumbnailQuality .QUALITY_80 ;
214233 this .excludeMediaInfo = null ;
234+ this .preserveTransparency = false ;
215235 }
216236
217237 /**
@@ -332,14 +352,38 @@ public Builder withExcludeMediaInfo(Boolean excludeMediaInfo) {
332352 return this ;
333353 }
334354
355+ /**
356+ * Set value for optional field.
357+ *
358+ * <p> If left unset or set to {@code null}, defaults to {@code false}.
359+ * </p>
360+ *
361+ * @param preserveTransparency Whether to preserve the original image's
362+ * transparency in the thumbnail. This is supported only when the
363+ * output format is PNG or WebP. Requests that set this flag with
364+ * JPEG output return an error. Defaults to {@code false} when set
365+ * to {@code null}.
366+ *
367+ * @return this builder
368+ */
369+ public Builder withPreserveTransparency (Boolean preserveTransparency ) {
370+ if (preserveTransparency != null ) {
371+ this .preserveTransparency = preserveTransparency ;
372+ }
373+ else {
374+ this .preserveTransparency = false ;
375+ }
376+ return this ;
377+ }
378+
335379 /**
336380 * Builds an instance of {@link ThumbnailV2Arg} configured with this
337381 * builder's values
338382 *
339383 * @return new instance of {@link ThumbnailV2Arg}
340384 */
341385 public ThumbnailV2Arg build () {
342- return new ThumbnailV2Arg (resource , format , size , mode , quality , excludeMediaInfo );
386+ return new ThumbnailV2Arg (resource , format , size , mode , quality , excludeMediaInfo , preserveTransparency );
343387 }
344388 }
345389
@@ -351,7 +395,8 @@ public int hashCode() {
351395 this .size ,
352396 this .mode ,
353397 this .quality ,
354- this .excludeMediaInfo
398+ this .excludeMediaInfo ,
399+ this .preserveTransparency
355400 });
356401 return hash ;
357402 }
@@ -373,6 +418,7 @@ else if (obj.getClass().equals(this.getClass())) {
373418 && ((this .mode == other .mode ) || (this .mode .equals (other .mode )))
374419 && ((this .quality == other .quality ) || (this .quality .equals (other .quality )))
375420 && ((this .excludeMediaInfo == other .excludeMediaInfo ) || (this .excludeMediaInfo != null && this .excludeMediaInfo .equals (other .excludeMediaInfo )))
421+ && (this .preserveTransparency == other .preserveTransparency )
376422 ;
377423 }
378424 else {
@@ -422,6 +468,8 @@ public void serialize(ThumbnailV2Arg value, JsonGenerator g, boolean collapse) t
422468 g .writeFieldName ("exclude_media_info" );
423469 StoneSerializers .nullable (StoneSerializers .boolean_ ()).serialize (value .excludeMediaInfo , g );
424470 }
471+ g .writeFieldName ("preserve_transparency" );
472+ StoneSerializers .boolean_ ().serialize (value .preserveTransparency , g );
425473 if (!collapse ) {
426474 g .writeEndObject ();
427475 }
@@ -442,6 +490,7 @@ public ThumbnailV2Arg deserialize(JsonParser p, boolean collapsed) throws IOExce
442490 ThumbnailMode f_mode = ThumbnailMode .STRICT ;
443491 ThumbnailQuality f_quality = ThumbnailQuality .QUALITY_80 ;
444492 Boolean f_excludeMediaInfo = null ;
493+ Boolean f_preserveTransparency = false ;
445494 while (p .getCurrentToken () == JsonToken .FIELD_NAME ) {
446495 String field = p .getCurrentName ();
447496 p .nextToken ();
@@ -463,14 +512,17 @@ else if ("quality".equals(field)) {
463512 else if ("exclude_media_info" .equals (field )) {
464513 f_excludeMediaInfo = StoneSerializers .nullable (StoneSerializers .boolean_ ()).deserialize (p );
465514 }
515+ else if ("preserve_transparency" .equals (field )) {
516+ f_preserveTransparency = StoneSerializers .boolean_ ().deserialize (p );
517+ }
466518 else {
467519 skipValue (p );
468520 }
469521 }
470522 if (f_resource == null ) {
471523 throw new JsonParseException (p , "Required field \" resource\" missing." );
472524 }
473- value = new ThumbnailV2Arg (f_resource , f_format , f_size , f_mode , f_quality , f_excludeMediaInfo );
525+ value = new ThumbnailV2Arg (f_resource , f_format , f_size , f_mode , f_quality , f_excludeMediaInfo , f_preserveTransparency );
474526 }
475527 else {
476528 throw new JsonParseException (p , "No subtype found that matches tag: \" " + tag + "\" " );
0 commit comments