Class ImageUtils

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

public class ImageUtils extends Object
Some utility methods for dealing with images.
  • 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
    • 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)