Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

cropResize does not work as expected for images in portrait format

Solved by Anna View solution

Started by Anna 7 years ago · 1 replies · 489 views
7 years ago

I'm using the following code to list a bunch of articles with an image each. The image part is:

TWIG
{{ image.cropResize(300,300).html('','Foto','right dreh'~drehgrad) }}

This works a treat for landscape shaped images, they get resized to a width of 300px and the appropriate height. However, portrait pictures also get resized to a width of 300px and correspondingly a much larger height. This isn't quite what I expected – I would like the longer side of the image, whichever that is, to be 300px, and the other to rescale accordingly. How can I do this?

7 years ago Solution

UGH so I finally figured it out – cropResize was working fine, just my CSS was messed up. I hadn't accounted for the standard img { width: 100%; }

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 193 2 months ago
Themes & Styling · by Ian, 2 months ago
3 91 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 451 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 45 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 125 3 months ago