Class Image<T extends Image<T>>


public class Image<T extends Image<T>> extends Img<T>
Represents an HTML image, extending the <img> element.

The Image class is a convenience wrapper around the Img element, providing a more intuitive class name for embedding images in HTML documents. It supports various configurations including source URL, alternative text, and width specifications (in pixels or CSS units). The Image element is a self-closing tag that displays graphics in web pages.

Features:

  • Alternative, more descriptive name for the Img element
  • Embeds images from local or remote sources
  • Supports alternative text for accessibility
  • Configurable width in pixels or CSS units
  • Inherits all image element attributes and methods

Usage:


 // Create a simple image
 Image img = new Image("photo.jpg", "A beautiful landscape");

 // Create image with fixed width
 Image thumbnail = new Image("thumb.jpg", "Thumbnail", 150);

 // Create image with CSS width
 Image responsive = new Image("banner.jpg", "Banner", "100%");

 // Create empty image and configure later
 Image img = new Image();
 img.setSrc("logo.png");
 img.setAlt("Company Logo");
 img.setIntrinsicWidth(200);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Image

      public Image()
      Constructs an empty image element.

      Creates an image without a source URL or attributes. These should be set using inherited methods from the Img class.

    • Image

      public Image(String src)
      Constructs an image with the specified source URL.
      Parameters:
      src - the URL of the image file; may be absolute or relative
    • Image

      public Image(String src, String altText)
      Constructs an image with source URL and alternative text.
      Parameters:
      src - the URL of the image file; may be absolute or relative
      altText - alternative text describing the image for accessibility
    • Image

      public Image(String src, int width)
      Constructs an image with source URL and fixed pixel width.
      Parameters:
      src - the URL of the image file; may be absolute or relative
      width - the width of the image in pixels
    • Image

      public Image(String src, String altText, int width)
      Constructs an image with source URL, alternative text, and fixed pixel width.
      Parameters:
      src - the URL of the image file; may be absolute or relative
      altText - alternative text describing the image for accessibility
      width - the width of the image in pixels
    • Image

      public Image(String src, String altText, String width)
      Constructs an image with source URL, alternative text, and CSS width.
      Parameters:
      src - the URL of the image file; may be absolute or relative
      altText - alternative text describing the image for accessibility
      width - the width as a CSS value (e.g., "100%", "50vw", "300px")
  • Method Details

    • setIntrinsicWidth

      public T setIntrinsicWidth(int pixels)
      Sets the HTML width attribute to specify intrinsic width in pixels.

      This sets the HTML attribute (e.g., <img width="300">), not the CSS width property. To set CSS width, use the inherited StyledElement.setWidth(int) method.

      Parameters:
      pixels - The width in pixels.
      Returns:
      This element for method chaining.
    • setIntrinsicWidth

      public T setIntrinsicWidth(String width)
      Sets the HTML width attribute to specify intrinsic width.

      This sets the HTML attribute, not the CSS width property. To set CSS width, use the inherited StyledElement.setWidth(String) method.

      Parameters:
      width - The width value.
      Returns:
      This element for method chaining.
    • setIntrinsicHeight

      public T setIntrinsicHeight(int pixels)
      Sets the HTML height attribute to specify intrinsic height in pixels.

      This sets the HTML attribute (e.g., <img height="200">), not the CSS height property. To set CSS height, use the inherited StyledElement.setHeight(int) method.

      Parameters:
      pixels - The height in pixels.
      Returns:
      This element for method chaining.
    • setIntrinsicHeight

      public T setIntrinsicHeight(String height)
      Sets the HTML height attribute to specify intrinsic height.

      This sets the HTML attribute, not the CSS height property. To set CSS height, use the inherited StyledElement.setHeight(String) method.

      Parameters:
      height - The height value.
      Returns:
      This element for method chaining.
    • getIntrinsicWidth

      public String getIntrinsicWidth()
      Returns the HTML width attribute value.

      Returns the intrinsic width set via the HTML attribute, not the CSS width.

      Returns:
      The width value, or null if not set.
    • getIntrinsicHeight

      public String getIntrinsicHeight()
      Returns the HTML height attribute value.

      Returns the intrinsic height set via the HTML attribute, not the CSS height.

      Returns:
      The height value, or null if not set.