A new feature for SilverStripe should be ...

Allow to resize images before storing them in assets

gd2 is memory hungry and trying to manipulate an image big enough can easily crash a small webserver. I have seen that many times on different servers, and you can meet this issue by just calling getimagesize().

At the end you will end up with a blob in your assets that cannot be manipulated. It will also crash the CMS whenever SilverStripe tries to make a thumbnail. And no matter what you say to the client: he will continue to upload his 4000x6000 raw JPEGs directly from the camera.

My propose is to allow to customise the default behavior of just blindly copy the uploaded file, e.g. by providing an extension hook in Upload::load() to inject some code instead.

The next step would be to provide proper configuration options to (optionally) change the default behavior and scale all the images with imagemagick automagically from Upload::load().

21 votes
Sign in
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Nicola Fontana shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Sign in with: facebook google
Signed in as (Sign out)
  • Luca Cattide commented  ·   ·  Flag as inappropriate

    This would be a very useful feature. Just these days I'm experiencing its lack on an ongoing project.

  • Nicola Fontana commented  ·   ·  Flag as inappropriate

    @Sam Yes, the basic idea would be to spawn an external command, just to avoid PHP memory issues altogether.

    @Ingo I encountered a case (in plain PHP) where just requesting the image size crashed mod_php. IIRC I was using getimagesize() though. This is why I proposed a hook, so you can either implement some heuristic or spawn an external command.

  • AdminIngo Schommer (Admin, SilverStripe) commented  ·   ·  Flag as inappropriate

    We've tried to avoid having those resize requests exceeding available PHP memory by implementing some heuristics: https://github.com/silverstripe/silverstripe-assets/blob/dc175b6587699ecc5bafca42ecd069a8e92469f8/src/GDBackend.php#L160

    But you're right, that just leads to an image that can't be manipulated through SilverStripe code (e.g. to produce a more lightweight thumbnail). Max filesize limitations on upload isn't very effective either, since fairly small file sizes can cause huge memory use when run through GD2 (and no compression).

    You could look into moving the heuristics into upload, and allow configuration of max image dimensions there? Alternatively, a hook in Upload::load() sounds good to me.

Feedback and Knowledge Base