Can you require a minimum image size in the panel?

I have several templates that contain a large cover image and then several side images. I would like set a minimum size or the cover image (something like 1500 x 600) and a minimum size for the side image ( maybe width of 500).

I don’t see any way of doing this in the panel. Is there a solution that I have missed?

Since you can only define maximum dimensions within the blueprint settings, I think this could be achieved with panel hooks.

I would use panel.file.upload and panel.file.replace to check the smaller size (side image). This cookbook recipe (with max instead of min width) could be a good starting point.

After that, I would use an image field to select the cover image. Inside hook you could load the selected file and check if its dimensions fit your needs.


I would use permissions:

Edit: Come to think about it, the problem with this approach (and the one suggested by @flokosiol) is that you can’t define this on a per field basis, as both options refer to the uploading process, not to selecting images in a field. The problem with the hook is that it would blow up the images, which is probably not the intended behavior.

Another option that comes to mind is to create a custom validator, similar to the size validator, but checking if file size is greater than. (not tested)

1 Like

My idea was not to resize the images on upload, but just check the dimensions and otherwise throw an error. Of course you need to check the smallest dimensions used for the whole page (page type). Might not be the best solution …

Personally, I would only use hook to check select images in combination with the great gallery field plugin by @timoetting to select the side images and the default image field to select the cover image.

Well, the problem is that a hook does not return anything. It seems that you can throw an alert but only in combination with a redirect: Hooks & Flash Message

Thank you for the suggestions. I agree that a hook will probably not be the best solution since it does not return anything. I will look into the custom validator option and see if I can get that to work.