I was wondering, how can I automatically resizing (all) images, inserted into a webpage through the upload feature. What’s the best way to do it? I searched for it for a long time, but couldn’t find anything.
My problem is the following: Users should be able to upload original, full size photos from their cameras. But these photos should not be distributed from the website. These photos should all be resized automatically, without applying a filter to each photo manually with Twig or Markdown.
There is currently no ‘hook’ to do work on uploading an image via the admin. However you can set media defaults so that all images receive some processing.
To do that you can look at the system/config/media.yaml file and override this in your user/config/media.yaml file. Specifically the image filters section:
Currently no. This is because there is an optimization check so images are not processed at all if there are no filters manually added.
Any processing is going to take time and potentially degrade photo quality (multiple processing of jpeg images is a lossy process). So if you don’t tell Grav to do any processing, it wont.
I’m thinking about adding an option to make this configurable though. Is this something you would find useful?
So now, when i try to open a page on my webhoster with some images, this error occurs:
Whoops \ Exception \ ErrorException (E_ERROR)
Out of memory (allocated 62914560) (tried to allocate 2650801 bytes)
in the file htdocs/next/vendor/gregwar/image/Gregwar/Image/Adapter/GD.php
Well, really that’s a problem with some of your image being too large and PHP’s GD library is using too much memory to resize them. So two real options for you:
Resize those really large images before uploading them to PHP