public function __construct($input) { $mod = cms_utils::get_module('CGSmartImage'); $this->_loc = $mod->GetPreference('croptofit_default_loc', 'c'); if (cge_array::is_hash($input)) { if (isset($input['width'])) { $this->_dest_w = (int) $input['width']; $this->_dest_h = (int) $input['height']; } else { if (isset($input['w'])) { $this->_dest_w = (int) $input['w']; $this->_dest_h = (int) $input['h']; } } if (isset($input['color']) && $input['color'] != '') { $this->_color = strtolower($input['color']); } if (isset($input['alpha'])) { $this->_alpha = (int) $input['alpha']; } } else { if (is_array($input)) { if (count($input) >= 2) { $this->_dest_w = (int) trim($input[0]); $this->_dest_h = (int) trim($input[1]); if (count($input) >= 3) { if ($input[2] != '') { $this->_color = strtolower($input[2]); } if (count($input) >= 4) { if ($input[3] != '') { $this->_alpha = (int) $input[3]; } } } } } } $this->_dest_w = cgsi_utils::trim_to_device('width', $this->_dest_w); $this->_dest_h = cgsi_utils::trim_to_device('height', $this->_dest_h); $this->_alpha = max(0, min(127, $this->_alpha)); // todo: convert color name into rgb. if ($this->_dest_h <= 0 || $this->_dest_w <= 0) { throw new Exception('Invalid values specified for Croptofit filter constructor'); } }
public function __construct($input) { $mod = cms_utils::get_module('CGSmartImage'); $this->_loc = $mod->GetPreference('croptofit_default_loc', 'c'); if (cge_array::is_hash($input)) { if (isset($input['width'])) { $this->_dest_w = (int) $input['width']; $this->_dest_h = (int) $input['height']; } else { if (isset($input['w'])) { $this->_dest_w = (int) $input['w']; $this->_dest_h = (int) $input['h']; } } if (isset($input['loc']) && in_array($input['loc'], self::$_valid_locs)) { $this->_loc = $input['loc']; } if (isset($input['upscale'])) { $this->_upscale = (int) $input['upscale']; } } else { if (is_array($input)) { if (count($input) >= 2) { $this->_dest_w = (int) trim($input[0]); $this->_dest_h = (int) trim($input[1]); if (count($input) >= 3 && in_array($input[2], self::$_valid_locs)) { $this->_loc = $input[2]; } if (count($input) >= 4) { $this->_upscale = (int) $input[3]; } } } } if (!$this->_upscale) { $this->_dest_w = cgsi_utils::trim_to_device('width', $this->_dest_w); $this->_dest_h = cgsi_utils::trim_to_device('height', $this->_dest_h); } if ($this->_dest_h <= 0 || $this->_dest_w <= 0) { throw new Exception('Invalid values specified for Croptofit filter constructor'); } }
protected function _transform_edge(CGImageBase $src) { //find the longest edge of image and resize based on it if ($src['width'] > $src['height']) { $new_w = $this->_edge; $new_w = cgsi_utils::trim_to_device('width', $new_w); $new_h = (int) ($this->_edge * $src['height'] / $src['width']); return $this->_transform($src, $new_w, $new_h); } else { $new_h = $this->_edge; $new_h = cgsi_utils::trim_to_device('height', $new_h); $new_w = (int) ($this->_edge * $src['width'] / $src['height']); return $this->_transform($src, $new_w, $new_h); } }