A little help for a script

A little help for a script

Hello
I'll try to explain what I want to do. I have multiple images to select and I'd like to limit the user selecting an image or images with the total with lower than 990px. I have the with information into the 'alt' of each images. It would be something like this:
- if you've chosen one image of 990px you can't select more images
- if you've chosen one image of 728px you can select another of 250px i.e
The max images are two. 
Could you please help me to start? I'm stuck! 
Thank you!!