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

Force image resize on upload

Started by Muut Archive 10 years ago · 3 replies · 1069 views
10 years ago

Is there a way to force ANY image uploaded in Grav via admin plugin to be resized to certain width and auto-height when uploaded? Or even on a field by field basis? Though a global setting would be better.

10 years ago

You can limit the size of the file, but as far as I know, you can not limit width on upload natively.
Is there a reason why you would want your file to have a certain width? I ask because you can easily manipulate image with twig. https://learn.getgrav.org/content/media

10 years ago

I want to resize on upload because I don't want clients to have to resize image themselves prior to uploading (which is how limiting the filesize works) because many of my clients don't know how or don't want the inconvenience - but I also don't want clients uploading 6000px wide 20mb images when i'm resizing them all with Twig anyway to no wider than 1400px which brings the size from 20mb to about 400kb max. So it's about server space. I have a couple of very simple websites that didn't have image resizing from the start and after 2 years are 1.5gb folder size just in images. If there is a function to resize on upload (which is common with CMS's) then I can resize any image uploaded to just 1400px wide (auto height) and then my images will all be big enough, but not take rediculous amounts of server space.

10 years ago

Even if it's not possible natively, there's no reason you couldn't do a plugin. I don't immediately see a hook, but it should be easy enough to create a hook that fires once the file is uploaded but before it is fully committed. You could even just do a basic cron job that scans the images folder and cuts down large images.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1357 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago