Clients have been uploading huuuge images, then complaining that the server is running out of memory.
Ofcourse one could bump the amount of memory, but this just introduces an arms race.
What hooks can I add to impose a maximum image size ( dimensions, not filesize ) on files uploaded, e.g. No you can’t upload that 8 Megapixel shot, resize it first to < 2 Megapixels.
To be clear, I am talking about image size, not file size, aka Image height, and Image width
Basically you just retrieve the info via
getimagesize()
, a basic PHP function, a then handle your errors with notes.The plugin
A basic plugin as a starting point:
Here’s my take on it
I understand that you only need to deny uploads based on Image Dimension. But I just want to add a note, this will not prevent your server from getting Out of Memory.
Image dimensions
is available once the data has been fully uploaded on the server (like Apache), and hence server memory is consumed.You should consider limiting the Upload size at Apache and PHP level, and then if you want, you can also restrict at WordPress level for Image Dimension.
To set the max upload size in Apache,
In php.ini, set: