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.

Support

Resize uploaded images

Solved by Oliver Scholz View solution

Started by Miceal Gallagher 8 years ago · 3 replies · 780 views
8 years ago

If I want to resize uploaded images when named

featureimage.jpg, whats the best way to do that?

8 years ago Solution

Well, there's a plugin that reportedly can resize images on upload. I have no experience with it, though.

However, given the name "featureimage", it sounds like what you want is to display a resized image for a specific page template. IMO, that is best achieved in the Twig for that page. For instance:

TWIG
  {% set my_image = page.media['featureimage.jpg'] %}
  {{ my_image.cropZoom(200, 200).html() }}

See page.media() and the various resize functions.

👍 1
8 years ago

Yep, that's exactly what I want to do!

I tried that plugin you mentioned but it can't discern based on filename.

Your code snippet works a treat!

Thank you

last edited 04/22/18 by Miceal Gallagher
8 years ago

When a contributor uploads an image that is larger than the configured size, Imsanity will automatically scale it down to the configured size and replace the original image. Imsanity also provides a bulk-resize feature to selectively resize previously uploaded images to free up disk space.

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 56 13 hours ago
Support · by Anna, 3 days ago
2 61 16 hours ago
Support · by Justin Young, 17 hours ago
1 32 17 hours ago
Support · by Duc , 1 week ago
2 66 5 days ago
Support · by Colin Hume, 1 week ago
2 59 5 days ago