I have this code to add an image to a page in a custom module.
$build = array( '#theme' => 'image', '#uri' => $uri_nhchart, );
I have searched the API in Backdrop and Drupal 7 to try and find out how to add any attributes to the image, eg 'alt' or 'align' and also a caption. I cannot find out how to do it.
there must be a simple way by adding something like this into the above code....
'#attributes' => array('alt = "Northern Hemsphere Chart"'),
I would really like to be able to add a caption I have to say with the <figcaption> tag for instance.
Since you're outputting a themed image, this is the API function that documents the available parameters: theme_image() That explains how to add 'alt' text and other attributes.
As for an image caption, it looks like this might be what you're looking for: theme_filter_caption() It's not as well documented, but looking at the code at the bottom of that page should give you an idea of what parameters to pass.
Hope that helps!