Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Resize uploaded images

Solved by Oliver Scholz View solution

Started by Miceal Gallagher 9 years ago · 3 replies · 1253 views
9 years ago

If I want to resize uploaded images when named

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

9 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
9 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
9 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 Anna, 4 days ago
1 96 4 days ago
Support · by Anna, 3 weeks ago
1 265 3 weeks ago
Support · by webmasterodp, 1 month ago
4 380 1 month ago
Support · by nwhitfield, 1 month ago
2 351 1 month ago
Support · by stell, 2 months ago
5 657 1 month ago