public function setOptions($options = array()) { require_once AK_CONTRIB_DIR . DS . 'pear' . DS . 'Image' . DS . 'Tools.php'; $this->Image->Transform =& Image_Tools::factory('Watermark'); $default_options = array('image' => $this->Image->Transform->createImage($this->Image->image_path)); $this->options = array_merge($default_options, $options); if (empty($this->options['mark']) || !is_file($this->options['mark'])) { trigger_error(Ak::t('Option "mark" does not contain a valid Watermark image path'), E_USER_ERROR); } $this->_variablizeOptions_($this->options); $this->Image->Transform->set($this->options); }
function smarty_function_image($params, &$smarty) { require_once $smarty->_get_plugin_filepath('modifier', 'curlang'); $src = ""; $width = 0; $height = 0; $bevel = A_MODE == 1 ? 4 : 0; $attr = ""; $DOMAIN = !empty($params['domain']) ? preg_replace("/[^a-zA-Z0-9]+/i", "", $params['domain']) : A::$DOMAIN; if (!empty($params['data']) && is_array($params['data'])) { if (array_key_exists('path', $params['data'])) { $row = $params['data']; unset($params['data']); } elseif (isset($params['data'][0]) && array_key_exists('path', $params['data'][0])) { $row = array_shift($params['data']); } if (!empty($row['path'])) { $src = $row['path']; } } elseif (!empty($params['id'])) { if ($row = A::$DB->getRowById($params['id'], $DOMAIN . "_images")) { $src = $row['path']; } } $alt = !empty($row['caption']) ? $row['caption'] : ""; foreach ($params as $_key => $_val) { switch ($_key) { case "id": case "data": case "domain": case "lightbox": case "popup": case "noimgheight": case "empty": break; case "src": $src = $_val; break; case "width": $width = $_val; if (!isset($row['width'])) { $attr .= " {$_key}=\"{$width}\""; } elseif ($width <= $row['width']) { if (!empty($scale)) { $_width = ceil($row['width'] / $scale); if ($_width < $width) { $width = (int) $_width; } //$attr.=" $_key=\"$width\""; $width = 0; } else { $scale = $row['width'] / $width; $attr .= " {$_key}=\"{$width}\""; } } elseif ($width > $row['width'] && !empty($scale)) { $_width = ceil($row['width'] / $scale); if ($_width < $width) { $width = (int) $_width; } $attr .= " {$_key}=\"{$width}\""; $width = 0; } break; case "height": $height = $_val; if (!isset($row['height'])) { $attr .= " {$_key}=\"{$height}\""; } elseif ($height <= $row['height']) { if (!empty($scale)) { $_height = ceil($row['height'] / $scale); if ($_height < $height) { $height = (int) $_height; } //$attr.=" $_key=\"$height\""; } elseif ($row['height'] > $row['width']) { $scale = $row['height'] / $height; $attr .= " {$_key}=\"{$height}\""; } } break; case "bevel": $bevel = (int) $_val; break; case "imgid": $attr .= " id=\"{$_val}\""; break; case "alt": $alt = $_val; break; default: $attr .= " {$_key}=\"{$_val}\""; } } $attr .= " alt=\"" . htmlspecialchars($alt) . "\""; if (!empty($src)) { $src = preg_replace("/^\\//i", "", $src); } elseif (!empty($params['empty'])) { $src = "templates/" . $DOMAIN . "/images/" . preg_replace("/[.]{2..}/i", "", $params['empty']); if (is_file($src)) { return "<img src=\"/{$src}\"{$attr}/>"; } } else { return ""; } if ($width > 0 && (!isset($row['width']) || $width < $row['width']) || $height > 0 && (!isset($row['height']) || $height < $row['height'])) { $path = pathinfo($src); if (preg_match("/^[.\\/]*(files|images)\\/([a-zA-Z0-9-_]+)\\//i", $src, $matches)) { $cachename = 'cache/images/' . $matches[2] . '/' . $path['filename']; } else { $cachename = 'cache/images/' . $path['filename']; } if ($width > 0) { $cachename .= '_w' . $width; } if ($height > 0) { $cachename .= '_h' . $height; } if ($bevel > 0) { $cachename .= '_b' . $bevel; } $cachename .= '.' . mb_strtolower($path['extension']); if (!is_file($cachename) && is_file($src)) { require_once "Image/Transform.php"; $it = Image_Transform::factory('GD'); $it->load($src); if ($width > 0 && $height > 0 && ($it->img_x > $width || $it->img_y > $height)) { if ($width < 0 || $height < 0) { return ""; } if ($it->img_x > $width) { $it->scaleByX($width); } if ($it->new_y > $height) { $it->crop($width, $height, 0, 0); } } elseif ($width > 0 && $it->img_x > $width) { $it->scaleByX($width); } elseif ($height > 0 && $it->img_y > $height) { $it->scaleByY((int) $height); } if (!empty($matches[2])) { if (!is_dir('cache/images/' . $matches[2])) { mkdir('cache/images/' . $matches[2]); } } $it->save($cachename, '', 100); if ($bevel > 0 && $bevel <= 5) { require_once "Image/Tools.php"; $border = Image_Tools::factory('border'); $border->set('image', $cachename); $border->set('style', 'bevel'); $border->set('params', array($bevel, '#ffffff', '#000000')); switch ($it->type) { case 'jpg': case 'jpeg': $border->save($cachename, IMAGETYPE_JPEG); break; case 'gif': $border->save($cachename, IMAGETYPE_GIF); break; case 'png': $border->save($cachename, IMAGETYPE_PNG); break; } } } if (is_file($cachename)) { $image = "<img src=\"/{$cachename}\"{$attr}/>"; } else { $image = "<img src=\"/image.php?src=" . urlencode($src) . "&x={$width}&y={$height}&b={$bevel}\"{$attr}/>"; } } elseif (isset($row)) { $attr = str_replace(" width=\"{$row['width']}\"", "", $attr); $attr = str_replace(" height=\"{$row['height']}\"", "", $attr); $image = "<img src=\"/{$src}\" width=\"{$row['width']}\" height=\"{$row['height']}\"{$attr}/>"; $params['popup'] = false; if (empty($params['data'])) { $params['lightbox'] = false; } } else { $image = "<img src=\"/{$src}\"{$attr}/>"; $params['popup'] = false; if (empty($params['data'])) { $params['lightbox'] = false; } } if (!empty($params['popup']) && !empty($row)) { if ($params['popup'] === true) { $params['popup'] = "Увеличить"; } $caption = !empty($params['alt']) ? $params['alt'] : $row['caption']; $caption = preg_replace("/[^a-zA-Zа-яА-Я0-9 ]+/iu", " ", smarty_modifier_curlang($caption)); if (A_MODE == A_MODE_FRONT && is_file($css = "templates/" . A::$DOMAIN . "/imagewin.css")) { $image = "<a href=\"javascript:open_imgwindow('/{$src}','{$caption}',{$row['width']},{$row['height']},'/{$css}')\" title=\"{$params['popup']}\">{$image}</a>"; } else { $image = "<a href=\"javascript:open_imgwindow('/{$src}','{$caption}',{$row['width']},{$row['height']})\" title=\"{$params['popup']}\">{$image}</a>"; } } elseif (!empty($params['lightbox']) && !empty($row)) { $caption = !empty($params['alt']) ? $params['alt'] : $row['caption']; $caption = smarty_modifier_curlang($caption); $group = !empty($params['group']) ? "[{$params['group']}]" : "[default]"; $image = "<a href=\"/{$src}\" rel=\"lightbox{$group}\" title=\"{$caption}\">{$image}</a>"; if (!empty($params['data'])) { while ($row = array_shift($params['data'])) { $row['caption'] = smarty_modifier_curlang($row['caption']); $image .= "<a href=\"/{$row['path']}\" rel=\"lightbox{$group}\" title=\"{$row['caption']}\" style=\"display:none\"></a>"; } } } return $image; }
/** * Draw image with logo result to resource. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access public */ function render() { $W = imagesx($this->_source); $H = imagesy($this->_source); $MW = imagesx($this->_mark); $MH = imagesy($this->_mark); // resize the logo image if ($this->options['width'] == 0 && $this->options['height'] == 0) { $this->options['width'] = $MW; $this->options['height'] = $MH; } else { if ($this->options['width'] == 0) { $this->options['width'] = ceil($this->options['height'] * $MW / $MH); } else { if ($this->options['height'] == 0) { $this->options['height'] = ceil($this->options['width'] * $MH / $MW); } } } // calculates the x position switch ($this->options['horipos']) { case IMAGE_TOOLS_WATERMARK_POSITION_LEFT: $posx = $this->options['marginx']; break; case IMAGE_TOOLS_WATERMARK_POSITION_CENTER: $posx = round(($W - $this->options['width']) / 2); break; case IMAGE_TOOLS_WATERMARK_POSITION_RIGHT: default: $posx = $W - $this->options['width'] - $this->options['marginx']; break; } // calculates the y position switch ($this->options['vertpos']) { case IMAGE_TOOLS_WATERMARK_POSITION_TOP: $posy = $this->options['marginy']; break; case IMAGE_TOOLS_WATERMARK_POSITION_MIDDLE: $posy = round(($H - $this->options['height']) / 2); break; case IMAGE_TOOLS_WATERMARK_POSITION_BOTTOM: default: $posy = $H - $this->options['height'] - $this->options['marginy']; break; } settype($posx, 'integer'); settype($posy, 'integer'); // Create the target image imagealphablending($this->_mark, false); // resize the mark image if ($MH != $this->options['height'] && $MW != $this->options['width']) { if (function_exists('imagecreatetruecolor')) { $mark = imagecreatetruecolor($this->options['width'], $this->options['height']); } else { $mark = imagecreate($this->options['width'], $this->options['height']); } imagealphablending($mark, false); if (function_exists('imagecoypresampled')) { $result = imagecopyresampled($mark, $this->_mark, 0, 0, 0, 0, $this->options['width'], $this->options['height'], $MW, $MH); } else { $result = imagecopyresampled($mark, $this->_mark, 0, 0, 0, 0, $this->options['width'], $this->options['height'], $MW, $MH); } $this->_mark = $mark; } if ($this->options['blend'] != 'none') { $blend = Image_Tools::factory('blend'); $blend->set('image1', $this->_source); $blend->set('image2', $this->_mark); $blend->set('x', $posx); $blend->set('y', $posy); $blend->set('mode', $this->options['blend']); // applies the blending mode. $this->_source = $blend->getResultImage(); } else { $result = imagecopy($this->_source, $this->_mark, $posx, $posy, 0, 0, $MW, $MH); if (!$result) { return PEAR::raiseError('Cannot copy logo image'); } } $this->resultImage = $this->_source; unset($this->_mark); return true; }