You are here

function image_im_advanced_settings_validate in Image 5

Same name and namespace in other branches
  1. 5.2 contrib/image_im_advanced/image_im_advanced.module \image_im_advanced_settings_validate()
  2. 6 contrib/image_im_advanced/image_im_advanced.module \image_im_advanced_settings_validate()
  3. 7 contrib/image_im_advanced/image_im_advanced.module \image_im_advanced_settings_validate()

Validate settings form.

File

contrib/image_im_advanced/image_im_advanced.module, line 115

Code

function image_im_advanced_settings_validate($form) {
  $options = $form['#post']['image_im_advanced_options'];

  // Check that the JPEG quality is a valid number.
  if (!is_numeric($options['jpeg_quality']) || $options['jpeg_quality'] < 1 || $options['jpeg_quality'] > 100) {
    form_set_error('image_im_advanced_options][jpeg_quality', t('The JPEG quality must be a positive number between 1 and 100.'));
  }

  // Check that the strip dimensions are valid.
  if (!preg_match('/^\\d+x\\d+$/', $options['strip'])) {
    form_set_error('image_im_advanced_options][strip', t('The strip metadata threshold must be specified in the form <em>NxN</em>. Example: <em>150x150</em>.'));
  }

  // Check the unsharp mask values.
  if (!empty($options['unsharp']['amount'])) {
    if (!is_numeric($options['unsharp']['amount']) || $options['unsharp']['amount'] < 0) {
      form_set_error('image_im_advanced_options][unsharp][amount', t('The sharpness amount must be specified as a positive number.'));
    }
    if (!is_numeric($options['unsharp']['radius']) || $options['unsharp']['radius'] < 0) {
      form_set_error('image_im_advanced_options][unsharp][radius', t('The sharpness radius must be specified as a positive value.'));
    }
  }

  // Check that if the color profile is provided that it's a readable file.
  if (!empty($options['profile']['path']) && (!is_file($options['profile']['path']) || !is_readable($options['profile']['path']))) {
    form_set_error('image_im_advanced_options][profile][path', t('The ICC profile could not be read.'));
  }
}