Class ImageFormat

java.lang.Object
net.dv8tion.jda.api.utils.ImageFormat

public final class ImageFormat extends Object
Represents an image format support by Discord's CDNs.

Format support varies based on the CDN endpoint.

See Also:
  • Field Details

    • JPG

      public static final ImageFormat JPG
      Lossy static image format.
      Generally has a smaller size but can have visual artifacts and doesn't support transparency.

      Requesting an image with this format should always work.

    • PNG

      public static final ImageFormat PNG
      Lossless static image format.
      Content is compressed but larger than other lossy image formats.

      Requesting an image with this format should always work.

    • GIF

      public static final ImageFormat GIF
      Lossless animated image format.
      Content is very poorly compressed, and only supports up to 255 colors.
      Using ANIMATED_WEBP is recommended instead.

      Requesting an image with this format may fail with an HTTP 415 (Unsupported Media Type) if the image was originally uploaded as a WebP.

      See Also:
    • STATIC_WEBP

      public static final ImageFormat STATIC_WEBP
      Lossy or lossless static image format.
      Sizes can be similar to JPG with the addition of transparency support.

      This is the format Discord recommends for static images. Requesting an image with this format should always work.

    • ANIMATED_WEBP

      public static final ImageFormat ANIMATED_WEBP
      Lossy or lossless animated image format.
      Sizes will be considerably smaller than GIF, however, encoding can also be slower.

      This is the format Discord recommends for animated images. Requesting an image with this format should always work, including static images.

  • Method Details

    • of

      @Nonnull public static ImageFormat of(@Nonnull String extension)
      Creates an ImageFormat using the provided extension.
      Parameters:
      extension - The extension of the image
      Returns:
      The new ImageFormat
      Throws:
      IllegalArgumentException - If the extension is null
    • of

      @Nonnull public static ImageFormat of(@Nonnull String extension, @Nonnull List<String> queryParameters)
      Creates an ImageFormat using the provided extension.
      Parameters:
      extension - The extension of the image
      queryParameters - Query parameters to add to URLs, must be a multiple of 2
      Returns:
      The new ImageFormat
      Throws:
      IllegalArgumentException -
      • If any argument is null
      • If the extension is blank
      • If the query parameter list's length is not a multiple of 2
    • getExtension

      @Nonnull public String getExtension()
      Returns the extension of this image format.
      Returns:
      The extension
    • getQueryParameters

      @Nonnull public @Unmodifiable List<String> getQueryParameters()
      Returns the query parameters added to URLs by this image format.
      The list's size is a multiple of 2, the first item is the key and the second is the value.
      Returns:
      An immutable list of query parameters