Fitting image in border but still keep ratio

When I add a caption to an image it gains a border and some text underneath it. I want to have multiple pictures with the same border size. The problem is if I do it with different images of different sizes, the size of the border is, of course, different as well. And if I resize the border to fit the size I want it to be the image gets distorted and does not keep its ratio. Is there a way to automatically resize the image so it fits the border but still keeps its ratio? The image would then fit horizontally or vertically (or perfect if it has the same ratio as the border).

I already tried to add margins to the image inside the border but for all the images I have it would take very long and I think there must be a more elegant solution.

There is a little bit weird work around.

  1. Insert a picture, open the style manager (F11) > Graphics should should be selected/highlighted
  2. Modify the Graphics style this way: Width = 9 cm (or other); Height = [x] AutoSize.
    From now on the Graphics style can be applied to each inserted image/Caption frame (see points below)
  3. Insert any new image, it can be wider or slimmer than the chosen 9 cm
  4. Right click on the image (green handles/grip points): Insert Caption
  5. Frame (not image!) is selected (green handles/grip points): Double click on Graphics in the style manager
  6. Image (and frame) moves proportional to chosen width, as desired

Little bug: Between upper boundary of frame and image you have some little space. If there is not defined any border this mistake is not to be seen in the print preview or in the printout. If you define a border, so don’t synchronize the distances; it is possible to diminish the bug (set the upper distance on 0, the other ones on ca 0,2 cm).

Tried on: LibreOffice 5.3.5.2

PS: I hope this is a “a more elegant solution” :wink:

PPS: An open question and - in my view - unsolved is the problem to save graphic and frame properties anchored “as character” in current file and within the default page style. The update style function seems to work roguely.