Image

Image component display an image.

API

Interface

func Image(c *tgframe.Container, img any, conf ...*ImageConf)

Parameters

  • c is Parent container.

  • img is 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 to Format if unknown
    • string: a url or base64 encoded image
      • example:
        • url: https://http.cat/100
        • base64 uri: data:image/png;base64,...

    An image.Image that will not encode draws an error placeholder instead of the image and fails the run, without stopping the rest of the page.

  • conf is 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"})

image component