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

Site Wide Default Image Processing > More than image quality? Crop?

Solved by Timothy Bradley View solution

Started by Timothy Bradley 9 years ago · 3 replies · 818 views
9 years ago

Greetings

New to Grav, and am trying to learn by setting up a blog for my parents.

I just know they're going to be dropping in massive high res photos in without processing, and there is 0% chance I can teach them the media actions.

To stop massive files being served, I want to be able to set site wide rule to say crop to width of say 1000px.

Is this possible?

A bit like quality in config system.yaml's images > default_image_quailty, but for ratio-respecting width cropping.

Thank you for any help in advance!

last edited 12/15/17 by Timothy Bradley
9 years ago

Hello,

I don't know about that, but you could define the resize and the quality in your twig file.
Let's say each post has it's own set of pictures.

You could write write your twig file to render a list of resized picture that would open a bigger one on click.

Or do you need them to put the photo wherever they want in the posts ?

👍 1
9 years ago

Thank you, @AmauryH, but yes, I need a solution that applies anywhere in the post/page.

My parents are 73 and 75 years old, and are non-technical. They will want to drop images into their posts, and because of their cameras etc the images they take are large ~8MB+.

They will not cope with Markdown image actions, and I cannot rely on them to do any processing of the images before uploading.

So I would like to keep it stupidly simple (KISS) for them.

I would like a default settling - like the config quality setting - which sets a maximum image width size when drag & dropping it from their admin.

It is not perfect (an automatic srcset solution would be best), but at least this will stop their pages being a massive - ~40MB+ assuming they do their usual 5 or so images per "dairy" post.

9 years ago Solution

THE SOLUTION

TL,DR: To add default/automatic image processing

Edit:-----------user/config/media.yaml

At top on:------types.defaults.image.filters.default

Add item:------ [{youFilter}, {yourValue1}, {yourValue2}]

My example:

YAML
types:
  defaults:
    type: file
    thumb: media/thumb.png
    mime: application/octet-stream
    image: 
      filters:
        default:
          - [resize, 1000]  <-- *this is what I added to set widths*
          - enableProgressive <--*this was already there*

Note: I changed structure to my liking.

Before the relevant part looked like this:

TXT
types:
  defaults:
    type: file
    thumb: media/thumb.png
    mime: application/octet-stream
    image: 'filters: { default: [enableProgressive] }'

So you could do:

TXT
types:
  defaults:
    type: file
    thumb: media/thumb.png
    mime: application/octet-stream
    image: 'filters: { default: [*yourFilterHere*], [enableProgressive] }'
👍 4

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 53 10 hours ago
Support · by Anna, 3 days ago
2 60 13 hours ago
Support · by Justin Young, 14 hours ago
1 30 14 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 56 5 days ago