Limit number of upload in Imagefield depending on a specific field
This will need customising to your specific situation, but the basic idea is to add a validation handler to the node form and perform a check in there, e.g.

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'the_form_id') {
    $form['#validate'][] = 'MYMODULE_images_validate_limit';
  }
}

function MYMODULE_images_validate_limit($form, &amp;$form_state) {
  $images_submitted = count($form_state['values']['field_image'][LANGUAGE_NONE]);

  if ($images_submitted &gt; function_to_get_limit()) {
    form_set_error('field_image', t('Too many images'));
  }
}