'textfield', '#title' => t('Compression Quality'), '#description' => t('Ranges from 1 to 100. Higher values mean better image quality, but bigger files.'), '#size' => 10, '#maxlength' => 3, '#default_value' => variable_get('imageapi_imagick_quality', 75), '#field_suffix' => '%', '#validate' => array('imageapi_imagick_quality_element_validate' => array()), ); return system_settings_form($form); } function imageapi_imagick_quality_element_validate($element) { if ($element['#value'] < 0 || $element['#value'] > 100) { form_set_error($element['#name'], t('Compression Quality must be a value between 1 and 100.')); } } function imageapi_imagick_image_open($image) { try { $image->res = new Imagick($image->source); $image->res->setCompressionQuality(variable_get('imageapi_imagick_quality', 75)); } catch(Exception $e) { return FALSE; } return $image; } function imageapi_imagick_image_close($image, $destination) { try { return $image->res->writeImage($destination); } catch(Exception $e) { //print_r($e); return FALSE; } } function imageapi_imagick_image_crop(&$image, $x, $y, $width, $height) { try { $image->res->cropImage($width, $height, $x, $y); $image->info['width'] = $width; $image->info['height'] = $height; } catch (Exception $e) { return FALSE; } return TRUE; } function imageapi_imagick_image_resize(&$image, $width, $height) { try { $image->res->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1); $image->info['width'] = $width; $image->info['height'] = $width; } catch (Exception $e) { return FALSE; } return TRUE; } function imageapi_imagick_image_rotate(&$image, $degrees, $bgcolor) { $image->res->imageRotate(new ImagickPixel($bgcolor), $degree); return TRUE; } function imageapi_imagick_image_desaturate(&$image) { $image->res->setImageType(Imagick::IMGTYPE_GRAYSCALE); return TRUE; }