Class PngUtils

java.lang.Object
org.forgerock.doc.maven.utils.PngUtils

public final class PngUtils extends Object
Set dots per inch in the metadata of a Portable Network Graphics image.
  • Method Details

    • resizePng

      public static void resizePng(File image) throws IOException
      Creates a thumbnail copy of provided image, prefixed with "thumb_".
      Parameters:
      image - image file.
      Throws:
      IOException - Failed to read the image or to write the thumbnail.
    • getScaledInstance

      public static BufferedImage getScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean higherQuality)
      Convenience method that returns a scaled instance of the provided BufferedImage.
      Parameters:
      img - the original image to be scaled
      targetWidth - the desired width of the scaled instance, in pixels
      targetHeight - the desired height of the scaled instance, in pixels
      hint - one of the rendering hints that corresponds to RenderingHints.KEY_INTERPOLATION (e.g. RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RenderingHints.VALUE_INTERPOLATION_BICUBIC)
      higherQuality - if true, this method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in downscaling cases, where targetWidth or targetHeight is smaller than the original dimensions, and generally only when the BILINEAR hint is specified)
      Returns:
      a scaled version of the original BufferedImage
    • setSafeDpi

      public static void setSafeDpi(File image, int maxHeightInInches) throws IOException
      Set the DPI on image so that it fits in maxHeightInInches, or to 160 if short enough.
      Parameters:
      image - PNG image file.
      maxHeightInInches - maximum available image height in inches.
      Throws:
      IOException - Failed to save the image.
    • setDpi

      public static void setDpi(File image) throws IOException
      Set the DPI on image to 160.
      Parameters:
      image - PNG image file.
      Throws:
      IOException - Failed to save the image.
    • setDpi

      public static void setDpi(File image, int dotsPerInch) throws IOException
      Set the DPI on image to dotsPerInch.
      Parameters:
      image - PNG image file.
      dotsPerInch - DPI to set in metadata.
      Throws:
      IOException - Failed to save the image.