protected function getOverlay($r, $g, $b) { extract($this->driver->getTargetSize()); $image = $this->driver->getResource(); $overlay = imagecreatetruecolor($width, $height); imagealphablending($image, true); imagelayereffect($image, IMG_EFFECT_OVERLAY); imagefilledrectangle($overlay, 0, 0, $width, $height, imagecolorallocatealpha($overlay, $r, $g, $b, 0)); imagecopy($image, $overlay, 0, 0, 0, 0, imagesx($overlay), imagesy($overlay)); }
function ct_colorize_pics($sourcePath, $destPath, $r, $g, $b) { if (@file_exists($sourcePath) && @is_readable($sourcePath) && @is_dir($sourcePath) && ($handle = @opendir($sourcePath))) { while (false !== ($file = @readdir($handle))) { $ext = strtolower(JFile::getExt($sourcePath . $file)); if ($file != "." && $file != ".." && ($ext == 'png' || $ext == 'jpg' || $ext == 'jpeg')) { if ($ext == 'png') { $im = imagecreatefrompng($sourcePath . $file); } else { $im = imagecreatefromjpeg($sourcePath . $file); } // prevent CONEXT updaters from wondering why the background images won't load anymore if (JFactory::getApplication()->getTemplate() == 'CONEXT' && stripos($sourcePath, 'bg_images_source') !== false) { // keep alphablending default } else { // turn off alphablending for images that are not explicetly marked to use in the filename if (stripos($file, '_alphablending') === false) { imagealphablending($im, false); } } imagefilter($im, IMG_FILTER_COLORIZE, intval($r), intval($g), intval($b)); imagesavealpha($im, true); if (stripos($file, '_multiply') !== false) { if ($ext == 'png') { $im2 = imagecreatefrompng($sourcePath . $file); } else { $im2 = imagecreatefromjpeg($sourcePath . $file); } imagelayereffect($im2, IMG_EFFECT_OVERLAY); $w = imagesx($im); $h = imagesy($im); imagecopy($im2, $im, 0, 0, 0, 0, $w, $h); imagesavealpha($im2, true); ob_start(); imagepng($im2); $c = ob_get_contents(); ob_end_clean(); JFile::write($destPath . $file, $c); imagedestroy($im); imagedestroy($im2); } else { ob_start(); imagepng($im); $c = ob_get_contents(); ob_end_clean(); JFile::write($destPath . $file, $c); imagedestroy($im); } } } } }
function CaptchaImages($code, $width = 145, $height = 35) { /* select the type of font, must be used in directoy in which script is being called into */ $this->font = dirname(__FILE__) . '/CALIBRI.TTF'; $font_size = $height * 0.6; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $bgR = mt_rand(0, 255); $bgG = mt_rand(0, 255); $bgB = mt_rand(0, 255); $background_color = imagecolorallocate($image, $bgR, $bgG, $bgB); $noise_color = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB)); $text_color = imagecolorallocate($image, abs(255 - $bgR), abs(255 - $bgG), abs(255 - $bgB)); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* set random colors */ $w = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB)); $r = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB)); /* Draw a dashed line, 5 red pixels, 5 white pixels */ $style = array($r, $r, $r, $r, $r, $w, $w, $w, $w, $w); imagesetstyle($image, $style); imageline($image, 0, 0, $width, $height, IMG_COLOR_STYLED); imageline($image, $width, 0, 0, $height, IMG_COLOR_STYLED); /* create random polygon points */ $values = array(mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width)); /* create Random Colors then set it to $clr */ $r = abs(100 - mt_rand(0, 255)); $g = abs(100 - mt_rand(0, 255)); $b = abs(100 - mt_rand(0, 255)); $clr = imagecolorallocate($image, $r, $g, $b); /* create filled polygon with random points */ imagefilledpolygon($image, $values, 6, $clr); $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function'); /* pretty it */ imageantialias($image, 100); imagealphablending($image, 1); imagelayereffect($image, IMG_EFFECT_OVERLAY); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); }
public function _blend($opacity = 1, $fill = 1, $options = array()) { // OVERLAY MODE { $destX = ($this->base->getWidth() - $this->top->getWidth()) / 2; $destY = ($this->base->getHeight() - $this->top->getHeight()) / 2; // This line causes all GD operations to use the overlay algorithm // when blending pixels together. $baseImg = $this->base->getImage(); imagelayereffect($baseImg, IMG_EFFECT_OVERLAY); // Blend the top image onto the base image. imagecopy($baseImg, $this->top->getImage(), $destX, $destY, 0, 0, $this->base->getWidth(), $this->base->getHeight()); // } OVERLAY return $baseImg; }
function create_image() { global $trips, $scale, $offsetX, $offsetY, $alpha, $name; // create image from map_bg.jpg, which was made in TileMill $im = imagecreatefromjpeg("map_bg.jpg") or die("Cannot Initialize new GD image stream"); imagelayereffect($im, IMG_EFFECT_ALPHABLEND); // lines are mostly transparent and we want to blend those alphas $slow = imagecolorallocatealpha($im, 170, 0, 0, $alpha); // red $med = imagecolorallocatealpha($im, 255, 244, 50, $alpha); // yellow $fast = imagecolorallocatealpha($im, 0, 240, 128, $alpha); // green foreach ($trips as $vehicle) { for ($i = 1; $i < count($vehicle); $i++) { $val = floatval($vehicle[$i][2]); // speed if ($val < 10) { $color = $slow; } else { if ($val < 25) { $color = $med; } else { $color = $fast; } } // $vehicles[$i][0] is latitude, $vehicles[$i][1] is longitude imageline($im, $vehicle[$i - 1][1] * $scale + $offsetX, -(projectLat($vehicle[$i - 1][0]) * $scale - $offsetY), $vehicle[$i][1] * $scale + $offsetX, -(projectLat($vehicle[$i][0]) * $scale - $offsetY), $color); } } // titles, etc. for the Bostonography maps $white = imagecolorallocate($im, 255, 255, 255); imagettftext($im, 50, 0, 50, 100, $white, "pnbold.otf", "MBTA Bus Speeds"); imagettftext($im, 20, 0, 50, 150, $white, "pnreg.otf", "The speed of buses on " . date("l, F j, Y") . ","); imagettftext($im, 20, 0, 50, 190, $white, "pnreg.otf", "based on 24 hour of real-time location data."); imagettftext($im, 20, 0, 50, 250, imagecolorallocate($im, 170, 0, 0), "pnbold.otf", "Red:"); imagettftext($im, 20, 0, 50, 290, imagecolorallocate($im, 255, 244, 50), "pnbold.otf", "Yellow:"); imagettftext($im, 20, 0, 50, 330, imagecolorallocate($im, 0, 240, 128), "pnbold.otf", "Green:"); imagettftext($im, 20, 0, 150, 250, $white, "pnreg.otf", "< 10 mph"); imagettftext($im, 20, 0, 150, 290, $white, "pnreg.otf", "10 to 25 mph"); imagettftext($im, 20, 0, 150, 330, $white, "pnreg.otf", "> 25 mph"); imagettftext($im, 10, 0, 50, 380, $white, "pnreg.otf", "Bostonography.com | Street map data copyright OpenStreetMap.org | MBTA bus data via NextBus"); // Save image twice imagejpeg($im, "archive/yesterday.jpg"); imagejpeg($im, $name); // To just output the image instead, comment out the above two lines and use these two //header('Content-Type: image/jpeg'); //imagejpeg($im); imagedestroy($im); }
public function overlay_original($layerPath, $posX = 0, $posY = 0, $layerX = 0, $layerY = 0, $layerWidth = 0, $layerHeight = 0) { // Load the new layer $draw = new Image($layerPath); if (!isset($draw->resource)) { return; } imagelayereffect($this->resource, IMG_EFFECT_OVERLAY); // Check default sizes if ($layerWidth == 0) { $layerWidth = $draw->width; } if ($layerHeight == 0) { $layerHeight = $draw->height; } // Copy the layer to the image imagecopy($this->resource, $draw->resource, $posX, $posY, $layerX, $layerY, $layerWidth, $layerHeight); }
/** * @param string $file * @param int $offsetX * @param int $offsetY * @param float $opacity * * @return static * @throws \ManaPHP\Image\Adapter\Exception */ public function watermark($file, $offsetX = 0, $offsetY = 0, $opacity = 1.0) { $file = $this->alias->resolve($file); $maskImageInfo = getimagesize($file); $maskWidth = $maskImageInfo[0]; /** @noinspection MultiAssignmentUsageInspection */ $maskHeight = $maskImageInfo[1]; /** @noinspection MultiAssignmentUsageInspection */ $maskType = $maskImageInfo[2]; if ($maskType === IMAGETYPE_GIF) { $maskImage = imagecreatefromgif($file); } elseif ($maskType === IMAGETYPE_JPEG) { $maskImage = imagecreatefromjpeg($file); } elseif ($maskType === IMAGETYPE_PNG) { $maskImage = imagecreatefrompng($file); } else { throw new GdException('Installed GD does not support such images'); } imagesavealpha($maskImage, true); $image = imagecreatetruecolor($this->_width, $this->_height); imagealphablending($image, false); imagesavealpha($image, true); if ($maskType !== IMAGETYPE_PNG) { $filedColor = imagecolorallocatealpha($image, 127, 127, 127, (1 - $opacity) * 127); } else { $filedColor = imagecolorallocate($image, 127, 127, 127); } imagelayereffect($maskImage, IMG_EFFECT_OVERLAY); imagefilledrectangle($maskImage, 0, 0, $maskWidth, $maskHeight, $filedColor); imagealphablending($this->_image, true); imagecopy($this->_image, $maskImage, $offsetX, $offsetY, 0, 0, $maskWidth, $maskHeight); return $this; }
<?php $image = imagecreatetruecolor(180, 30); $layer = imagelayereffect($image, IMG_EFFECT_REPLACE); if ($layer) { ob_start(); imagepng($image, null, 9); $img = ob_get_contents(); ob_end_clean(); } echo md5(base64_encode($img));
static function set(&$image, $value, $method) { if ($method == 'border') { //画线粗细 return imagesetthickness($image, (int) $value); } if ($method == 'style') { //画线风格 return imagesetstyle($image, (array) $value); } if ($method == 'brush') { //画笔图像 return imagesetbrush($image, $value); } if ($method == 'pattern') { //填充的贴图 图案 return imagesettile($image, $value); } if ($method == 'alias') { //抗锯齿 return imageantialias($image, (bool) $value); } if ($method == 'alpha') { //alpha混色标志 return imagelayereffect($image, (int) $value); } if ($method == 'transparent') { //透明色 return imagecolortransparent($image, (int) $value); } if ($method == 'mix') { //混色模式 return imagealphablending($image, (bool) $value); } }
protected function _do_watermark(Image $watermark, $offset_x, $offset_y, $opacity) { if (!Image_GD::$_bundled) { throw new Kohana_Exception('This method requires :function, which is only available in the bundled version of GD', array(':function' => 'imagelayereffect')); } // Loads image if not yet loaded $this->_load_image(); // Create the watermark image resource $overlay = imagecreatefromstring($watermark->render()); // Get the width and height of the watermark $width = imagesx($overlay); $height = imagesy($overlay); if ($opacity < 100) { // Convert an opacity range of 0-100 to 127-0 $opacity = round(abs($opacity * 127 / 100 - 127)); // Allocate transparent white $color = imagecolorallocatealpha($overlay, 255, 255, 255, $opacity); // The transparent image will overlay the watermark imagelayereffect($overlay, IMG_EFFECT_OVERLAY); // Fill the background with transparent white imagefilledrectangle($overlay, 0, 0, $width, $height, $color); } // Alpha blending must be enabled on the background! imagealphablending($this->_image, TRUE); if (imagecopy($this->_image, $overlay, $offset_x, $offset_y, 0, 0, $width, $height)) { // Destroy the overlay image imagedestroy($overlay); } }
/** * {@inheritdoc} */ protected function doApply(CanvasInterface $canvas) { $box = is_null($this->getBox()) ? new Box($canvas->getDimension()) : $this->getBox(); $compine = new \Jaguar\Canvas($canvas->getDimension()); $compine->paste($canvas); $compine->paste($this->getOverlay(), null, $box); imagelayereffect($canvas->getHandler(), IMG_EFFECT_OVERLAY); imagecopymerge($canvas->getHandler(), $compine->getHandler(), 0, 0, 0, 0, $canvas->getWidth(), $canvas->getHeight(), $this->getAmount()); $canvas->alphaBlending(true); $compine->destroy(); }
// add all the icons to the sprite image for ($i = 0; $i < $cnt; $i++) { $base = $i * 90; $IN = imagecreatefrompng($input[$i]); imagesavealpha($IN, true); imagecolorscale($IN, $GAMMA); imagecopy($DST, $IN, 0, $base, 0, 0, 30, 30); imagedestroy($IN); $IN = imagecreatefrompng($input[$i]); imagesavealpha($IN, true); imagecolorscale($IN, $GAMMA); imagecopy($DST, $IN, 0, $base + 45, 0, 0, 30, 30); imagedestroy($IN); imagelayereffect($DST, IMG_EFFECT_OVERLAY); imagefilledrectangle($DST, 0, $base + 45, 30, $base + 45 + 30, $C_active); imagelayereffect($DST, IMG_EFFECT_NORMAL); } // output sprite imagepng($DST, 'pagetools-sprite.png'); imagedestroy($DST); // optimize if possible if (is_executable($OPTIPNG)) { system("{$OPTIPNG} -o5 'pagetools-sprite.png'"); } /** * Convert a hex color code to an rgb array */ function hex2rgb($hex) { // strip hash $hex = str_replace('#', '', $hex);
public function layerEffect(string $effect = 'normal') : InternalGD { imagelayereffect($this->canvas, Converter::toConstant($effect, 'IMG_EFFECT_')); return $this; }
/** * {@inheritdoc} */ public function watermark($file, $position = Image::WATERMARK_TOP_LEFT, $opacity = 100) { $watermark = $this->createImageResource($file, $this->getImageInfo($file)); $watermarkWidth = imagesx($watermark); $watermarkHeight = imagesy($watermark); if ($opacity < 100) { // Convert alpha to 0-127 $alpha = min(round(abs($opacity * 127 / 100 - 127)), 127); $transparent = imagecolorallocatealpha($watermark, 0, 0, 0, $alpha); imagelayereffect($watermark, IMG_EFFECT_OVERLAY); imagefilledrectangle($watermark, 0, 0, $watermarkWidth, $watermarkHeight, $transparent); } // Position the watermark. switch ($position) { case Image::WATERMARK_TOP_RIGHT: $x = imagesx($this->image) - $watermarkWidth; $y = 0; break; case Image::WATERMARK_BOTTOM_LEFT: $x = 0; $y = imagesy($this->image) - $watermarkHeight; break; case Image::WATERMARK_BOTTOM_RIGHT: $x = imagesx($this->image) - $watermarkWidth; $y = imagesy($this->image) - $watermarkHeight; break; case Image::WATERMARK_CENTER: $x = imagesx($this->image) / 2 - $watermarkWidth / 2; $y = imagesy($this->image) / 2 - $watermarkHeight / 2; break; default: $x = 0; $y = 0; } imagealphablending($this->image, true); imagecopy($this->image, $watermark, $x, $y, 0, 0, $watermarkWidth, $watermarkHeight); imagedestroy($watermark); }
static function set(&$image, $value, $style = 'mix') { switch ($style) { case 'border': //画线粗细 return imagesetthickness($image, (int) $value); case 'style': //画线风格 return imagesetstyle($image, (array) $value); case 'brush': //画笔图像 return imagesetbrush($image, $value); case 'pattern': //填充的贴图 图案 return imagesettile($image, $value); case 'alias': //抗锯齿 return imageantialias($image, (bool) $value); case 'alpha': //alpha混色标志 return imagelayereffect($image, (int) $value); case 'transparent': //透明色 return imagecolortransparent($image, (int) $value); case 'mix': //混色模式 //混色模式 default: return imagealphablending($image, (bool) $value); } }
public function multiplyRun($image1, $image2, $destFile, $opacity = 50) { $baseImageType = pathinfo($image1, PATHINFO_EXTENSION); if ($baseImageType == 'png') { $baseImage = imagecreatefrompng($image1); } else { if ($baseImageType == 'gif') { $baseImage = imagecreatefromgif($image1); } else { $baseImage = imagecreatefromjpeg($image1); } } $baseIsTrueColor = imageistruecolor($baseImage); $topImageType = pathinfo($image2, PATHINFO_EXTENSION); if ($topImageType == 'png') { $topImage = imagecreatefrompng($image2); } else { if ($topImageType == 'gif') { $topImage = imagecreatefromgif($image2); } else { $topImage = imagecreatefromjpeg($image2); } } $topIsTrueColor = imageistruecolor($topImage); $baseWidth = imagesx($baseImage); $baseHeight = imagesy($baseImage); $topWidth = imagesx($topImage); $topHeight = imagesy($topImage); $destX = ($baseWidth - $topWidth) / 2; $destY = ($baseHeight - $topHeight) / 2; if (function_exists('imagelayereffect')) { switch ($this->alphaBlendMode) { default: case 'normal': imagelayereffect($topImage, IMG_EFFECT_NORMAL); break; case 'replace': imagelayereffect($topImage, IMG_EFFECT_REPLACE); break; case 'overlay': imagelayereffect($topImage, IMG_EFFECT_OVERLAY); break; } } if ($this->effects != false) { // negate,grayscale,brightness,contrast,colorize,edges,emboss,gaussBlur,selectiveBlur,meanRemoval,smooth,pixelate foreach ($this->effects as $effect) { switch ($effect) { case 'gammaCorrect': if (function_exists('imagegammacorrect') && isset($this->gammaCorrect) && !empty($this->gammaCorrect)) { imagegammacorrect($topImage, $this->gammaInput, $this->gammaOutput); } break; case 'negate': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_NEGATE); } break; case 'grayscale': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_GRAYSCALE); } break; case 'brightness': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_BRIGHTNESS, $this->effectBrightnessLevel); } break; case 'contrast': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_CONTRAST, $this->effectContrastLevel); } break; case 'colorize': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_COLORIZE, $this->colorize['red'], $this->colorize['green'], $this->colorize['blue'], $this->colorize['alpha']); } break; case 'edges': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_EDGEDETECT); } break; case 'emboss': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_EMBOSS); } break; case 'gaussBlur': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_GAUSSIAN_BLUR); } break; case 'selectiveBlur': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_SELECTIVE_BLUR); } break; case 'meanRemoval': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_MEAN_REMOVAL); } break; case 'smooth': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_SMOOTH, $this->effectSmoothLevel); } break; case 'pixelate': if (function_exists('imagefilter')) { imagefilter($topImage, IMG_FILTER_PIXELATE, $this->effectPixelSize, $this->effectAdvancedPixelation); } break; } } } if ($this->blendMode != false) { $baseImage = $this->blend($baseImage, $topImage, $this->blendMode); } else { imagecopymerge($baseImage, $topImage, $destX, $destY, 0, 0, $topWidth, $topHeight, $opacity); } imagepng($baseImage, $destFile); imagedestroy($baseImage); imagedestroy($topImage); return $destFile; }
<?php $layer = imagelayereffect('invalid_resource', IMG_EFFECT_REPLACE);
<?php $image = imagecreatetruecolor(180, 30); $layer = imagelayereffect($image, 'IMG_EFFECT_REPLACE');
private function createEmblem($showlevel = TRUE, $width = 215) { if (!$this->emblemAdd) { $imgfile = dirname(__FILE__) . "/cache/" . $this->region . '_' . $this->realm . '_' . $this->name . ".png"; } else { $imgfile = dirname(__FILE__) . "/cache/" . $this->region . '_' . $this->realm . '_' . $this->name . '_' . $this->emblemAdd . ".png"; } #$imgfile = dirname(__FILE__)."/cache/".$this->region.$this->realm.$this->name.".png"; #print $imgfile; if (file_exists($imgfile) and $width == imagesx(imagecreatefrompng($imgfile)) and filemtime($imgfile) + 86000 > time()) { $finalimg = imagecreatefrompng($imgfile); imagesavealpha($finalimg, true); imagealphablending($finalimg, true); } else { if ($width > 1 and $width < 215) { $height = $width / 215 * 230; $finalimg = imagecreatetruecolor($width, $height); $trans_colour = imagecolorallocatealpha($finalimg, 0, 0, 0, 127); imagefill($finalimg, 0, 0, $trans_colour); imagesavealpha($finalimg, true); imagealphablending($finalimg, true); } if ($this->guildData['side'] == 0) { $ring = 'alliance'; } else { $ring = 'horde'; } $imgOut = imagecreatetruecolor(215, 230); $emblemURL = dirname(__FILE__) . "/img/emblems/emblem_" . sprintf("%02s", $this->guildData['emblem']['icon']) . ".png"; $borderURL = dirname(__FILE__) . "/img/borders/border_" . sprintf("%02s", $this->guildData['emblem']['border']) . ".png"; $ringURL = dirname(__FILE__) . "/img/static/ring-" . $ring . ".png"; $shadowURL = dirname(__FILE__) . "/img/static/shadow_00.png"; $bgURL = dirname(__FILE__) . "/img/static/bg_00.png"; $overlayURL = dirname(__FILE__) . "/img/static/overlay_00.png"; $hooksURL = dirname(__FILE__) . "/img/static/hooks.png"; $levelURL = dirname(__FILE__) . "/img/static/"; imagesavealpha($imgOut, true); imagealphablending($imgOut, true); $trans_colour = imagecolorallocatealpha($imgOut, 0, 0, 0, 127); imagefill($imgOut, 0, 0, $trans_colour); $ring = imagecreatefrompng($ringURL); $ring_size = getimagesize($ringURL); $emblem = imagecreatefrompng($emblemURL); $emblem_size = getimagesize($emblemURL); imagelayereffect($emblem, IMG_EFFECT_OVERLAY); $emblemcolor = preg_replace('/^ff/i', '', $this->guildData['emblem']['iconColor']); $color_r = hexdec(substr($emblemcolor, 0, 2)); $color_g = hexdec(substr($emblemcolor, 2, 2)); $color_b = hexdec(substr($emblemcolor, 4, 2)); imagefilledrectangle($emblem, 0, 0, $emblem_size[0], $emblem_size[1], imagecolorallocatealpha($emblem, $color_r, $color_g, $color_b, 0)); $border = imagecreatefrompng($borderURL); $border_size = getimagesize($borderURL); imagelayereffect($border, IMG_EFFECT_OVERLAY); $bordercolor = preg_replace('/^ff/i', '', $this->guildData['emblem']['borderColor']); $color_r = hexdec(substr($bordercolor, 0, 2)); $color_g = hexdec(substr($bordercolor, 2, 2)); $color_b = hexdec(substr($bordercolor, 4, 2)); imagefilledrectangle($border, 0, 0, $border_size[0] + 100, $border_size[0] + 100, imagecolorallocatealpha($border, $color_r, $color_g, $color_b, 0)); $shadow = imagecreatefrompng($shadowURL); $bg = imagecreatefrompng($bgURL); $bg_size = getimagesize($bgURL); imagelayereffect($bg, IMG_EFFECT_OVERLAY); $bgcolor = preg_replace('/^ff/i', '', $this->guildData['emblem']['backgroundColor']); $color_r = hexdec(substr($bgcolor, 0, 2)); $color_g = hexdec(substr($bgcolor, 2, 2)); $color_b = hexdec(substr($bgcolor, 4, 2)); imagefilledrectangle($bg, 0, 0, $bg_size[0] + 100, $bg_size[0] + 100, imagecolorallocatealpha($bg, $color_r, $color_g, $color_b, 0)); $overlay = imagecreatefrompng($overlayURL); $hooks = imagecreatefrompng($hooksURL); $x = 20; $y = 23; if (!$this->emblemHideRing) { imagecopy($imgOut, $ring, 0, 0, 0, 0, $ring_size[0], $ring_size[1]); } $size = getimagesize($shadowURL); imagecopy($imgOut, $shadow, $x, $y, 0, 0, $size[0], $size[1]); imagecopy($imgOut, $bg, $x, $y, 0, 0, $bg_size[0], $bg_size[1]); imagecopy($imgOut, $emblem, $x + 17, $y + 30, 0, 0, $emblem_size[0], $emblem_size[1]); imagecopy($imgOut, $border, $x + 13, $y + 15, 0, 0, $border_size[0], $border_size[1]); $size = getimagesize($overlayURL); imagecopy($imgOut, $overlay, $x, $y + 2, 0, 0, $size[0], $size[1]); $size = getimagesize($hooksURL); imagecopy($imgOut, $hooks, $x - 2, $y, 0, 0, $size[0], $size[1]); if ($showlevel) { $level = $this->guildData['level']; if ($level < 10) { $levelIMG = imagecreatefrompng($levelURL . $level . ".png"); } else { $digit[1] = substr($level, 0, 1); $digit[2] = substr($level, 1, 1); $digit1 = imagecreatefrompng($levelURL . $digit[1] . ".png"); $digit2 = imagecreatefrompng($levelURL . $digit[2] . ".png"); $digitwidth = imagesx($digit1); $digitheight = imagesy($digit1); $levelIMG = imagecreatetruecolor($digitwidth * 2, $digitheight); $trans_colour = imagecolorallocatealpha($levelIMG, 0, 0, 0, 127); imagefill($levelIMG, 0, 0, $trans_colour); imagesavealpha($levelIMG, true); imagealphablending($levelIMG, true); // Last image added first because of the shadow need to be behind first digit imagecopy($levelIMG, $digit2, $digitwidth - 12, 0, 0, 0, $digitwidth, $digitheight); imagecopy($levelIMG, $digit1, 12, 0, 0, 0, $digitwidth, $digitheight); } $size[0] = imagesx($levelIMG); $size[1] = imagesy($levelIMG); $levelemblem = imagecreatefrompng($ringURL); imagesavealpha($levelemblem, true); imagealphablending($levelemblem, true); imagecopy($levelemblem, $levelIMG, 215 / 2 - $size[0] / 2, 215 / 2 - $size[1] / 2, 0, 0, $size[0], $size[1]); imagecopyresampled($imgOut, $levelemblem, 143, 150, 0, 0, 215 / 3, 215 / 3, 215, 215); } if ($width > 1 and $width < 215) { imagecopyresampled($finalimg, $imgOut, 0, 0, 0, 0, $width, $height, 215, 230); } else { $finalimg = $imgOut; } imagepng($finalimg, $imgfile); } return $finalimg; }
// Rotate and flip it (strip flip method) for ($y = 0; $y < $new_height; $y++) { imagecopy($buffer, $output, 0, $y, 0, $new_height - $y - 1, $width, 1); } $output = $buffer; /* ---------------------------------------------------------------- Apply the fade effect ---------------------------------------------------------------- */ // This is quite simple really. There are 127 available levels of alpha, so we just // step-through the reflected image, drawing a box over the top, with a set alpha level. // The end result? A cool fade. // There are a maximum of 127 alpha fade steps we can use, so work out the alpha step rate $alpha_length = abs($alpha_start - $alpha_end); imagelayereffect($output, IMG_EFFECT_OVERLAY); for ($y = 0; $y <= $new_height; $y++) { // Get % of reflection height $pct = $y / $new_height; // Get % of alpha if ($alpha_start > $alpha_end) { $alpha = (int) ($alpha_start - $pct * $alpha_length); } else { $alpha = (int) ($alpha_start + $pct * $alpha_length); } // Rejig it because of the way in which the image effect overlay works $final_alpha = 127 - $alpha; //imagefilledrectangle($output, 0, $y, $width, $y, imagecolorallocatealpha($output, 127, 127, 127, $final_alpha)); imagefilledrectangle($output, 0, $y, $width, $y, imagecolorallocatealpha($output, $red, $green, $blue, $final_alpha)); } /*
static function set($res, $method, $mix) { if ($method == 1) { //画线粗细 return imagesetthickness($res, (int) $mix); } if ($method == 2) { //画线风格 return imagesetstyle($res, (array) $mix); } if ($method == 3) { //画笔图像 return imagesetbrush($res, $mix); } if ($method == 4) { //填充的贴图 return imagesettile($res, $mix); } if ($method == 5) { //抗锯齿 return imageantialias($res, (bool) $mix); } if ($method == 6) { //alpha混色标志 return imagelayereffect($res, (int) $mix); } if ($method == 7) { //透明色 return imagecolortransparent($res, (int) $mix); } if ($method == 8) { //混色模式 return imagealphablending($res, (bool) $mix); } return 'method error'; }
function makePngIphoneIcon($InFile, $OutFile, $Width = 100, $Height = 100) { $dim = getimagesize($InFile); $haut = $dim[1]; $larg = $dim[0]; if ($haut != 100 && $larg != 100) { pngReductionFixe($InFile, $OutFile, 100, 100, true); $InFile = $OutFile; } // Load the image where the logo will be embeded into $image = imagecreatefrompng($InFile); // Load the overlay image $overlayImage = imagecreatefrompng(dirname(__FILE__) . "/../img/mask_icon_iphone.png"); //imagealphablending($overlayImage, true); // Get dimensions $imageWidth = imagesx($image); $imageHeight = imagesy($image); $overlayImageWidth = imagesx($overlayImage); $overlayImageHeight = imagesy($overlayImage); imagelayereffect($overlayImage, IMG_EFFECT_OVERLAY); // Paste the logo imagecopy($overlayImage, $image, ($overlayImageWidth - $imageWidth) / 2, ($overlayImageHeight - $imageHeight) / 2, 0, 0, $imageWidth, $imageHeight); if ($Width != 100 && $Height != 100) { $diffHeight = 0; $diffWidth = 0; if ($imageWidth > $imageHeight) { $reduire = $Width / $imageWidth; $larg2 = $Width; $haut2 = round($imageHeight * $reduire); $diffHeight = ($Height - $haut2) / 2; } else { $reduire = $Height / $imageHeight; $larg2 = round($imageWidth * $reduire); $haut2 = $Height; $diffWidth = ($Width - $larg2) / 2; } ImageCopyreSampled($overlayImage, $overlayImage, $diffWidth, $diffHeight, 0, 0, $larg2, $haut2, $imageWidth, $imageHeight); } if (file_exists($OutFile)) { unlink($OutFile); } touch($OutFile); imagepng($overlayImage, $OutFile); // Release memory imageDestroy($image); imageDestroy($overlayImage); makePngColorTransparentBackground($OutFile, $OutFile, array('red' => 255, 'green' => 0, 'blue' => 255)); }
<?php $resource = tmpfile(); $layer = imagelayereffect($resource, IMG_EFFECT_REPLACE);
/** * function to create a Wow Guild emblem, adapted for phpBB from http://us.battle.net/wow/en/forum/topic/3082248497#8 * * @author Thomas Andersen <*****@*****.**> * @copyright Copyright (c) 2011, Thomas Andersen, http://sourceforge.net/projects/wowarmoryapi * @param boolean $showlevel * @param int $width * @return resource */ private function createEmblem($showlevel = TRUE, $width = 115) { global $phpbb_root_path; //location to create the file $imgfile = $phpbb_root_path . "images/bbdkp/guildemblem/" . $this->region . '_' . $this->realm . '_' . $this->mb_str_replace(' ', '_', $this->name) . ".png"; $outputpath = "images/bbdkp/guildemblem/" . $this->region . '_' . $this->realm . '_' . $this->mb_str_replace(' ', '_', $this->name) . ".png"; if (file_exists($imgfile) and $width == imagesx(imagecreatefrompng($imgfile)) and filemtime($imgfile) + 86000 > time()) { $finalimg = imagecreatefrompng($imgfile); imagesavealpha($finalimg, true); imagealphablending($finalimg, true); } else { if ($width > 1 and $width < 215) { $height = $width / 215 * 230; $finalimg = imagecreatetruecolor($width, $height); $trans_colour = imagecolorallocatealpha($finalimg, 0, 0, 0, 127); imagefill($finalimg, 0, 0, $trans_colour); imagesavealpha($finalimg, true); imagealphablending($finalimg, true); } if ($this->side == 0) { $ring = 'alliance'; } else { $ring = 'horde'; } $imgOut = imagecreatetruecolor(215, 230); $emblemURL = $phpbb_root_path . "images/bbdkp/wowapi/emblems/emblem_" . sprintf("%02s", $this->emblem['icon']) . ".png"; $borderURL = $phpbb_root_path . "images/bbdkp/wowapi/borders/border_" . sprintf("%02s", $this->emblem['border']) . ".png"; $ringURL = $phpbb_root_path . "images/bbdkp/wowapi/static/ring-" . $ring . ".png"; $shadowURL = $phpbb_root_path . "images/bbdkp/wowapi/static/shadow_00.png"; $bgURL = $phpbb_root_path . "images/bbdkp/wowapi/static/bg_00.png"; $overlayURL = $phpbb_root_path . "images/bbdkp/wowapi//static/overlay_00.png"; $hooksURL = $phpbb_root_path . "images/bbdkp/wowapi/static/hooks.png"; $levelURL = $phpbb_root_path . "images/bbdkp/wowapi/static/"; imagesavealpha($imgOut, true); imagealphablending($imgOut, true); $trans_colour = imagecolorallocatealpha($imgOut, 0, 0, 0, 127); imagefill($imgOut, 0, 0, $trans_colour); $ring = imagecreatefrompng($ringURL); $ring_size = getimagesize($ringURL); $emblem = imagecreatefrompng($emblemURL); $emblem_size = getimagesize($emblemURL); imagelayereffect($emblem, IMG_EFFECT_OVERLAY); $emblemcolor = preg_replace('/^ff/i', '', $this->emblem['iconColor']); $color_r = hexdec(substr($emblemcolor, 0, 2)); $color_g = hexdec(substr($emblemcolor, 2, 2)); $color_b = hexdec(substr($emblemcolor, 4, 2)); imagefilledrectangle($emblem, 0, 0, $emblem_size[0], $emblem_size[1], imagecolorallocatealpha($emblem, $color_r, $color_g, $color_b, 0)); $border = imagecreatefrompng($borderURL); $border_size = getimagesize($borderURL); imagelayereffect($border, IMG_EFFECT_OVERLAY); $bordercolor = preg_replace('/^ff/i', '', $this->emblem['borderColor']); $color_r = hexdec(substr($bordercolor, 0, 2)); $color_g = hexdec(substr($bordercolor, 2, 2)); $color_b = hexdec(substr($bordercolor, 4, 2)); imagefilledrectangle($border, 0, 0, $border_size[0] + 100, $border_size[0] + 100, imagecolorallocatealpha($border, $color_r, $color_g, $color_b, 0)); $shadow = imagecreatefrompng($shadowURL); $bg = imagecreatefrompng($bgURL); $bg_size = getimagesize($bgURL); imagelayereffect($bg, IMG_EFFECT_OVERLAY); $bgcolor = preg_replace('/^ff/i', '', $this->emblem['backgroundColor']); $color_r = hexdec(substr($bgcolor, 0, 2)); $color_g = hexdec(substr($bgcolor, 2, 2)); $color_b = hexdec(substr($bgcolor, 4, 2)); imagefilledrectangle($bg, 0, 0, $bg_size[0] + 100, $bg_size[0] + 100, imagecolorallocatealpha($bg, $color_r, $color_g, $color_b, 0)); $overlay = imagecreatefrompng($overlayURL); $hooks = imagecreatefrompng($hooksURL); $x = 20; $y = 23; imagecopy($imgOut, $ring, 0, 0, 0, 0, $ring_size[0], $ring_size[1]); $size = getimagesize($shadowURL); imagecopy($imgOut, $shadow, $x, $y, 0, 0, $size[0], $size[1]); imagecopy($imgOut, $bg, $x, $y, 0, 0, $bg_size[0], $bg_size[1]); imagecopy($imgOut, $emblem, $x + 17, $y + 30, 0, 0, $emblem_size[0], $emblem_size[1]); imagecopy($imgOut, $border, $x + 13, $y + 15, 0, 0, $border_size[0], $border_size[1]); $size = getimagesize($overlayURL); imagecopy($imgOut, $overlay, $x, $y + 2, 0, 0, $size[0], $size[1]); $size = getimagesize($hooksURL); imagecopy($imgOut, $hooks, $x - 2, $y, 0, 0, $size[0], $size[1]); //Blizzard disabled guild levels /* if ($showlevel) { $level = $this->level; if ($level < 10) { $levelIMG = imagecreatefrompng($levelURL.$level.".png"); } else { $digit[1] = substr($level,0,1); $digit[2] = substr($level,1,1); $digit1 = imagecreatefrompng($levelURL.$digit[1].".png"); $digit2 = imagecreatefrompng($levelURL.$digit[2].".png"); $digitwidth = imagesx($digit1); $digitheight = imagesy($digit1); $levelIMG = imagecreatetruecolor($digitwidth*2,$digitheight); $trans_colour = imagecolorallocatealpha($levelIMG, 0, 0, 0, 127); imagefill($levelIMG, 0, 0, $trans_colour); imagesavealpha($levelIMG,true); imagealphablending($levelIMG, true); // Last image added first because of the shadow need to be behind first digit imagecopy($levelIMG,$digit2,$digitwidth-12,0,0,0, $digitwidth, $digitheight); imagecopy($levelIMG,$digit1,12,0,0,0, $digitwidth, $digitheight); } $size[0] = imagesx($levelIMG); $size[1] = imagesy($levelIMG); $levelemblem = imagecreatefrompng($ringURL); imagesavealpha($levelemblem,true); imagealphablending($levelemblem, true); imagecopy($levelemblem,$levelIMG,(215/2)-($size[0]/2),(215/2)-($size[1]/2),0,0,$size[0],$size[1]); imagecopyresampled($imgOut, $levelemblem, 143, 150,0,0, 215/3, 215/3, 215, 215); } */ //endregion if ($width > 1 and $width < 215) { imagecopyresampled($finalimg, $imgOut, 0, 0, 0, 0, $width, $height, 215, 230); } else { $finalimg = $imgOut; } imagepng($finalimg, $imgfile); } return $outputpath; }
/** * Generate guild tabard & save in cache * * @param $emblemdata emblem data array of battle.net api * @param $faction name of the faction * @param $guild name of the guild * @param $imgwidth width of the image * @return bol */ public function guildTabard($emblemdata, $faction, $guild, $imgwidth = 215) { $cached_img = sprintf('image_tabard_%s_w%s.png', strtolower(str_replace(' ', '', $this->clean_name($guild))), $imgwidth); $imgfile_sp = $this->get_CachedData($cached_img, false, true, false, true); if (!($imgfile = $this->get_CachedData($cached_img, false, true))) { if (!function_exists('imagecreatefrompng') || version_compare(PHP_VERSION, "5.3.0", '<')) { return sprintf('games/wow/guild/tabard_%s.png', $faction == 0 ? 'alliance' : 'horde'); } $imgfile = $this->get_CachedData($cached_img, false, true, true); $imgfile_sp = $this->get_CachedData($cached_img, false, true, true, true); // set the URL of the required image parts $img_emblem = $this->_config['apiTabardRenderUrl'] . sprintf('emblem_%02s', $emblemdata['icon']) . '.png'; $img_border = $this->_config['apiTabardRenderUrl'] . "border_" . ($emblemdata['border'] == '-1' ? sprintf("%02s", $emblemdata['border']) : '00') . ".png"; $img_ring = $this->_config['apiTabardRenderUrl'] . sprintf('ring-%s', $faction == 0 ? 'alliance' : 'horde') . '.png'; $img_background = $this->_config['apiTabardRenderUrl'] . 'bg_00.png'; $img_shadow = $this->_config['apiTabardRenderUrl'] . 'shadow_00.png'; $img_overlay = $this->_config['apiTabardRenderUrl'] . 'overlay_00.png'; $img_hooks = $this->_config['apiTabardRenderUrl'] . 'hooks.png'; // set the image size (max width 215px) & generate the guild tabard image $img_resampled = false; if ($imgwidth > 1 && $imgwidth < 215) { $img_resampled = true; $imgheight = $imgwidth / 215 * 230; $img_tabard = imagecreatetruecolor($imgwidth, $imgheight); $tranparency = imagecolorallocatealpha($img_tabard, 0, 0, 0, 127); imagefill($img_tabard, 0, 0, $tranparency); imagesavealpha($img_tabard, true); imagealphablending($img_tabard, true); } // generate the output image $img_genoutput = imagecreatetruecolor(215, 230); imagesavealpha($img_genoutput, true); imagealphablending($img_genoutput, true); $tranparency = imagecolorallocatealpha($img_genoutput, 0, 0, 0, 127); imagefill($img_genoutput, 0, 0, $tranparency); // generate the ring $ring = imagecreatefrompng($img_ring); $ring_size = getimagesize($img_ring); $emblem_image = imagecreatefrompng($img_emblem); $emblem_size = getimagesize($img_emblem); if ($this->checkImageLayerEffect()) { imagelayereffect($emblem_image, IMG_EFFECT_OVERLAY); } $tmp_emblemcolor = preg_replace('/^ff/i', '', $emblemdata['iconColor']); $emblemcolor = array(hexdec(substr($tmp_emblemcolor, 0, 2)), hexdec(substr($tmp_emblemcolor, 2, 2)), hexdec(substr($tmp_emblemcolor, 4, 2))); if ($this->checkImageLayerEffect()) { imagefilledrectangle($emblem_image, 0, 0, $emblem_size[0], $emblem_size[1], imagecolorallocate($emblem_image, $emblemcolor[0], $emblemcolor[1], $emblemcolor[2])); } else { $this->imageColorize($emblem_image, $emblemcolor[0], $emblemcolor[1], $emblemcolor[2]); } // generate the border $border = imagecreatefrompng($img_border); $border_size = getimagesize($img_border); if ($this->checkImageLayerEffect()) { imagelayereffect($border, IMG_EFFECT_OVERLAY); } $tmp_bcolor = preg_replace('/^ff/i', '', $emblemdata['borderColor']); $bordercolor = array(hexdec(substr($tmp_bcolor, 0, 2)), hexdec(substr($tmp_bcolor, 2, 2)), hexdec(substr($tmp_bcolor, 4, 2))); if ($this->checkImageLayerEffect()) { imagefilledrectangle($border, 0, 0, $border_size[0] + 100, $border_size[0] + 100, imagecolorallocate($border, $bordercolor[0], $bordercolor[1], $bordercolor[2])); } else { $this->imageColorize($border, $bordercolor[0], $bordercolor[1], $bordercolor[2]); } // generate the background $shadow = imagecreatefrompng($img_shadow); $bg = imagecreatefrompng($img_background); $bg_size = getimagesize($img_background); if ($this->checkImageLayerEffect()) { imagelayereffect($bg, IMG_EFFECT_OVERLAY); } $tmp_bgcolor = preg_replace('/^ff/i', '', $emblemdata['backgroundColor']); $bgcolor = array(hexdec(substr($tmp_bgcolor, 0, 2)), hexdec(substr($tmp_bgcolor, 2, 2)), hexdec(substr($tmp_bgcolor, 4, 2))); if ($this->checkImageLayerEffect()) { imagefilledrectangle($bg, 0, 0, $bg_size[0] + 100, $bg_size[0] + 100, imagecolorallocate($bg, $bgcolor[0], $bgcolor[1], $bgcolor[2])); } else { $this->imageColorize($bg, $bgcolor[0], $bgcolor[1], $bgcolor[2]); } // put it together... imagecopy($img_genoutput, $ring, 0, 0, 0, 0, $ring_size[0], $ring_size[1]); $size = getimagesize($img_shadow); imagecopy($img_genoutput, $shadow, 20, 23, 0, 0, $size[0], $size[1]); imagecopy($img_genoutput, $bg, 20, 23, 0, 0, $bg_size[0], $bg_size[1]); imagecopy($img_genoutput, $emblem_image, 37, 53, 0, 0, $emblem_size[0], $emblem_size[1]); imagecopy($img_genoutput, $border, 32, 38, 0, 0, $border_size[0], $border_size[1]); $size = getimagesize($img_overlay); imagecopy($img_genoutput, imagecreatefrompng($img_overlay), 20, 25, 0, 0, $size[0], $size[1]); $size = getimagesize($img_hooks); imagecopy($img_genoutput, imagecreatefrompng($img_hooks), 18, 23, 0, 0, $size[0], $size[1]); // check if the image is the same size as the image file parts, if not, resample the image if ($img_resampled) { imagecopyresampled($img_tabard, $img_genoutput, 0, 0, 0, 0, $imgwidth, $imgheight, 215, 230); } else { $img_tabard = $img_genoutput; } $strTmpFolder = is_object($this->pfh) ? $this->pfh->FolderPath('tmp', '') . $cached_img : $imgfile; //Create PNG imagepng($img_tabard, $strTmpFolder); //Move from tmp-Folder to right folder if (is_object($this->pfh)) { $this->pfh->FileMove($strTmpFolder, $imgfile); } return $imgfile_sp; } return $imgfile_sp; }
protected function _do_watermark(Image $watermark, $offset_x, $offset_y, $opacity) { // Create the watermark image resource $overlay = imagecreatefromstring($watermark->render()); // Get the width and height of the watermark $width = imagesx($overlay); $height = imagesy($overlay); if ($opacity < 100) { // Convert an opacity range of 0-100 to 127-0 $opacity = round(abs($opacity * 127 / 100 - 127)); // Allocate transparent white $color = imagecolorallocatealpha($overlay, 255, 255, 255, $opacity); // The transparent image will overlay the watermark imagelayereffect($overlay, IMG_EFFECT_OVERLAY); // Fill the background with transparent white imagefilledrectangle($overlay, 0, 0, $width, $height, $color); } // Alpha blending must be enabled on the background! imagealphablending($this->_image, TRUE); if (imagecopy($this->_image, $overlay, $offset_x, $offset_y, 0, 0, $width, $height)) { // Destroy the overlay image imagedestroy($overlay); } }
$minY = 755; $maxZ = 14; $zoom = $minZ; // width and height of the area of interest, in number of tiles at minimum zoom $columns = 3; $rows = 5; while ($zoom <= $maxZ) { $width = $columns * 256; $height = $rows * 256; // create big image of the whole thing $im = imagecreatetruecolor($width, $height) or die("Cannot Initialize new GD image stream"); // use this for transparent background $black = imagecolorallocatealpha($im, 254, 254, 254, 127); imagefill($im, 0, 0, $black); imagesavealpha($im, true); imagelayereffect($im, IMG_EFFECT_ALPHABLEND); $slow = imagecolorallocatealpha($im, 170, 0, 0, $alpha); // red $med = imagecolorallocatealpha($im, 255, 244, 50, $alpha); // yellow $fast = imagecolorallocatealpha($im, 0, 240, 128, $alpha); // green foreach ($trips as $vehicle) { for ($i = 1; $i < count($vehicle); $i++) { $val = floatval($vehicle[$i][2]); // speed if ($val < 10) { $color = $slow; } else { if ($val < 25) { $color = $med;
/** * Execute a watermarking. * * @param Image $image watermarking Image * @param integer $offset_x offset from the left * @param integer $offset_y offset from the top * @param integer $opacity opacity of watermark * @return void */ protected function _do_watermark(Image $watermark, $offset_x, $offset_y, $opacity) { if (empty(GD::$_available_functions[GD::IMAGELAYEREFFECT])) { die('This method requires "imagelayereffect", which is only available in the bundled version of GD'); } // Loads image if not yet loaded $this->_load_image(); // Create the watermark image resource $overlay = imagecreatefromstring($watermark->render()); imagesavealpha($overlay, TRUE); // Get the width and height of the watermark $width = imagesx($overlay); $height = imagesy($overlay); if ($opacity < 100) { // Convert an opacity range of 0-100 to 127-0 $opacity = round(abs($opacity * 127 / 100 - 127)); // Allocate transparent gray $color = imagecolorallocatealpha($overlay, 127, 127, 127, $opacity); // The transparent image will overlay the watermark imagelayereffect($overlay, IMG_EFFECT_OVERLAY); // Fill the background with the transparent color imagefilledrectangle($overlay, 0, 0, $width, $height, $color); } // Alpha blending must be enabled on the background! imagealphablending($this->_image, TRUE); if (imagecopy($this->_image, $overlay, $offset_x, $offset_y, 0, 0, $width, $height)) { // Destroy the overlay image imagedestroy($overlay); } }
public function createIcon($guildData, $showLevel = true, $width = 215) { //$id = strtolower(Core::$REGION .'-'. $guildData['realm'] .'-'. str_replace(' ', '_', $guildData['name'])); $id = Core::getID($guildData['name'], $guildData['realm']); $fName = $this->site->baseDir . "imgCache/{$id}_{$width}_" . intval($showLevel) . ".png"; /* if(file_exists($fName)) { return "imgCache/{$id}_{$width}.png"; } */ //Start copy-code $imgfile = $fName; #print $imgfile; if (file_exists($imgfile) and filemtime($imgfile) + 86400 > time()) { /* $finalimg = imagecreatefrompng($imgfile); imagesavealpha($finalimg,true); imagealphablending($finalimg, true); */ return "imgCache/{$id}_{$width}_" . intval($showLevel) . ".png"; } else { if ($width > 1 and $width < 215) { $height = $width / 215 * 230; $finalimg = imagecreatetruecolor($width, $height); $trans_colour = imagecolorallocatealpha($finalimg, 0, 0, 0, 127); imagefill($finalimg, 0, 0, $trans_colour); imagesavealpha($finalimg, true); imagealphablending($finalimg, true); } if ($guildData['side'] == 0) { $ring = 'alliance'; } else { $ring = 'horde'; } $imgOut = imagecreatetruecolor(215, 230); $emblemURL = $this->site->baseDir . "wowIcons/guildImg/emblems/emblem_" . sprintf("%02s", $guildData['emblem']['icon']) . ".png"; $borderURL = $this->site->baseDir . "wowIcons/guildImg/borders/border_" . sprintf("%02s", $guildData['emblem']['border']) . ".png"; $ringURL = $this->site->baseDir . "wowIcons/guildImg/static/ring-" . $ring . ".png"; $shadowURL = $this->site->baseDir . "wowIcons/guildImg/static/shadow_00.png"; $bgURL = $this->site->baseDir . "wowIcons/guildImg/static/bg_00.png"; $overlayURL = $this->site->baseDir . "wowIcons/guildImg/static/overlay_00.png"; $hooksURL = $this->site->baseDir . "wowIcons/guildImg/static/hooks.png"; $levelURL = $this->site->baseDir . "wowIcons/guildImg/static/"; imagesavealpha($imgOut, true); imagealphablending($imgOut, true); $trans_colour = imagecolorallocatealpha($imgOut, 0, 0, 0, 127); imagefill($imgOut, 0, 0, $trans_colour); $ring = imagecreatefrompng($ringURL); $ring_size = getimagesize($ringURL); $emblem = imagecreatefrompng($emblemURL); $emblem_size = getimagesize($emblemURL); imagelayereffect($emblem, IMG_EFFECT_OVERLAY); $emblemcolor = preg_replace('/^ff/i', '', $guildData['emblem']['iconColor']); $color_r = hexdec(substr($emblemcolor, 0, 2)); $color_g = hexdec(substr($emblemcolor, 2, 2)); $color_b = hexdec(substr($emblemcolor, 4, 2)); imagefilledrectangle($emblem, 0, 0, $emblem_size[0], $emblem_size[1], imagecolorallocatealpha($emblem, $color_r, $color_g, $color_b, 0)); $border = imagecreatefrompng($borderURL); $border_size = getimagesize($borderURL); imagelayereffect($border, IMG_EFFECT_OVERLAY); $bordercolor = preg_replace('/^ff/i', '', $guildData['emblem']['borderColor']); //print_r($bordercolor); $color_r = hexdec(substr($bordercolor, 0, 2)); $color_g = hexdec(substr($bordercolor, 2, 2)); $color_b = hexdec(substr($bordercolor, 4, 2)); imagefilledrectangle($border, 0, 0, $border_size[0] + 100, $border_size[1] + 100, imagecolorallocatealpha($border, $color_r, $color_g, $color_b, 0)); $shadow = imagecreatefrompng($shadowURL); $bg = imagecreatefrompng($bgURL); $bg_size = getimagesize($bgURL); imagelayereffect($bg, IMG_EFFECT_OVERLAY); $bgcolor = preg_replace('/^ff/i', '', $guildData['emblem']['backgroundColor']); $color_r = hexdec(substr($bgcolor, 0, 2)); $color_g = hexdec(substr($bgcolor, 2, 2)); $color_b = hexdec(substr($bgcolor, 4, 2)); imagefilledrectangle($bg, 0, 0, $bg_size[0] + 100, $bg_size[0] + 100, imagecolorallocatealpha($bg, $color_r, $color_g, $color_b, 0)); $overlay = imagecreatefrompng($overlayURL); $hooks = imagecreatefrompng($hooksURL); $x = 20; $y = 23; //if (!$this->emblemHideRing){ imagecopy($imgOut, $ring, 0, 0, 0, 0, $ring_size[0], $ring_size[1]); //} $size = getimagesize($shadowURL); imagecopy($imgOut, $shadow, $x, $y, 0, 0, $size[0], $size[1]); imagecopy($imgOut, $bg, $x, $y, 0, 0, $bg_size[0], $bg_size[1]); imagecopy($imgOut, $emblem, $x + 17, $y + 30, 0, 0, $emblem_size[0], $emblem_size[1]); imagecopy($imgOut, $border, $x + 13, $y + 15, 0, 0, $border_size[0], $border_size[1]); $size = getimagesize($overlayURL); imagecopy($imgOut, $overlay, $x, $y + 2, 0, 0, $size[0], $size[1]); $size = getimagesize($hooksURL); imagecopy($imgOut, $hooks, $x - 2, $y, 0, 0, $size[0], $size[1]); if ($showLevel) { $level = $guildData['level']; if ($level < 10) { $levelIMG = imagecreatefrompng($levelURL . $level . ".png"); //echo $levelURL.$level.".png"; } else { //$levelURL.$level.".png"; $digit[1] = substr($level, 0, 1); $digit[2] = substr($level, 1, 1); $digit1 = imagecreatefrompng($levelURL . $digit[1] . ".png"); $digit2 = imagecreatefrompng($levelURL . $digit[2] . ".png"); $digitwidth = imagesx($digit1); $digitheight = imagesy($digit1); $levelIMG = imagecreatetruecolor($digitwidth * 2, $digitheight); $trans_colour = imagecolorallocatealpha($levelIMG, 0, 0, 0, 127); imagefill($levelIMG, 0, 0, $trans_colour); imagesavealpha($levelIMG, true); imagealphablending($levelIMG, true); // Last image added first because of the shadow need to be behind first digit imagecopy($levelIMG, $digit2, $digitwidth - 12, 0, 0, 0, $digitwidth, $digitheight); imagecopy($levelIMG, $digit1, 12, 0, 0, 0, $digitwidth, $digitheight); } $size[0] = imagesx($levelIMG); $size[1] = imagesy($levelIMG); $levelemblem = imagecreatefrompng($ringURL); imagesavealpha($levelemblem, true); imagealphablending($levelemblem, true); imagecopy($levelemblem, $levelIMG, 215 / 2 - $size[0] / 2, 215 / 2 - $size[1] / 2, 0, 0, $size[0], $size[1]); imagecopyresampled($imgOut, $levelemblem, 143, 150, 0, 0, 215 / 3, 215 / 3, 215, 215); } if ($width > 1 and $width < 215) { imagecopyresampled($finalimg, $imgOut, 0, 0, 0, 0, $width, $height, 215, 230); } else { $finalimg = $imgOut; } imagepng($finalimg, $imgfile); } return "imgCache/{$id}_{$width}_" . intval($showLevel) . ".png"; }
protected function _watermark(\Leaps\Image\Adapter $watermark, $offset_x, $offset_y, $opacity) { $overlay = imagecreatefromstring($watermark->render()); imagesavealpha($overlay, true); $width = (int) imagesx($overlay); $height = (int) imagesy($overlay); if ($opacity < 100) { $opacity = (int) round(abs($opacity * 127 / 100 - 127)); $color = imagecolorallocatealpha($overlay, 127, 127, 127, $opacity); imagelayereffect($overlay, IMG_EFFECT_OVERLAY); imagefilledrectangle($overlay, 0, 0, $width, $height, $color); } imagealphablending($this->_image, true); if (imagecopy($this->_image, $overlay, $offset_x, $offset_y, 0, 0, $width, $height)) { imagedestroy($overlay); } }