Class ImageTool

java.lang.Object
org.sentrysoftware.maven.skin.ImageTool

@DefaultKey("imageTool") public class ImageTool extends Object
Set of tools for handling images
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new instance
  • Method Summary

    Modifier and Type
    Method
    Description
    org.jsoup.nodes.Element
    checkImageLinks(org.jsoup.nodes.Element body, String basedir, String currentDocument)
    Check the image links in the document and make sure they refer to a file that actually exists.
    org.jsoup.nodes.Element
    convertImagesToThumbnails(org.jsoup.nodes.Element body, String selector, String basedir, String currentDocument, int maxWidth, int maxHeight, String wrapTemplate)
    For all images in the document, create the corresponding thumbnail, and wrap the picture elements with the specified template.
    org.jsoup.nodes.Element
    convertImagesToWebp(org.jsoup.nodes.Element body, String selector, String basedir, String currentDocument)
    Upgrades all images in the specified HTML document to WEBP.
    org.jsoup.nodes.Element
    explicitImageSize(org.jsoup.nodes.Element body, String selector, String basedir, String currentDocument)
    Explicitly states the width and height of each image in the specified document.

    Methods inherited from class java.lang.Object

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

    • ImageTool

      public ImageTool()
      Create a new instance
  • Method Details

    • checkImageLinks

      public org.jsoup.nodes.Element checkImageLinks(org.jsoup.nodes.Element body, String basedir, String currentDocument) throws IOException
      Check the image links in the document and make sure they refer to a file that actually exists.
      Parameters:
      body - the HTML content
      basedir - Actual root directory of the site on the file system
      currentDocument - Logical path of the document being parsed (e.g. "index.html", or "subdir/subpage.html")
      Returns:
      the updated HTML content
      Throws:
      IOException - when an image cannot be read or converted
    • convertImagesToWebp

      public org.jsoup.nodes.Element convertImagesToWebp(org.jsoup.nodes.Element body, String selector, String basedir, String currentDocument) throws IOException
      Upgrades all images in the specified HTML document to WEBP.
      Parameters:
      body - the HTML content
      selector - CSS selector to select all images to upgrade ("img.screenshot" will process all <IMG class="screenshot"> elements)
      basedir - Actual root directory of the site on the file system
      currentDocument - Logical path of the document being parsed (e.g. "index.html", or "subdir/subpage.html")
      Returns:
      the updated HTML content
      Throws:
      IOException - when an image cannot be read or converted
    • explicitImageSize

      public org.jsoup.nodes.Element explicitImageSize(org.jsoup.nodes.Element body, String selector, String basedir, String currentDocument) throws IOException
      Explicitly states the width and height of each image in the specified document.
      Parameters:
      body - the HTML content
      selector - CSS selector to select all images to upgrade ("img.screenshot" will process all <IMG class="screenshot"> elements)
      basedir - Actual root directory of the site on the file system
      currentDocument - Logical path of the document being parsed (e.g. "index.html", or "subdir/subpage.html")
      Returns:
      the updated HTML content
      Throws:
      IOException - when an image cannot be read or converted
    • convertImagesToThumbnails

      public org.jsoup.nodes.Element convertImagesToThumbnails(org.jsoup.nodes.Element body, String selector, String basedir, String currentDocument, int maxWidth, int maxHeight, String wrapTemplate) throws IOException
      For all images in the document, create the corresponding thumbnail, and wrap the picture elements with the specified template.

      The specified template may reference the below "macros":

      • %imgWidth%: the original image width
      • %imgHeight%: the original image height
      • %imgAlt%: the image alternate text (it's description)
      • %thumbWidth%: the thumbnail image width
      • %thumbHeight%: the thumbnail image height
      • %thumbSrc%: the thumbnail image source path
      Parameters:
      body - the HTML content
      selector - CSS selector to select all images to upgrade ("img.screenshot" will process all <IMG class="screenshot"> elements)
      basedir - Actual root directory of the site on the file system
      currentDocument - Logical path of the document being parsed (e.g. "index.html", or "subdir/subpage.html")
      maxWidth - Maximum width for the thumbnail (or 0 for no maximum)
      maxHeight - Maximum height for the thumbnail (or 0 for no maximum)
      wrapTemplate - HTML code wrap the image element with. This will be typically used to create the thumbnail element. The HTML can reference macros.
      Returns:
      the updated HTML content
      Throws:
      IOException - when an image cannot be read or converted