Record Class ImageWatermark

java.lang.Object
java.lang.Record
com.nsdev.lettergenerator.model.watermark.ImageWatermark
Record Components:
data - encoded PNG/JPEG/static SVG bytes, required during generation
mimeType - exact supported MIME type, image/png, image/jpeg or image/svg+xml
widthMm - image fitting-box width in millimeters; required and positive during generation
heightMm - image fitting-box height in millimeters; required and positive during generation
pages - page selection, required during generation
opacity - finite paint opacity between zero and one, required during generation
rotationDegrees - finite counterclockwise angle in degrees, required during generation
All Implemented Interfaces:
Watermark

public record ImageWatermark(byte[] data, String mimeType, Double widthMm, Double heightMm, PageSelector pages, Double opacity, Double rotationDegrees) extends Record implements Watermark
PNG/JPEG/static SVG image centered behind selected physical pages, with its aspect ratio preserved inside the supplied millimeter box. Watermark position is independent of page margins. Opacity ranges from zero to one; positive rotation turns counterclockwise about page center in PDF coordinates.

The constructor copies image bytes but does not decode them or default null properties. Generation checks the MIME type, signature, decodability, positive finite box dimensions, page selection, opacity, and finite rotation. Factories detect image format and provide complete defaults. Stored bytes are protected by defensive copies on construction and access; equality and hashing compare their contents.

  • Constructor Details

    • ImageWatermark

      public ImageWatermark(byte[] data, String mimeType, Double widthMm, Double heightMm, PageSelector pages, Double opacity, Double rotationDegrees)
      Defensively copies the encoded bytes. Other components, including nulls, are stored unchanged and validated during generation.
      Parameters:
      data - bytes to clone, or null
      mimeType - declared image format
      widthMm - fitting-box width in millimeters
      heightMm - fitting-box height in millimeters
      pages - page selection
      opacity - paint opacity from zero to one
      rotationDegrees - counterclockwise rotation in degrees
  • Method Details

    • of

      public static ImageWatermark of(byte[] data)
      Decodes supplied image bytes, detects PNG/JPEG/static SVG format, and proportionally fits the image within an 80 by 40 mm box. The result selects all pages with opacity 0.12 and zero rotation. Unlike direct record construction, this factory validates image readability.
      Parameters:
      data - encoded image bytes, copied before decoding
      Returns:
      watermark with fitted dimensions and default page/paint settings
      Throws:
      IllegalArgumentException - if data is null, unreadable, or not supported PNG/JPEG/static SVG
    • of

      public static ImageWatermark of(Path path) throws IOException
      Reads a local image and creates the same fitted default watermark as of(byte[]). The file is fully read before the watermark is returned.
      Parameters:
      path - local PNG/JPEG/static SVG file
      Returns:
      watermark fitted within 80 by 40 mm, on all pages, with opacity 0.12 and no rotation
      Throws:
      IOException - if the image file cannot be read
      NullPointerException - if path is null
      IllegalArgumentException - if the file is not a readable supported PNG/JPEG/static SVG
    • data

      public byte[] data()
      Returns a defensive copy of the encoded image.
      Returns:
      a new byte array, or null when no bytes were supplied
    • equals

      public boolean equals(Object other)
      Compares image byte contents and every other record component.
      Specified by:
      equals in class Record
      Parameters:
      other - object to compare, possibly null
      Returns:
      true for an image watermark with equal bytes and other components
    • hashCode

      public int hashCode()
      Hashes byte contents and every other record component consistently with equality.
      Specified by:
      hashCode in class Record
      Returns:
      content-based hash code
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • mimeType

      public String mimeType()
      Returns the value of the mimeType record component.
      Returns:
      the value of the mimeType record component
    • widthMm

      public Double widthMm()
      Returns the value of the widthMm record component.
      Returns:
      the value of the widthMm record component
    • heightMm

      public Double heightMm()
      Returns the value of the heightMm record component.
      Returns:
      the value of the heightMm record component
    • pages

      public PageSelector pages()
      Returns the value of the pages record component.
      Specified by:
      pages in interface Watermark
      Returns:
      the value of the pages record component
    • opacity

      public Double opacity()
      Returns the value of the opacity record component.
      Specified by:
      opacity in interface Watermark
      Returns:
      the value of the opacity record component
    • rotationDegrees

      public Double rotationDegrees()
      Returns the value of the rotationDegrees record component.
      Specified by:
      rotationDegrees in interface Watermark
      Returns:
      the value of the rotationDegrees record component