/** * Overlay an image onto the current image. * * @param string $image * @param int $x * @param int $y * @throws Exception * @return Gd */ public function overlay($image, $x = 0, $y = 0) { imagealphablending($this->image->resource(), true); // Create an image resource from the overlay image. if (stripos($image, '.gif') !== false) { $overlay = imagecreatefromgif($image); } else { if (stripos($image, '.png') !== false) { $overlay = imagecreatefrompng($image); } else { if (stripos($image, '.jp') !== false) { $overlay = imagecreatefromjpeg($image); } else { throw new Exception('Error: The overlay image must be either a JPG, GIF or PNG.'); } } } if ($this->opacity > 0) { if ($this->opacity == 100) { imagecopy($this->image->resource(), $overlay, $x, $y, 0, 0, imagesx($overlay), imagesy($overlay)); } else { imagecopymerge($this->image->resource(), $overlay, $x, $y, 0, 0, imagesx($overlay), imagesy($overlay), $this->opacity); } } return $this; }
function run() { global $dynbasepath, $rootpath; $MAX_LEN = 630; $totalWidth = 0; $counter = 0; $im = imagecreatetruecolor($MAX_LEN, 80); $alpha = imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im, 0, 0, 800, 80, $alpha); imagecolortransparent($im, $alpha); $numbers = $this->mrand(1, 50, 50); while ($totalWidth < $MAX_LEN && $counter < 10) { $number = $numbers[$counter]; $path = $rootpath . 'images/header/header_' . $number . '.jpg'; $tmp = imagecreatefromjpeg($path); $totalWidth += imagesx($tmp); /* echo "total=".$totalWidth; echo "<br />"; echo "im_".$number."=".imagesx($tmp); */ if ($totalWidth >= $MAX_LEN) { // return the real width od final logo $totalWidth -= imagesx($tmp); break; } imagecopy($im, $tmp, $totalWidth - imagesx($tmp), 0, 0, 0, imagesx($tmp), imagesy($tmp)); $counter++; } $im_final = imagecreatetruecolor($totalWidth, 80); imagecopy($im_final, $im, 0, 0, 0, 0, $totalWidth, 80); imagejpeg($im_final, $rootpath . "images/header/logo.jpg", 90); imagedestroy($im); imagedestroy($im_final); }
function cuttingimg($zoom, $fn, $sz) { @mkdir(WUO_ROOT . '/photos/maps'); $img = imagecreatefrompng(WUO_ROOT . '/photos/maps/0-0-0-' . $fn); // получаем идентификатор загруженного изрбражения которое будем резать $info = getimagesize(WUO_ROOT . '/photos/maps/0-0-0-' . $fn); // получаем в массив информацию об изображении $w = $info[0]; $h = $info[1]; // ширина и высота исходного изображения $sx = round($w / $sz, 0); // длинна куска изображения $sy = round($h / $sz, 0); // высота куска изображения $px = 0; $py = 0; // координаты шага "реза" for ($y = 0; $y <= $sz; $y++) { for ($x = 0; $x <= $sz; $x++) { $imgcropped = imagecreatetruecolor($sx, $sy); imagecopy($imgcropped, $img, 0, 0, $px, $py, $sx, $sy); imagepng($imgcropped, WUO_ROOT . '/photos/maps/' . $zoom . '-' . $y . '-' . $x . '-' . $fn); $px = $px + $sx; } $px = 0; $py = $py + $sy; } }
/** * Background fill an image using the provided color * * @param int $width The desired width of the new image * @param int $height The desired height of the new image * @param Array the desired pad colors in RGB format, array should be array( 'top' => '', 'right' => '', 'bottom' => '', 'left' => '' ); */ private function fill_color(array $colors) { $current_size = $this->editor->get_size(); $size = array('width' => $this->args['width'], 'height' => $this->args['height']); $offsetLeft = ($size['width'] - $current_size['width']) / 2; $offsetTop = ($size['height'] - $current_size['height']) / 2; $new_image = imagecreatetruecolor($size['width'], $size['height']); // This is needed to support alpha imagesavealpha($new_image, true); imagealphablending($new_image, false); // Check if we are padding vertically or horizontally if ($current_size['width'] != $size['width']) { $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['left'], 0, 3), substr($colors['left'], 3, 3), substr($colors['left'], 6, 3), substr($colors['left'], 9, 3)); // Fill left color imagefilledrectangle($new_image, 0, 0, $offsetLeft + 5, $size['height'], $colorToPaint); $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['right'], 0, 3), substr($colors['right'], 3, 3), substr($colors['right'], 6, 3), substr($colors['left'], 9, 3)); // Fill right color imagefilledrectangle($new_image, $offsetLeft + $current_size['width'] - 5, 0, $size['width'], $size['height'], $colorToPaint); } elseif ($current_size['height'] != $size['height']) { $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['top'], 0, 3), substr($colors['top'], 3, 3), substr($colors['top'], 6, 3), substr($colors['left'], 9, 3)); // Fill top color imagefilledrectangle($new_image, 0, 0, $size['width'], $offsetTop + 5, $colorToPaint); $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['bottom'], 0, 3), substr($colors['bottom'], 3, 3), substr($colors['bottom'], 6, 3), substr($colors['left'], 9, 3)); // Fill bottom color imagefilledrectangle($new_image, 0, $offsetTop - 5 + $current_size['height'], $size['width'], $size['height'], $colorToPaint); } imagecopy($new_image, $this->editor->get_image(), $offsetLeft, $offsetTop, 0, 0, $current_size['width'], $current_size['height']); $this->editor->update_image($new_image); $this->editor->update_size(); }
public function thumbCkeditor($new_width = 0, $new_height = 0) { list($water_width, $water_height, $water_type) = getimagesize(WATER_DIR); $water = $this->getImageFrom(WATER_DIR, $water_type); if (empty($new_height) && empty($new_width)) { $new_height = $this->height; $new_width = $this->width; } elseif (!is_numeric($new_width) || !is_numeric($new_width)) { $new_height = $this->height; $new_width = $this->width; } //固定一边缩放 if ($this->width > $new_width) { $new_height = $new_width / $this->width * $this->height; } else { $new_width = $this->width; $new_height = $this->height; } if ($this->height > $new_height) { $new_width = $new_height / $this->height * $this->width; } else { $new_width = $this->width; $new_height = $this->height; } //水印的位置 $water_x = $new_width - $water_width - 5; $water_y = $new_height - $water_height - 5; //创建一个画布用来存放缩略图 $this->thumb = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($this->thumb, $this->img, 0, 0, 0, 0, $new_width, $new_height, $this->width, $this->height); if ($new_width > $water_width && $new_height > $water_height) { imagecopy($this->thumb, $water, $water_x, $water_y, 0, 0, $water_width, $water_height); } imagedestroy($water); }
/** * method puts image onto map image * * @param Map $map * @param resources $imageToPut */ public function putImage(Map $map, $imageToPut) { $mapImage = $map->getImage(); $width = imagesx($imageToPut); $height = imagesy($imageToPut); imagecopy($mapImage, $imageToPut, imagesx($mapImage) - $width, 0, 0, 0, $width, $height); }
public function render(Job $job) { $format = $this->configuration->getString('format', 'png'); $defaultColor = $format == 'png' ? 0x0 : 0xffffffff; $backgroundColor = $this->configuration->getColor('background', $defaultColor); foreach ($job->spritesheets as $spritesheet) { /** @var Spritesheet $spritesheet */ $image = ImageTools::createImage($spritesheet->width, $spritesheet->height, $backgroundColor); foreach ($spritesheet->sprites as $sprite) { $repeatY = $sprite->repeatY; while ($repeatY--) { $repeatX = $sprite->repeatX; while ($repeatX--) { imagecopy($image, $sprite->image, $sprite->spriteX + $sprite->paddingLeft + $repeatX * $sprite->width, $sprite->spriteY + $sprite->paddingTop + $repeatY * $sprite->height, 0, 0, $sprite->width, $sprite->height); } } } $output = $this->mosaic->getPath($this->configuration->getString('outputFolder', Configuration::VALUE_REQUIRED)); $encodedSpritesheetPath = Tools::encodeFilePath($output . '/' . $spritesheet->name . '.' . $format); FileTools::createDirectory(dirname($encodedSpritesheetPath)); if ($format == 'png') { imagepng($image, $encodedSpritesheetPath, 9, E_ALL); } elseif ($format == 'jpg') { imagejpeg($image, $encodedSpritesheetPath, $this->configuration->getInt('quality', 90)); } imagedestroy($image); $encodedSpritesheetPath = realpath($encodedSpritesheetPath); if (!$encodedSpritesheetPath) { throw new \Exception('Could not verify rendered spritesheet path.'); } // Normalize output path $spritesheet->path = Tools::decodeFilePath($encodedSpritesheetPath); } }
function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center") { // Calculate the watermark position switch ($position) { case "center": $marginBottom = round($imgHeight / 2); $marginRight = round($imgWidth / 2) - round($watermarkWidth / 2); break; case "top-left": $marginBottom = round($imgHeight - $watermarkHeight); $marginRight = round($imgWidth - $watermarkWidth); break; case "bottom-left": $marginBottom = 5; $marginRight = round($imgWidth - $watermarkWidth); break; case "top-right": $marginBottom = round($imgHeight - $watermarkHeight); $marginRight = 5; break; default: $marginBottom = 2; $marginRight = 2; break; } $watermark = imagecreatefrompng($watermark); switch ($mimeType) { case "jpeg": case "jpg": $createImage = imagecreatefromjpeg($image); break; case "png": $createImage = imagecreatefrompng($image); break; case "gif": $createImage = imagecreatefromgif($image); break; default: $createImage = imagecreatefromjpeg($image); break; } $sx = imagesx($watermark); $sy = imagesy($watermark); imagecopy($createImage, $watermark, imagesx($createImage) - $sx - $marginRight, imagesy($createImage) - $sy - $marginBottom, 0, 0, imagesx($watermark), imagesy($watermark)); switch ($mimeType) { case "jpeg": case "jpg": imagejpeg($createImage, $image); break; case "png": imagepng($createImage, $image); break; case "gif": imagegif($createImage, $image); break; default: throw new \Exception("A watermark can only be applied to: jpeg, jpg, gif, png images "); break; } }
function imagemergealpha($i) { //create a new image $s = imagecreatetruecolor(imagesx($i[0]), imagesy($i[1])); $back_color = imagecolorallocate($s, 0xa9, 0xb1, 0xd3); //merge all images imagealphablending($s, true); $z = $i; while ($d = each($z)) { imagecopy($s, $d[1], 0, 0, 0, 0, imagesx($d[1]), imagesy($d[1])); } //restore the transparency imagealphablending($s, false); $w = imagesx($s); $h = imagesy($s); for ($x = 0; $x < $w; $x++) { for ($y = 0; $y < $h; $y++) { $c = imagecolorat($s, $x, $y); $c = imagecolorsforindex($s, $c); $z = $i; $t = 0; while ($d = each($z)) { $ta = imagecolorat($d[1], $x, $y); $ta = imagecolorsforindex($d[1], $ta); $t += 127 - $ta['alpha']; } $t = $t > 127 ? 127 : $t; $t = 127 - $t; $c = imagecolorallocatealpha($s, $c['red'], $c['green'], $c['blue'], $t); imagesetpixel($s, $x, $y, $c); } } imagesavealpha($s, true); return $s; }
function creaMapa($usuario, $img, $pantalla, $nombre, $nFil, $nCol) { $nombreComp = dirname(__DIR__) . "/../img/mapasUsuarios/{$nombre}.png"; //GUARDO UN FICHERO .PNG CON LA IMAGEN DE LA PANTALLA //Creo una imagen en memoria a partir de la cadena en base64:pacman/autogenerados $im = imagecreatefromstring($img); if ($im !== false) { header('Content-Type: image/png'); imagepng($im); //imagedestroy($im); } else { echo 'An error occurred.'; } //Creo el fichero para almacenar la imagen creada en memoria $ancho = 10 * $nCol; $alto = 10 * $nFil; $nuevaImg = imagecreatetruecolor($ancho, $alto); imagecopy($nuevaImg, $im, 0, 0, 0, 0, $ancho, $alto); imagepng($nuevaImg, $nombreComp); //El directorio esta en $nombreComp imagedestroy($nuevaImg); imagedestroy($im); //LLAMO A CONSULTAS PARA HACER LA INSERCION EN BBDD include_once dirname(__DIR__) . "/dao/consultas.php"; $chulta = metePantalla($pantalla, $nombre, $usuario, $nFil, $nCol); return $chulta; }
/** * Reduces colors of a given image * * @param \Intervention\Image\Image $image * @return boolean */ public function execute($image) { $count = $this->argument(0)->value(); $matte = $this->argument(1)->value(); // get current image size $size = $image->getSize(); // create empty canvas $resource = imagecreatetruecolor($size->width, $size->height); // define matte if (is_null($matte)) { $matte = imagecolorallocatealpha($resource, 255, 255, 255, 127); } else { $matte = $image->getDriver()->parseColor($matte)->getInt(); } // fill with matte and copy original image imagefill($resource, 0, 0, $matte); // set transparency imagecolortransparent($resource, $matte); // copy original image imagecopy($resource, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height); if (is_numeric($count) && $count <= 256) { // decrease colors imagetruecolortopalette($resource, true, $count); } // set new resource $image->setCore($resource); return true; }
/** * Method called when 'clone' keyword is used. */ public function __clone() { $original = $this->gd; $copy = imagecreatetruecolor($this->width, $this->height); imagecopy($copy, $original, 0, 0, 0, 0, $this->width, $this->height); $this->gd = $copy; }
protected function add_water($src, $width, $height) { if ($this->waterimg and is_numeric($this->arg["water_scope"]) and $width > $this->arg["water_scope"] and $height > $this->arg["water_scope"]) { imagecopy($src, $this->waterimg[0], $width - $this->waterimg[1] - 10, $height - $this->waterimg[2] - 10, 0, 0, $this->waterimg[1], $this->waterimg[2]); } return $src; }
public function process(Image $image) { $destCanvas = $image->getCanvas(); $destImageMetrics = $image->getMetrics(); $watermarkImage = $this->getWaterMarkSource(); $wmWidth = $this->watermarkMetrics[0]; $wmHeight = $this->watermarkMetrics[1]; $wmImageType = $this->watermarkMetrics[2]; $destinationX = ""; $destinationY = ""; switch ($this->position) { case self::TOP_LEFT: $destinationX = $destImageMetrics->sourceWidth - $destImageMetrics->sourceWidth; $destinationY = $destImageMetrics->sourceHeight - $destImageMetrics->sourceHeight; break; case self::TOP_RIGHT: $destinationX = $destImageMetrics->sourceWidth - $wmWidth - 15; $destinationY = $destImageMetrics->sourceHeight - $destImageMetrics->sourceHeight; break; case self::BOTTOM_LEFT: $destinationX = $destImageMetrics->sourceWidth - $destImageMetrics->sourceWidth; $destinationY = $destImageMetrics->sourceHeight - $wmHeight - 15; break; case self::BOTTOM_RIGHT: $destinationX = $destImageMetrics->sourceWidth - $wmWidth - 15; $destinationY = $destImageMetrics->sourceHeight - $wmHeight - 15; break; } imagecopy($destCanvas, $watermarkImage, $destinationX, $destinationY, 0, 0, $wmWidth, $wmHeight); }
/** * Save image to specific path. * If some folders of path does not exist they will be created * * @throws Exception if destination path is not writable * @param string $destination * @param string $newName */ public function save($destination = null, $newName = null) { $fileName = $this->_prepareDestination($destination, $newName); if (!$this->_resized) { // keep alpha transparency $isAlpha = false; $isTrueColor = false; $this->_getTransparency($this->_imageHandler, $this->_fileType, $isAlpha, $isTrueColor); if ($isAlpha) { if ($isTrueColor) { $newImage = imagecreatetruecolor($this->_imageSrcWidth, $this->_imageSrcHeight); } else { $newImage = imagecreate($this->_imageSrcWidth, $this->_imageSrcHeight); } $this->_fillBackgroundColor($newImage); imagecopy($newImage, $this->_imageHandler, 0, 0, 0, 0, $this->_imageSrcWidth, $this->_imageSrcHeight); $this->_imageHandler = $newImage; } } $functionParameters = array($this->_imageHandler, $fileName); $quality = $this->quality(); if ($quality !== null) { if ($this->_fileType == IMAGETYPE_PNG) { // for PNG files quality param must be from 0 to 10 $quality = ceil($quality / 10); if ($quality > 10) { $quality = 10; } $quality = 10 - $quality; } $functionParameters[] = $quality; } call_user_func_array($this->_getCallback('output'), $functionParameters); }
/** * Build the CSS sprite in memory * @return Tinyfier_Image_Tool */ public function build() { //Sort images inside the sprite $y = 0; foreach ($this->_images as $image) { $image->top = $y; $image->left = 0; $y += $image->image->height(); } //Draw sprite $w = 0; $h = 0; foreach ($this->_images as $image) { $w = max($w, $image->left + $image->image->width()); $h = max($w, $image->top + $image->image->height()); } $sprite = imagecreatetruecolor($w, $h); imagealphablending($sprite, false); //Soporte de transparencias imagefill($sprite, 0, 0, imagecolorallocatealpha($sprite, 0, 0, 0, 127)); //Fondo transparente foreach ($this->_images as $image) { imagecopy($sprite, $image->image->handle(), $image->left, $image->top, 0, 0, $image->image->width(), $image->image->height()); } return new Tinyfier_Image_Tool($sprite); }
function watermark($path) { // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script // where this script is named watermark.php // call this script with an image tag // <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg //$imagesource = $_GET['path']; $imagesource = $path; $filetype = substr($imagesource, strlen($imagesource) - 4, 4); $filetype = strtolower($filetype); if ($filetype == ".gif") { $image = @imagecreatefromgif($imagesource); } if ($filetype == ".jpg") { $image = @imagecreatefromjpeg($imagesource); } if ($filetype == ".png") { $image = @imagecreatefrompng($imagesource); } if (!$image) { die; } $watermark = @imagecreatefromgif($basepath . '/wp-content/plugins/wp-shopping-cart/images/watermark.gif'); $imagewidth = imagesx($image); $imageheight = imagesy($image); $watermarkwidth = imagesx($watermark); $watermarkheight = imagesy($watermark); $startwidth = ($imagewidth - $watermarkwidth) / 2; $startheight = ($imageheight - $watermarkheight) / 2; imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); }
function cuttingimg($zoom, $fn, $sz) { $img = imagecreatefrompng("../../../photos/maps/" . '0-0-0-' . $fn); // получаем идентификатор загруженного изрбражения которое будем резать $info = getimagesize("../../../photos/maps/" . '0-0-0-' . $fn); // получаем в массив информацию об изображении $w = $info[0]; $h = $info[1]; // ширина и высота исходного изображения $sx = round($w / $sz, 0); // длинна куска изображения $sy = round($h / $sz, 0); // высота куска изображения $px = 0; $py = 0; // координаты шага "реза" //echo "-- $sx,$sy -- $w/$h -- $img !"; //print_r($info); for ($y = 0; $y <= $sz; $y++) { for ($x = 0; $x <= $sz; $x++) { $imgcropped = imagecreatetruecolor($sx, $sy); imagecopy($imgcropped, $img, 0, 0, $px, $py, $sx, $sy); imagepng($imgcropped, "../../../photos/maps/" . $zoom . "-" . $y . "-" . $x . "-" . $fn); $px = $px + $sx; //echo "../../images/maps/".$y."-".$x."-".$fn; } $px = 0; $py = $py + $sy; } // return "ok"; }
public static function createPingImg($imgurl, $ping = ImageHelper::PING_BASE_RED) { $ping = Url::to($ping); //ファイルから新規にJPEG画像を作成する $image_back = imagecreatefrompng($ping); $image_alpha = static::createImageByMask($imgurl); //背景画像の幅と高さを取得 list($width, $height, $type, $attr) = getimagesize($ping); //合成する画像をちょいとずらしてみる $x = 32; $y = 32; //imagealphablending($image_back, false); //imagealphablending($image_alpha, false); imagesavealpha($image_back, true); imagesavealpha($image_alpha, true); //画像を合成する imagecopy($image_back, $image_alpha, $x, $y, 0, 0, imagesx($image_alpha), imagesy($image_alpha)); //合成した画像を出力 //header("Content-type: image/png"); //imagepng($image_back); $filename = basename($imgurl, ".jpg") . ".png"; $filepath = Url::to(static::PING_IMG_DIR) . $filename; imagepng($image_back, $filepath); //メモリから解放 imagedestroy($image_back); imagedestroy($image_alpha); }
function merge($width, $height) { $array_variable = get_variable(); $bg = $array_variable[0]; $over = $array_variable[1]; $outputFile = $array_variable[2]; $result = $array_variable[3]; $path_to_save = $array_variable[4]; $n = $array_variable[5]; $tmp_img = $path_to_save . "/tmp_" . $n . ".png"; // $result_jpg_compressed = $path_to_save.'/'.$n.'.JPG'; // $base_image = imagecreatefrompng($bg); jpg2png($bg, $outputFile); $base_image = imagecreatefrompng($outputFile); $top_image = imagecreatefrompng($over); // $merged_image = $result; imagesavealpha($top_image, true); imagealphablending($top_image, true); imagecopy($base_image, $top_image, 0, 0, 0, 0, $width, $height); imagepng($base_image, $result); // rename to temp for compression rename($result, $path_to_save . "/tmp_" . $n . ".png"); // compress IMG $img = imagecreatefrompng($tmp_img); // imagejpeg($img,$result_jpg_compressed,75); imagejpeg($img, $result, 75); unlink($tmp_img); unlink($tmp_img); // if necessery !!!!!!!!!!!!!!!!!!! unlink($outputFile); unlink($over); }
function createCode($len = 4) { $width = 100; $height = 50; $size = 22; //字体大小 $font = ROOT_PATH . '/static/font/arial.ttf'; //字体 $img = imagecreatetruecolor($width, $height); //创建画布 $bgimg = imagecreatefromjpeg(ROOT_PATH . '/static/background/' . rand(1, 5) . '.jpg'); //生成背景图片 $bg_x = rand(0, 100); //随机招贴画布起始X轴坐标 $bg_y = rand(0, 50); //随机招贴画布起始Y轴坐标 imagecopy($img, $bgimg, 0, 0, $bg_x, $bg_y, $bg_x + $width, $bg_y + $height); //把背景图片$bging粘贴的画布上 $str = $this->creaStr($len); //字符串 for ($i = 0, $j = 5; $i < 4; $i++) { $array = array(-1, 1); $p = array_rand($array); $an = $array[$p] * mt_rand(1, 10); //扭曲角度 imagettftext($img, $size, $an, $j + 5, 34, imagecolorallocate($img, rand(0, 100), rand(0, 100), rand(0, 100)), $font, $str[$i]); //生成验证字符窜 $j += 20; } cookie('captchacode', strtolower($str)); header('Content-type:image/png'); imagepng($img); imagedestroy($img); }
/** * Function copied from: http://www.php.net/manual/en/function.imagecopymerge.php#92787 * Does the same as "imagecopymerge" but preserves the alpha-channel */ protected function imageCopyMergeAlpha(&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct) { $cut = imagecreatetruecolor($src_w, $src_h); imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h); imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h); imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct); }
function GetPartialImage($url) { $W = 150; $H = 130; $F = 80; $STEP = 1.0 / $F; $im = imagecreatefromjpeg($url); $dest = imagecreatetruecolor($W, $H); imagecopy($dest, $im, 0, 0, 35, 40, $W, $H); $a = 1; for( $y = $H - $F; $y < $H; $y++ ) { for ( $x = 0; $x < $W; $x++ ) { $i = imagecolorat($dest, $x, $y); $c = imagecolorsforindex($dest, $i); $c = imagecolorallocate($dest, a($c['red'], $a), a($c['green'], $a), a($c['blue'], $a) ); imagesetpixel($dest, $x, $y, $c); } $a -= $STEP; } header('Content-type: image/png'); imagepng($dest); imagedestroy($dest); imagedestroy($im); }
function img_bundle() { $sources = func_get_args(); $target = array_shift($sources); $this->sizeinfo = array(); $this->vpos = 0; $this->wpos = 0; foreach ($sources as $src) { $this->_bundle_index($src); } $target_img = imagecreatetruecolor($this->wpos, $this->vpos); $bg_color = imagecolorallocate($target_img, 255, 0, 255); //牺牲掉这个最丑的颜色做透明背景 //todo:智能选择调色板中没有的颜色 imagefilledrectangle($target_img, 0, 0, $this->wpos, $this->vpos, $bg_color); $app = $params['app'] ? app::get($params['app']) : $this->app; foreach ($this->sizeinfo as $file => $info) { $src_img = imagecreatefromgif($app->res_dir . '/' . $file); $rst = imagecopy($target_img, $src_img, 0, $info[0], 0, 0, $info[1], $info[2]); // $rst = imagecopyresampled($target_img,$src_img,0,$info[0],0,0,$info[1],$info[2],$info[1],$info[2]); // $rst = imagecopyresized($target_img,$src_img,0,$info[0],0,0,$info[1],$info[2],$info[1],$info[2]); $src_img = null; } imagecolortransparent($target_img, $bg_color); // imagetruecolortopalette($target_img,true,256); //todo:优化显示效果 imagegif($target_img, $app->res_dir . '/' . $target); $target_img = null; $rs = fopen($app->res_dir . '/' . $target, 'a'); $info = serialize($this->sizeinfo); fwrite($rs, pack('a*V', $info, strlen($info))); fclose($rs); $this->sizeinfo = null; }
public function fill_watermark() { $image = $this->editor->get_image(); $size = $this->editor->get_size(); list($mask_width, $mask_height, $mask_type, $mask_attr) = getimagesize($this->args['mask']); switch ($mask_type) { case 1: $mask = imagecreatefromgif($this->args['mask']); break; case 2: $mask = imagecreatefromjpeg($this->args['mask']); break; case 3: $mask = imagecreatefrompng($this->args['mask']); break; } imagealphablending($image, true); if (strpos($this->args['position'], 'left') !== false) { $left = $this->args['padding']; } else { $left = $size['width'] - $mask_width - $this->args['padding']; } if (strpos($this->args['position'], 'top') !== false) { $top = $this->args['padding']; } else { $top = $size['height'] - $mask_height - $this->args['padding']; } imagecopy($image, $mask, $left, $top, 0, 0, $mask_width, $mask_height); $this->editor->update_image($image); imagedestroy($mask); }
public static function water($source, $water, $savename = NULL, $alpha = 80) { if (!file_exists($source) || !file_exists($water)) { return false; } $sInfo = self::getImageInfo($source); $wInfo = self::getImageInfo($water); if ($sInfo['width'] < $wInfo['width'] || $sInfo['height'] < $wInfo['height']) { return false; } $sCreateFun = 'imagecreatefrom' . $sInfo['type']; $sImage = $sCreateFun($source); $wCreateFun = 'imagecreatefrom' . $wInfo['type']; $wImage = $wCreateFun($water); imagealphablending($wImage, true); $posY = $sInfo['height'] - $wInfo['height']; $posX = $sInfo['width'] - $wInfo['width']; imagecopy($sImage, $wImage, $posX, $posY, 0, 0, $wInfo['width'], $wInfo['height']); $ImageFun = 'Image' . $sInfo['type']; if (!$savename) { $savename = $source; @unlink($source); } if ($sInfo['type'] == 'jpg' || $sInfo['type'] == 'jpeg') { imagejpeg($sImage, $savename, 100); } else { $ImageFun($sImage, $savename); } imagedestroy($sImage); }
public function save() { $maxHeight = 0; $width = 0; foreach ($this->_segmentsArray as $segment) { $maxHeight = max($maxHeight, $segment->height); $width += $segment->width; } // create our canvas $img = imagecreatetruecolor($width, $maxHeight); $background = imagecolorallocatealpha($img, 255, 255, 255, 127); imagefill($img, 0, 0, $background); imagealphablending($img, false); imagesavealpha($img, true); // start placing our images on a single x axis $xPos = 0; foreach ($this->_segmentsArray as $segment) { $tmp = imagecreatefromjpeg($segment->pathToImage); imagecopy($img, $tmp, $xPos, 0, 0, 0, $segment->width, $segment->height); $xPos += $segment->width; imagedestroy($tmp); } // create our final output image. imagepng($img, $this->_saveToPath); }
function apply(lmbAbstractImageContainer $container) { list($x, $y, $width, $height) = $this->calculateCropArea($container->getWidth(), $container->getHeight()); $im = $container->isPallete() ? imagecreate($width, $height) : imagecreatetruecolor($width, $height); imagecopy($im, $container->getResource(), 0, 0, $x, $y, $width, $height); $container->replaceResource($im); }
/** * * @param string $playername Minecraft player name * @param resource $avatar the rendered avatar (for example player head) * * @param string $background Image Path or Standard Value * @return resource the generated banner */ public static function player($playername, $avatar = NULL, $background = NULL) { $canvas = MinecraftBanner::getBackgroundCanvas(self::PLAYER_WIDTH, self::PLAYER_HEIGHT, $background); $head_height = self::AVATAR_SIZE; $head_width = self::AVATAR_SIZE; $avater_x = self::PLAYER_PADDING; $avater_y = self::PLAYER_HEIGHT / 2 - self::AVATAR_SIZE / 2; if ($avatar == NULL) { $avatar = imagecreatefrompng(__DIR__ . "/img/head.png"); imagesavealpha($avatar, true); imagecopy($canvas, $avatar, $avater_x, $avater_y, 0, 0, $head_width, $head_height); } else { $head_width = imagesx($avatar); $head_height = imagesy($avatar); if ($head_width > self::AVATAR_SIZE) { $head_width = self::AVATAR_SIZE; } if ($head_height > self::AVATAR_SIZE) { $head_height = self::AVATAR_SIZE; } $center_x = $avater_x + self::AVATAR_SIZE / 2 - $head_width / 2; $center_y = $avater_y + self::AVATAR_SIZE / 2 - $head_height / 2; imagecopy($canvas, $avatar, $center_x, $center_y, 0, 0, $head_width, $head_height); } $box = imagettfbbox(self::TEXT_SIZE, 0, MinecraftBanner::FONT_FILE, $playername); $text_width = abs($box[4] - $box[0]); $text_color = imagecolorallocate($canvas, 255, 255, 255); $remaining = self::PLAYER_WIDTH - self::AVATAR_SIZE - $avater_x - self::PLAYER_PADDING; $text_posX = $avater_x + self::AVATAR_SIZE + $remaining / 2 - $text_width / 2; $text_posY = $avater_y + self::AVATAR_SIZE / 2 + self::TEXT_SIZE / 2; imagettftext($canvas, self::TEXT_SIZE, 0, $text_posX, $text_posY, $text_color, MinecraftBanner::FONT_FILE, $playername); return $canvas; }
public function addBackground($canvas, $bgImage, $bgWidth, $bgHeight, $bgOriginX, $bgOriginY) { $background = imagecreatetruecolor($bgWidth, $bgHeight); imagesettile($background, $bgImage); imagefill($background, 0, 0, IMG_COLOR_TILED); imagecopy($canvas, $background, $bgOriginX, $bgOriginY, 0, 0, $bgWidth, $bgHeight); }