When outputting to HTML, users have the option of having images being output in their template via an Import Tag being embedded into the output as BASE64 encoded images, or they can leave the images as file locations pointing to the image source. This article teaches how to explicitly specify one output method or the other.
The template used in all the examples bellow is an import tag importing an image from a URL.
The following code snippet shows our default behavior:
This code creates the following HTML output. You can see that the images default to being embedded inside the HTML as BASE64 encoded images:
The same default output can be achieved by explicitly specifying to embed the images in the output using the setEmbedImages method:
Alternatively, the user can specify a location for the images to be saved as output is generated, and then these image locations can be referenced in the HTML. To do this, the user needs to use two methods:
- ProcessHtmlAPI.setImagePath(String s, String s2, String s3): this will allow the user to specify relative the location to save the images, and the relative location to the output HTML to reference the images, as well as the prefix to use for the image. Read more here.
- ProcessHtmlAPI.setEmbedImages(Boolean b): This is the same method used above to specify the default functionality of embedding the images. Setting this to false will use the specified image paths to save and reference the images. Read more here.
The final code looks like this:
The output HTML references the image at the relative "images" location, and the image is saved with our specified prefix and an appended identifier: