How to change inner alignment of an image with fixed width and height

I have an image with a fixed height and width, however I dont always know what the actual dimensions of logo.png are going to be. Sometimes the logo is smaller than those dimensions.

image(
    "images/logo.png",
    height: 3cm,
    width: 6cm,
    alt: none,
    fit: "contain",
  )

My problem is, in case the logo.png is smaller, the image is always centered inside the image block and I can’t get it right aligned. Is there something I am missing? Or is there a workaround?
I tried omitting either height or width, but some logos are either too tall or too wide, so I have to set both as a maximum.

UPDATE: I think I got want I needed when putting the image in a box and setting the width and height of that box instead. Wrapping the box with align(right, …) seems to do the trick.
align(alignment.right + alignment.horizon, box(height: 3cm, width: 6cm, image("images/logo.png", alt: none, fit: "contain")))

Hi, welcome to the Typst forum! Nice that you found a way to solve your issue! Maybe a more idiomatic solution would be:

#block(
  width: 6cm,
  height: 3cm,
  stroke: black, // for debugging
  {
    set align(right+horizon)
    image("images/logo.png")
  }
)

(You can replace block with box if you want inline content.)

1 Like

Thanks for your help!
Your suggestion doesn’t completely do what I need in my case, because it doesn’t align the block. But this can be achieved by pulling set align(right+horizon) above #block :slight_smile:

1 Like