Class ImageUtils

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

public class ImageUtils
extends java.lang.Object
Some utility methods for dealing with images.
  • Constructor Summary

    Constructors 
    Constructor Description
    ImageUtils()  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String getContentType​(java.io.File file)
    Gets the content type of the specified file representing an image.
    static java.lang.String getImageAsBase64​(java.io.File file)
    Gets the content of an image as a Base64 encoded string.
    static java.lang.String getImageAsDataUri​(java.io.File file)
    Gets the content of an image as a data URI; e.g.
    static boolean isSupportedDataUri​(java.lang.String uri)  
    static void validateImage​(java.lang.String url)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getContentType

      public static java.lang.String getContentType​(@Nonnull java.io.File file) throws java.io.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:
      java.io.IOException - if there is an error reading the file
    • getImageAsBase64

      public static java.lang.String getImageAsBase64​(@Nonnull java.io.File file) throws java.io.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:
      java.io.IOException - if there is an error reading the file
    • getImageAsDataUri

      public static java.lang.String getImageAsDataUri​(java.io.File file) throws java.io.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:
      java.io.IOException - if there is an error reading the file
    • validateImage

      public static void validateImage​(java.lang.String url)
    • isSupportedDataUri

      public static boolean isSupportedDataUri​(java.lang.String uri)