Class ImageUtils

java.lang.Object
com.structurizr.util.ImageUtils

public class ImageUtils extends Object
Some utility methods for dealing with images.
  • Field Details

  • Constructor Details

    • ImageUtils

      public ImageUtils()
  • Method Details

    • getContentType

      public static String getContentType(@Nonnull File file) throws IOException
      Gets the content type of the specified file representing an image.
      Parameters:
      file - a File pointing to an image
      Returns:
      a content type (e.g. "image/png")
      Throws:
      IOException - if there is an error reading the file
    • getContentType

      public static String getContentType(String url) throws IOException
      Gets the content type of the specified URL representing an image.
      Parameters:
      url - a URL pointing to an image
      Returns:
      a content type (e.g. "image/png")
      Throws:
      IOException - if there is an error reading the file
    • getContentTypeFromDataUri

      public static String getContentTypeFromDataUri(String dataUri)
      Gets the content type of the specified data URI representing an image.
      Parameters:
      dataUri - a data URI representing an image
      Returns:
      a content type (e.g. "image/png")
    • getImageAsBase64

      public static String getImageAsBase64(@Nonnull File file) throws IOException
      Gets the content of an image as a Base64 encoded string.
      Parameters:
      file - a File pointing to an image
      Returns:
      a Base64 encoded version of that image
      Throws:
      IOException - if there is an error reading the file
    • getImageAsDataUri

      public static String getImageAsDataUri(File file) throws IOException
      Gets the content of an image as a data URI; e.g. "data:image/png;base64,iVBORw0KGgoAA..."
      Parameters:
      file - a File pointing to an image
      Returns:
      a data URI
      Throws:
      IOException - if there is an error reading the file
    • validateImage

      public static void validateImage(String imageDescriptor)
    • isSupportedDataUri

      public static boolean isSupportedDataUri(String uri)