public function transform(CGImageBase $src) { $type = 'image/png'; $_dest = new CGImageBase(array($type, $src['width'], $src['height'])); imagecopy($_dest['rsrc'], $src['rsrc'], 0, 0, 0, 0, $src['width'], $src['height']); list($_r, $_g, $_b) = cgsi_utils::color_to_rgb($this->_color); $color = imagecolorallocatealpha($_dest['rsrc'], $_r, $_g, $_b, $this->_alpha); imagecolortransparent($_dest['rsrc'], $color); $_dest['transparent'] = $color; return $_dest; }
public function transform(CGImageBase $src) { $type = 'image/jpeg'; if (!function_exists('imagerotate')) { throw new Exception('imagerotate function not found'); } $_dest = new CGImageBase(array($type, $src['width'], $src['height'])); list($_r, $_g, $_b) = cgsi_utils::color_to_rgb($this->_color); $color = imagecolorallocate($_dest['rsrc'], $_r, $_g, $_b); imagefill($_dest['rsrc'], 0, 0, $color); if ($this->_pct == 100) { imagecopy($_dest['rsrc'], $src['rsrc'], 0, 0, 0, 0, $src['width'], $src['height']); } else { imagecopymerge($_dest['rsrc'], $src['rsrc'], 0, 0, 0, 0, $src['width'], $src['height'], $this->_pct); } return $_dest; }
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'); } }
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Or read it online: http://www.gnu.org/licenses/licenses.html#GPL # #------------------------------------------------------------------------- #END_LICENSE if (!isset($gCms)) { return; } $outp = cgsi_utils::process_image($params); $silent = $this->GetPreference('silent', 0); if (isset($params['silent'])) { $silent = (int) $params['silent']; } if (isset($outp['error']) && $outp['error'] != '') { if (!$silent) { trigger_error($outp['error']); } audit('', $this->GetName(), $outp['error']); return; } if (isset($outp['output'])) { echo $outp['output']; } #
public function transform(CGImageBase $src) { if ($this->_angle == 0) { return $src; } // nothing to do. $type = $src['type']; if ($this->_alpha != 0) { $type = 'image/png'; } if ($this->_alpha == 127) { $this->_color = 'transparent'; } if ($this->_color == 'transparent') { $type = 'image/png'; } if (!function_exists('imagerotate')) { throw new Exception('imagerotate function not found'); } $_dest = new CGImageBase(array($type, $src['width'], $src['height'])); if (!$this->_color || $this->_color == 'transparent') { $tcolor = cgsi_utils::get_transparent_color($src); } else { list($_r, $_g, $_b) = cgsi_utils::color_to_rgb($this->_color); $tcolor = imagecolorallocatealpha($_dest['rsrc'], $_r, $_g, $_b, $this->_alpha); } $res = imagerotate($src['rsrc'], $this->_angle * -1, $tcolor); if ($res === FALSE) { throw new Exception('Error applying filter ' . IMG_FILTER_COLORIZE); } imagecolortransparent($res, $tcolor); $_dest['rsrc'] = $res; $_dest['width'] = imagesx($res); $_dest['height'] = imagesy($res); return $_dest; }
# as an addon module to CMS Made Simple. You may not use this software # in any Non GPL version of CMS Made simple, or in any version of CMS # Made simple that does not indicate clearly and obviously in its admin # section that the site was built with CMS Made simple. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Or read it online: http://www.gnu.org/licenses/licenses.html#GPL # #------------------------------------------------------------------------- #END_LICENSE if (!isset($gCms)) { return; } if (!$this->GetPreference('responsive')) { return; } $cn = cgsi_utils::get_responsive_cookiename(); if (!isset($_COOKIE[$cn])) { $tpl = $this->CreateSmartyTemplate('responsive.tpl'); $tpl->assign('cookiename', $cn); $tpl->display(); } # # EOF #
public function transform(CGImageBase $src) { // quick optimization (nothing to do) //if( $this->_dest_w == $src['width'] && $this->_dest_h == $src['height'] ) return $src; $type = $src['type']; if ($this->_alpha == 127) { $this->_color = 'transparent'; } if ($src->supports_transparency() && !$this->_color) { $this->_color = 'transparent'; } if ($this->_color == 'transparent' || $this->_alpha > 0) { $type = 'image/png'; } if ($this->_color == 'transparent') { $this->_alpha = 127; } // create our destination image. $_dest = new CGImageBase(array($type, $this->_dest_w, $this->_dest_h)); // fill our image with a color (or transparent) $color = null; if ($this->_color) { if ($this->_color == 'transparent') { // need to get a transparent color from someplace $color = $_dest['transparent']; } else { $_r = $_g = $_b = 255; list($_r, $_g, $_b) = cgsi_utils::color_to_rgb($this->_color); $color = imagecolorallocatealpha($_dest['rsrc'], $_r, $_g, $_b, $this->_alpha); } } if ($this->_alpha > 0 && $this->_alpha < 127) { $_dest['savealpha'] = TRUE; imagealphablending($_dest['rsrc'], TRUE); imagesavealpha($_dest['rsrc'], TRUE); } if ($this->_color == 'transparent') { imagecolortransparent($_dest['rsrc'], $color); imagealphablending($_dest['rsrc'], FALSE); } imagefill($_dest['rsrc'], 0, 0, $color); if ($this->_dest_w / $this->_dest_h > $src['width'] / $src['height']) { // height is greater... $new_h = $this->_dest_h; $new_w = round($new_h / $src['height'] * $src['width'], 0); } else { // width is greater. $new_w = $this->_dest_w; $new_h = round($new_w / $src['width'] * $src['height'], 0); } $x0 = (int) (($this->_dest_w - $new_w) / 2); $y0 = (int) (($this->_dest_h - $new_h) / 2); // resize the big image into the temporary transparent image $res = imagecopyresampled($_dest['rsrc'], $src['rsrc'], $x0, $y0, 0, 0, $new_w, $new_h, $src['width'], $src['height']); if ($res === FALSE) { throw new Exception('Resizetofit - stage 1 - failed'); } return $_dest; }
public function transform(CGImageBase $src) { $width = $src['width']; $height = $src['height']; $radius = $this->_radius; $type = $src['type']; $color = null; $r = $g = $b = 255; if ($src->supports_transparency() && !$this->_color) { $this->_color = 'transparent'; } if ($this->_color == 'transparent') { $type = 'image/png'; } $_dest = new CGImageBase(array($type, $width, $height)); imagecopy($_dest['rsrc'], $src['rsrc'], 0, 0, 0, 0, $width, $height); if ($this->_color) { if ($this->_color == 'transparent') { // get the dest imagages transparent color. $color = $_dest['transparent']; if (!$color) { list($r, $g, $b) = cgsi_utils::find_unused_color($_dest); } } else { // use the specified rgb. list($r, $g, $b) = cgsi_utils::color_to_rgb($this->_color); } } if (!$color) { if ($this->_color == 'transparent') { $color = imagecolorallocatealpha($_dest['rsrc'], $r, $g, $b, 127); } else { $color = imagecolorallocate($_dest['rsrc'], $r, $g, $b); } } if ($this->_color == 'transparent') { $_dest['transparent'] = $color; imagecolortransparent($_dest['rsrc'], $color); imagealphablending($_dest['rsrc'], FALSE); } // round the corners. imagearc($_dest['rsrc'], $radius - 1, $radius - 1, $radius * 2, $radius * 2, 180, 270, $color); imagefilltoborder($_dest['rsrc'], 0, 0, $color, $color); imagearc($_dest['rsrc'], $width - $radius, $radius - 1, $radius * 2, $radius * 2, 270, 0, $color); imagefilltoborder($_dest['rsrc'], $width - 1, 0, $color, $color); imagearc($_dest['rsrc'], $radius - 1, $height - $radius, $radius * 2, $radius * 2, 90, 180, $color); imagefilltoborder($_dest['rsrc'], 0, $height - 1, $color, $color); imagearc($_dest['rsrc'], $width - $radius, $height - $radius, $radius * 2, $radius * 2, 0, 90, $color); imagefilltoborder($_dest['rsrc'], $width - 1, $height - 1, $color, $color); return $_dest; }
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); } }
public static function get_device_capabilities() { $mod = \cms_utils::get_module(MOD_CGSMARTIMAGE); if ($mod->GetPreference('responsive')) { $cookie_enc = cms_cookies::get(cgsi_utils::get_responsive_cookiename()); if ($cookie_enc) { $data = json_decode($cookie_enc, TRUE); return $data; } } }