xml_image: Generate HTML and XML Representations for an Image

View source: R/generate_xml.R

xml_imageR Documentation

Generate HTML and XML Representations for an Image

Description

This function generates an HTML ⁠<img>⁠ tag and an XML ⁠<file>⁠ tag for a given image. The image can be processed to adjust its dimensions and encoded in base64 for embedding.

Usage

xml_image(image, image_alt, adapt_images = FALSE, width = NULL, height = NULL)

Arguments

image

character Path to the image file. If the string is empty, the function returns empty values.

image_alt

character Alternative text for the image, used for accessibility purposes (e.g., screen readers).

adapt_images

logical, default FALSE If TRUE, the image dimensions are adjusted to the specified width and height. If FALSE, the original dimensions are used.

width

numeric or NULL, default NULL Desired width for the image. Only used when adapt_images = TRUE. If NULL, the width is derived from the image file.

height

numeric or NULL, default NULL Desired height for the image. Only used when adapt_images = TRUE. If NULL, the height is derived from the image file.

Details

  • If adapt_images = TRUE, the function resizes the image using the specified dimensions.

  • If adapt_images = FALSE, the function reads the image's original dimensions and uses them.

  • The image is embedded as a base64 string in the ⁠<file>⁠ tag for compatibility with XML-based systems.

Value

A list with two elements:

img

character: HTML string containing the ⁠<img>⁠ tag.

fimg

character: XML string containing the base64-encoded ⁠<file>⁠ tag.


moodef documentation built on April 12, 2025, 1:42 a.m.