Example #1
0
 /**
  * Applies a smooth filter.
  *
  * @access public
  * @since  8.1
  * @url    http://www.tuxradar.com/practicalphp/11/2/15
  * @param  integer $level    -100 = max smooth, 100 = min smooth
  *
  * @return mixed             bool | object WP_Error
  */
 public function smooth($level = 0)
 {
     $level = (double) cnUtility::remapRange($level, -100, 100, -8, 8);
     if ($level >= -8 && $level <= 8 && filter_var($level, FILTER_VALIDATE_FLOAT) !== FALSE) {
         if (function_exists('imagefilter')) {
             if (imagefilter($this->image, IMG_FILTER_SMOOTH, $level)) {
                 return TRUE;
             }
         }
     }
     return new WP_Error('image_smooth_error', __('Image smooth failed.', 'connections'), $this->file);
 }
 /**
  * Adjust the image contrast.
  *
  * @access public
  * @since  8.1
  * @param  integer $level -100 = max contrast, 0 = no change, +100 = min contrast (note the direction!)
  *
  * @return object         Imagick | WP_Error
  */
 public function contrast($level)
 {
     if ($level >= -100 && $level <= 100 && filter_var($level, FILTER_VALIDATE_FLOAT) !== FALSE) {
         try {
             $sharpen = $level <= 0 ? TRUE : FALSE;
             $midpoint = cnUtility::remapRange($level, -100, 100, -20, 20);
             $quanta = $this->image->getQuantumRange();
             return $this->image->sigmoidalContrastImage($sharpen, abs($midpoint), 0.5 * $quanta["quantumRangeLong"]);
         } catch (Exception $e) {
             return new WP_Error('image_contrast_error', $e->getMessage(), $this->file);
         }
     }
     return new WP_Error('image_contrast_error', __('Image contrast failed.', 'connections'), $this->file);
 }