Image
Image component display an image.
API
Interface
func Image(c *tgframe.Container, img any, conf ...*ImageConf)
Parameters
-
cis Parent container. -
imgis the image.image.Image: an image.Image[]byte: a byte array, MIME is detected from magic bytes (png, jpeg, gif, webp, bmp, ico, svg); falls back toFormatif unknownstring: a url or base64 encoded image- example:
- url:
https://http.cat/100 - base64 uri:
data:image/png;base64,...
- url:
- example:
An
image.Imagethat will not encode draws an error placeholder instead of the image and fails the run, without stopping the rest of the page. -
confis an optional configuration, at most one.
// ImageConf is the configuration for the Image component
type ImageConf struct {
tgframe.Base // ID
// Width is the width of the image (e.g. "100px", "50%")
Width string
// Format is the format of the image, default is "png".
// For []byte, the MIME is detected from magic bytes; Format is the fallback.
Format ImageFormat
}
Example
tgcomp.Image(p.Main, "https://http.cat/100",
&tgcomp.ImageConf{
Width: "200px",
})
tgcomp.Image(p.Main, "https://http.cat/100", &tgcomp.ImageConf{Width: "200px"})
