0

I want to limit the user to only upload profile pictures of 160x160 size. What is the simplest way to validate that the resolution of uploaded avatar picture is actually 160x160, and provide an error message if it's not?

0

You need to form alter user_account_form(). Remove user_validate_picture() as the validator. Duplicate that function into your own module, and add as a validator. Inside that, update the size line to be:

'file_validate_image_resolution' => array('160x160', '160x160'),

This should enforce the same value for both minimum and maximum size before the file gets saved off. I don't think you can add a second validator; I think the size check needs to be done in one step.

0

Well you can change the picture upload dimensions here at /admin/config/people/accounts.

That doesn't limit the actual upload to those dimensions though. You would need a custom validation handler for that I suppose. The user profile picture is a bit tricky actually because even if your form fails validation and doesn't get submitted, the new avatar is used anyway - as reported here.

You could always add your own custom image field to profiles instead - then you have all the control of a standard image field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.