Example #1
0
function resize_image_crop($src_image, $width, $height)
{
    $src_width = imageSX($src_image);
    $src_height = imageSY($src_image);
    $width = $width <= 0 ? $src_width : $width;
    $height = $height <= 0 ? $src_height : $height;
    $prop_width = $src_width / $width;
    $prop_height = $src_height / $height;
    if ($prop_height > $prop_width) {
        $crop_width = $src_width;
        $crop_height = round($prop_width * $height);
        $srcX = 0;
        $srcY = round($src_height / 2) - round($crop_height / 2);
    } else {
        $crop_width = round($prop_height * $width);
        $crop_height = $src_height;
        $srcX = round($src_width / 2) - round($crop_width / 2);
        $srcY = 0;
    }
    $new_image = imageCreateTrueColor($width, $height);
    $tmp_image = imageCreateTrueColor($crop_width, $crop_height);
    imageCopy($tmp_image, $src_image, 0, 0, $srcX, $srcY, $crop_width, $crop_height);
    imageCopyResampled($new_image, $tmp_image, 0, 0, 0, 0, $width, $height, $crop_width, $crop_height);
    imagedestroy($tmp_image);
    image_unsharp_mask($new_image);
    return $new_image;
}
Example #2
0
 /**
  * Method to apply a background color to an image resource.
  *
  * @param   array  $options  An array of options for the filter.
  *                           color  Background matte color
  *
  * @return  void
  *
  * @since   3.4
  * @throws  InvalidArgumentException
  * @deprecated  5.0  Use Joomla\Image\Filter\Backgroundfill::execute() instead
  */
 public function execute(array $options = array())
 {
     // Validate that the color value exists and is an integer.
     if (!isset($options['color'])) {
         throw new InvalidArgumentException('No color value was given. Expected string or array.');
     }
     $colorCode = !empty($options['color']) ? $options['color'] : null;
     // Get resource dimensions
     $width = imagesX($this->handle);
     $height = imagesY($this->handle);
     // Sanitize color
     $rgba = $this->sanitizeColor($colorCode);
     // Enforce alpha on source image
     if (imageIsTrueColor($this->handle)) {
         imageAlphaBlending($this->handle, false);
         imageSaveAlpha($this->handle, true);
     }
     // Create background
     $bg = imageCreateTruecolor($width, $height);
     imageSaveAlpha($bg, empty($rgba['alpha']));
     // Allocate background color.
     $color = imageColorAllocateAlpha($bg, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
     // Fill background
     imageFill($bg, 0, 0, $color);
     // Apply image over background
     imageCopy($bg, $this->handle, 0, 0, 0, 0, $width, $height);
     // Move flattened result onto curent handle.
     // If handle was palette-based, it'll stay like that.
     imageCopy($this->handle, $bg, 0, 0, 0, 0, $width, $height);
     // Free up memory
     imageDestroy($bg);
     return;
 }
Example #3
0
 public function watermark()
 {
     $imagecreatefromfunc = $this->_imagecreatefromfunc;
     $imagefunc = $this->_imagefunc;
     list($img_w, $img_h) = $this->_imageinfo;
     $watermark_file = 'D:/www/phpweb20/public/watermark.png';
     $watermarkinfo = @getimagesize($watermark_file);
     $watermark_logo = @imagecreatefrompng($watermark_file);
     if (!$watermark_logo) {
         return;
     }
     list($logo_w, $logo_h) = $watermarkinfo;
     $x = $img_w - $logo_w - 5;
     $y = $img_h - $logo_h - 5;
     $dst_photo = imagecreatetruecolor($img_w, $img_h);
     $image_photo = @$imagecreatefromfunc($this->_imagefile);
     imagecopy($dst_photo, $image_photo, 0, 0, 0, 0, $img_w, $img_h);
     imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);
     clearstatcache();
     if ($this->_imageinfo[2] == 2) {
         $imagefunc($dst_photo, $this->_imagefile, 80);
     } else {
         $imagefunc($dst_photo, $this->_imagefile);
     }
 }
 function asTrueColor()
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $new = wiTrueColorImage::create($width, $height);
     if ($this->isTransparent()) {
         $new->copyTransparencyFrom($this);
     }
     imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height);
     return $new;
 }
Example #5
0
 function AnimatedOut()
 {
     for ($i = 0; $i < ANIM_FRAMES; $i++) {
         $image = imageCreateTrueColor(imageSX($this->image), imageSY($this->image));
         if (imageCopy($image, $this->image, 0, 0, 0, 0, imageSX($this->image), imageSY($this->image))) {
             Captcha::DoNoise($image, 200, 0);
             Ob_Start();
             imageGif($image);
             imageDestroy($image);
             $f_arr[] = Ob_Get_Contents();
             $d_arr[] = ANIM_DELAYS;
             Ob_End_Clean();
         }
     }
     $GIF = new GIFEncoder($f_arr, $d_arr, 0, 2, -1, -1, -1, 'C_MEMORY');
     return $GIF->GetAnimation();
 }
Example #6
0
function watermask($targetfile, $logofile)
{
    $imagetype = array("1" => "gif", "2" => "jpeg", "3" => "png", "4" => "wbmp");
    $targetinfo = getimagesize($targetfile);
    $imagecreatefromfunc = "imagecreatefrom" . $imagetype[$targetinfo[2]];
    $imagefunc = "image" . $imagetype[$targetinfo[2]];
    list($img_w, $img_h) = $targetinfo;
    $watermarkinfo = getimagesize($logofile);
    $watermark = imageCreateFromPNG($logofile);
    list($logo_w, $logo_h) = $watermarkinfo;
    $x = $img_w - $logo_w - 5;
    $y = $img_h - $logo_h - 5;
    $dst_photo = imagecreatetruecolor($img_w, $img_h);
    $target_photo = @$imagecreatefromfunc($targetfile);
    imageCopy($dst_photo, $target_photo, 0, 0, 0, 0, $img_w, $img_h);
    imageCopy($dst_photo, $watermark, $x, $y, 0, 0, $logo_w, $logo_h);
    clearstatcache();
    $imagefunc($dst_photo, $targetfile, 80);
}
 /**
  * Add a Water Mark to the image
  * (filigrana)
  *
  * @param string $from
  * @param string $waterMark
  */
 public function addWaterMarkImage($waterMark, $opacity = 35, $x = 5, $y = 5)
 {
     // set data
     $size = $this->info;
     $im = $this->gdID;
     // set WaterMark's data
     $waterMarkSM = new SmartImage($waterMark);
     $imWM = $waterMarkSM->getGDid();
     // Add it!
     // In png watermark images we ignore the opacity (you have to set it in the watermark image)
     if ($waterMarkSM->info[2] == 3) {
         imageCopy($im, $imWM, $x, $y, 0, 0, imagesx($imWM), imagesy($imWM));
     } else {
         imageCopyMerge($im, $imWM, $x, $y, 0, 0, imagesx($imWM), imagesy($imWM), $opacity);
     }
     $waterMarkSM->close();
     $this->gdID = $im;
 }
Example #8
0
 function createpng($tag = 0, $gray = 0, $fuzzy = 0, $x = 1, $y = 1, $debug_flag = 0, $borders = array())
 {
     global $tmppath;
     global $tilecachepath;
     $v3img = dirname(__FILE__) . "/../imgs/v3image2.png";
     if ($this->createfromim == 1) {
         // just load image from im or filename
         $cim = $this->im;
     } else {
         // load from STB files
         $pscount = 1;
         $pstotal = $this->shiftx * $this->shifty;
         $this->doLog("check tiles...");
         for ($j = $this->starty; $j > $this->starty - $this->shifty; $j--) {
             for ($i = $this->startx; $i < $this->startx + $this->shiftx; $i++) {
                 //error_log("call $i $j");
                 list($status, $fname) = img_from_tiles($this->stbdir, $i * 1000, $j * 1000, 1, 1, $this->zoom, $this->ph, $debug_flag, $tmppath, $tilecachepath);
                 // 產生 progress
                 $this->doLog("{$pscount} /  {$pstotal}");
                 $this->doLog(sprintf("ps%%+%d", 20 * $pscount / $pstotal));
                 $pscount++;
                 if ($status === FALSE) {
                     error_log("error {$fname}");
                     $this->err[] = $fname;
                     return FALSE;
                 }
                 $fn[] = $fname;
             }
         }
         //print_r($fn);
         // 合併
         $this->doLog("merge tiles...");
         $outi = $outimage = tempnam($tmppath, "MTILES");
         $montage_bin = "montage";
         $cmd = sprintf("{$montage_bin} %s -mode Concatenate -tile %dx%d miff:-| composite -gravity northeast %s - miff:-| convert - -resize %dx%d\\! png:%s", implode(" ", $fn), $this->shiftx, $this->shifty, $v3img, $this->shiftx * 315, $this->shifty * 315, $outi);
         if ($debug_flag) {
             $this->doLog($cmd);
         }
         exec($cmd);
         $cim = imagecreatefrompng($outi);
         exec("rm " . implode(" ", $fn) . " {$outi}");
         //	$cim=cropimage($im,$this->movX,$this->movY,
         //		$this->shiftx * 315 + $fuzzy,
         //		$this->shifty * 315 + $fuzzy );
     }
     if ($tag == 1) {
         // echo "tag it ...\n";
         $this->doLog("tagimage ...");
         $cim = tagimage($cim, $this->startx, $this->starty, $fuzzy);
     } else {
         if ($tag == 2) {
             if ($this->outsizex == 0 || $this->outsizey == 0) {
                 $this->err[] = "Please call setoutsize() first\n";
                 return FALSE;
             }
             if ($this->createfromim == 0 && ($this->shiftx < $this->outsizex || $this->shifty < $this->outsizey)) {
                 // echo "resizing image...\n";
                 $dst = imageCreate($this->outsizex * 315 + $fuzzy, $this->outsizey * 315 + $fuzzy);
                 $bgcolor = imagecolorallocate($dst, 255, 255, 255);
                 imagefill($dst, 0, 0, $bgcolor);
                 imageCopy($dst, $cim, 0, 0, 0, 0, imageSX($cim), imageSY($cim));
                 $cim = $dst;
             }
             // refer to X,Y, I
             // debug: echo "addtagbprder2 cim $x $y $d $this->startx, $this->starty, 4x6, $this->shiftx, $this->shifty $fuzzy \n";
             $this->doLog("add borders ...");
             $cim = addtagborder2($cim, $x, $y, $debug_flag, $this->startx, $this->starty, array("x" => $this->outsizex, "y" => $this->outsizey), $this->shiftx, $this->shifty, $fuzzy);
             if (!($x == 1 && $y == 1)) {
                 // echo "add boder to cut or paste...\n";
                 $cim = addborder2($cim, $x, $y, $debug_flag, $borders);
             }
         }
     }
     if ($gray >= 1) {
         // $cim = grayscale($cim);
         //grayscale2($cim);
         $this->doLog("grayscale image ...");
         $cim = im_grayscale($cim);
     }
     return $cim;
 }
	/**
	* Horizontally mirror (flop) the image
	* 
	* @param Asido_Image &$image
	* @return boolean
	* @access protected
	*/
	function __flop(&$tmp) {

		$t = imageCreateTrueColor($tmp->image_width, $tmp->image_height);
		imageAlphaBlending($t, true);

		for ($x = 0; $x < $tmp->image_width; ++$x) {
			imageCopy(
				$t,
				$tmp->target,
				$x, 0,
                		$tmp->image_width - $x - 1, 0,
                		1, $tmp->image_height
                		);
			}
		imageAlphaBlending($t, false);

		$this->__destroy_target($tmp);
		$tmp->target = $t;

		return true;
		}
Example #10
0
function makewatermark($srcfile)
{
    global $_SCONFIG;
    if ($_SCONFIG['watermark'] && function_exists('imageCreateFromJPEG') && function_exists('imageCreateFromPNG') && function_exists('imageCopyMerge')) {
        $srcfile = A_DIR . '/' . $srcfile;
        $watermark_file = $_SCONFIG['watermarkfile'];
        $watermarkstatus = $_SCONFIG['watermarkstatus'];
        $fileext = fileext($watermark_file);
        $ispng = $fileext == 'png' ? true : false;
        $attachinfo = @getimagesize($srcfile);
        if (!empty($attachinfo) && is_array($attachinfo) && $attachinfo[2] != 1 && $attachinfo['mime'] != 'image/gif') {
        } else {
            return '';
        }
        $watermark_logo = $ispng ? @imageCreateFromPNG($watermark_file) : @imageCreateFromGIF($watermark_file);
        if (!$watermark_logo) {
            return '';
        }
        $logo_w = imageSX($watermark_logo);
        $logo_h = imageSY($watermark_logo);
        $img_w = $attachinfo[0];
        $img_h = $attachinfo[1];
        $wmwidth = $img_w - $logo_w;
        $wmheight = $img_h - $logo_h;
        if (is_readable($watermark_file) && $wmwidth > 100 && $wmheight > 100) {
            switch ($attachinfo['mime']) {
                case 'image/jpeg':
                    $dst_photo = imageCreateFromJPEG($srcfile);
                    break;
                case 'image/gif':
                    $dst_photo = imageCreateFromGIF($srcfile);
                    break;
                case 'image/png':
                    $dst_photo = imageCreateFromPNG($srcfile);
                    break;
                default:
                    break;
            }
            switch ($watermarkstatus) {
                case 1:
                    $x = +5;
                    $y = +5;
                    break;
                case 2:
                    $x = ($img_w - $logo_w) / 2;
                    $y = +5;
                    break;
                case 3:
                    $x = $img_w - $logo_w - 5;
                    $y = +5;
                    break;
                case 4:
                    $x = +5;
                    $y = ($img_h - $logo_h) / 2;
                    break;
                case 5:
                    $x = ($img_w - $logo_w) / 2;
                    $y = ($img_h - $logo_h) / 2;
                    break;
                case 6:
                    $x = $img_w - $logo_w - 5;
                    $y = ($img_h - $logo_h) / 2;
                    break;
                case 7:
                    $x = +5;
                    $y = $img_h - $logo_h - 5;
                    break;
                case 8:
                    $x = ($img_w - $logo_w) / 2;
                    $y = $img_h - $logo_h - 5;
                    break;
                case 9:
                    $x = $img_w - $logo_w - 5;
                    $y = $img_h - $logo_h - 5;
                    break;
            }
            if ($ispng) {
                $watermark_photo = imagecreatetruecolor($img_w, $img_h);
                imageCopy($watermark_photo, $dst_photo, 0, 0, 0, 0, $img_w, $img_h);
                imageCopy($watermark_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);
                $dst_photo = $watermark_photo;
            } else {
                imageAlphaBlending($watermark_logo, true);
                imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $_SCONFIG['watermarktrans']);
            }
            switch ($attachinfo['mime']) {
                case 'image/jpeg':
                    imageJPEG($dst_photo, $srcfile, $_SCONFIG['watermarkjpgquality']);
                    break;
                case 'image/gif':
                    imageGIF($dst_photo, $srcfile);
                    break;
                case 'image/png':
                    imagePNG($dst_photo, $srcfile);
                    break;
            }
        }
    }
}
Example #11
0
 if ($width / $height > $ratio_orig) {
     $width = $height * $ratio_orig;
 } else {
     $height = $width / $ratio_orig;
 }
 # Resample
 $image_p = imagecreatetruecolor($width, $height);
 $image = imagecreatefromjpeg($konyvtar . '/' . $fajlnev_n);
 if ($degrees != "") {
     // Create a square image the size of the largest side of our src image
     $kulonb = ($width_orig - $height_orig) / 2;
     $tmp = imageCreateTrueColor($width_orig, $width_orig);
     // Exchange sides
     $image_p = imageCreateTrueColor($height, $width);
     // Now copy our src image to tmp where we will rotate and then copy that to $out
     imageCopy($tmp, $image, 0, $kulonb, 0, 0, $width_orig, $height_orig);
     $tmp2 = imageRotate($tmp, $degrees, 0);
     // Now copy tmp2 to $out;
     #majd kicsinyíteni a kívánt méretre
     imagecopyresampled($image_p, $tmp2, 0, 0, $kulonb, 0, $width, $height + 200, $width_orig, $width_orig);
 } else {
     imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
 }
 # Output
 imagejpeg($image_p, $konyvtar . '/' . $fajlnev_n);
 imagedestroy($image_p);
 #a képek adatainak rögzítése az adatbázisba
 if ($nincsfajl != 1) {
     $sql2 = "INSERT INTO " . $_SESSION[adatbazis_etag] . "_galeriakepek (sorszam, fajlnev_nagy, felirat_hu, csoport, kepszam) values ('{$num_rows}', '{$fajlnev_n}', '{$_REQUEST['felirat_hu']}', '{$_REQUEST['csoport']}', '{$num_rowkeps}')";
     mysql_query($sql2);
 }
Example #12
0
 function applyWatermark($options = array('image_to_modify' => null, 'watermark_image' => null))
 {
     $watermark = imageCreateFromPNG($options['watermark_image']);
     $watermark_width = imagesx($watermark);
     $watermark_height = imagesy($watermark);
     $image = imageCreateTrueColor($watermark_width, $watermark_height);
     $image = imageCreateFromJPEG($options['image_to_modify']);
     $size = getImageSize($options['image_to_modify']);
     $dest_x = $size[0] - $watermark_width - 5;
     $dest_y = $size[1] - $watermark_height - 5;
     imageCopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
     if (imageJPEG($image, $options['image_to_modify'], $quality = 100)) {
         // TODO REFACTOR: To work for gif and png from trent's code
         imageDestroy($image);
         imageDestroy($watermark);
         return true;
     } else {
         imageDestroy($image);
         imageDestroy($watermark);
         return false;
     }
 }
 /**
  * Merge two image var
  *
  * @param resource $destinationImage
  * @param resource $sourceImage
  * @param integer $destinationPosX
  * @param integer $destinationPosY
  * @param integer $sourcePosX
  * @param integer $sourcePosY
  */
 public static function mergeTwoImages(&$destinationImage, $sourceImage, $destinationPosX = 0, $destinationPosY = 0, $sourcePosX = 0, $sourcePosY = 0)
 {
     imageCopy($destinationImage, $sourceImage, $destinationPosX, $destinationPosY, $sourcePosX, $sourcePosY, imageSX($sourceImage), imageSY($sourceImage));
 }
Example #14
0
 function Watermark_GD()
 {
     if (function_exists('imagecopy') && function_exists('imagealphablending') && function_exists('imagecopymerge')) {
         $imagecreatefromfunc = $this->imagecreatefromfunc;
         $imagefunc = $this->imagefunc;
         list($img_w, $img_h) = $this->attachinfo;
         if ($this->watermarktype < 2) {
             //非文本
             $watermark_file = HDWIKI_ROOT . './style/default/watermark/logo.' . ($this->watermarktype == 1 ? 'png' : 'gif');
             $watermarkinfo = @getimagesize($watermark_file);
             $watermark_logo = $this->watermarktype == 1 ? @imageCreateFromPNG($watermark_file) : @imageCreateFromGIF($watermark_file);
             if (!$watermark_logo) {
                 return;
             }
             list($logo_w, $logo_h) = $watermarkinfo;
         } else {
             //水印是文本类型
             $watermarktextcvt = $this->watermarktext['text'];
             $box = imagettfbbox($this->watermarktext['size'], $this->watermarktext['angle'], $this->watermarktext['fontpath'], $watermarktextcvt);
             $logo_h = max($box[1], $box[3]) - min($box[5], $box[7]);
             $logo_w = max($box[2], $box[4]) - min($box[0], $box[6]);
             $ax = min($box[0], $box[6]) * -1;
             $ay = min($box[5], $box[7]) * -1;
         }
         $wmwidth = $img_w - $logo_w;
         $wmheight = $img_h - $logo_h;
         if (($this->watermarktype < 2 && is_readable($watermark_file) || $this->watermarktype == 2) && $wmwidth > 10 && $wmheight > 10 && !$this->animatedgif) {
             switch ($this->watermarkstatus) {
                 case 1:
                     $x = +5;
                     $y = +5;
                     break;
                 case 2:
                     $x = ($img_w - $logo_w) / 2;
                     $y = +5;
                     break;
                 case 3:
                     $x = $img_w - $logo_w - 5;
                     $y = +5;
                     break;
                 case 4:
                     $x = +5;
                     $y = ($img_h - $logo_h) / 2;
                     break;
                 case 5:
                     $x = ($img_w - $logo_w) / 2;
                     $y = ($img_h - $logo_h) / 2;
                     break;
                 case 6:
                     $x = $img_w - $logo_w - 5;
                     $y = ($img_h - $logo_h) / 2;
                     break;
                 case 7:
                     $x = +5;
                     $y = $img_h - $logo_h - 5;
                     break;
                 case 8:
                     $x = ($img_w - $logo_w) / 2;
                     $y = $img_h - $logo_h - 5;
                     break;
                 case 9:
                     $x = $img_w - $logo_w - 5;
                     $y = $img_h - $logo_h - 5;
                     break;
             }
             $dst_photo = imagecreatetruecolor($img_w, $img_h);
             $target_photo = @$imagecreatefromfunc($this->srcfile);
             imageCopy($dst_photo, $target_photo, 0, 0, 0, 0, $img_w, $img_h);
             if ($this->watermarktype == 1) {
                 imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);
             } elseif ($this->watermarktype == 2) {
                 if (($this->watermarktext['shadowx'] || $this->watermarktext['shadowy']) && $this->watermarktext['shadowcolor']) {
                     $shadowcolorrgb = $this->excolor($this->watermarktext['shadowcolor']);
                     $shadowcolor = imagecolorallocate($dst_photo, $shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]);
                     imagettftext($dst_photo, $this->watermarktext['size'], $this->watermarktext['angle'], $x + $ax + $this->watermarktext['shadowx'], $y + $ay + $this->watermarktext['shadowy'], $shadowcolor, $this->watermarktext['fontpath'], $watermarktextcvt);
                 }
                 $colorrgb = $this->excolor($this->watermarktext['color']);
                 $color = imagecolorallocate($dst_photo, $colorrgb[0], $colorrgb[1], $colorrgb[2]);
                 imagettftext($dst_photo, $this->watermarktext['size'], $this->watermarktext['angle'], $x + $ax, $y + $ay, $color, $this->watermarktext['fontpath'], $watermarktextcvt);
             } else {
                 imageAlphaBlending($watermark_logo, true);
                 imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $this->watermarktrans);
             }
             if ($this->attachinfo['mime'] == 'image/jpeg') {
                 $imagefunc($dst_photo, $this->targetfile, $this->watermarkquality);
             } else {
                 $imagefunc($dst_photo, $this->targetfile);
             }
         } else {
             return false;
         }
     }
     return true;
 }
function drawPlayer($number, $name)
{
    $font = "font/tahomab.ttf";
    $fontb = "font/tahomab.ttf";
    $player = imagecreatetruecolor(46, 46);
    // пустое изображение, нужно для прозрачности
    $transparent = imagecolorallocatealpha($player, 0, 0, 0, 127);
    // устанавливаем прозрачный цвет
    imagefill($player, 0, 0, $transparent);
    // заполняем им контейнер
    imageSaveAlpha($player, true);
    // сохраняем прозрачность
    imageAlphaBlending($player, true);
    // делаем так, чтобы все что копировалось в контейнер, копировалось вместе с настройками прозрачности
    $src1 = imagecreatefrompng("img/tshirt.png");
    // И копируем нашу форму, в которой этой прозрачности завались
    imageCopy($player, $src1, 0, 0, 0, 0, 46, 46);
    //копируем картинку с формой в пустую картинку (куда копируем, что копируем, координатаХ бокса, координатаY бокса, координата Х картинки, координата Y картинки, ширина картинки, высота картинки)
    $white = imagecolorallocate($player, 255, 255, 255);
    // определяем цвет текста - белый
    $black = imagecolorallocate($player, 0, 0, 0);
    // определяем цвет текста - черный
    imageAlphaBlending($player, true);
    // А теперь делаем так, чтобы то что будет нарисовано позднее (наложен текст), брало имеющиеся настройки прозрачности.
    $nbox = imagettfbbox(10, 0, $fontb, $number);
    // определяем размер бокса под номер
    $nwidth = $nbox[2] - $nbox[0];
    // ширина бокса
    $nposition = round(46 / 2 - $nwidth / 2);
    imagettftext($player, 10, 0, $nposition, 30, $white, $fontb, $number);
    // накладываем номер
    $bbox = imagettfbbox(10, 0, $font, $name);
    // определяем размер бокса под фамилию
    $width = $bbox[2] - $bbox[0];
    // ширина бокса
    $height = $bbox[1] - $bbox[7];
    // высота бокса
    $height += 50;
    // добавляем 50 пикселей для пиктограммы формы
    if ($width < 46) {
        $textPosition = round(46 / 2 - $width / 2);
        $width = 46;
    } else {
        $textPosition = 0;
    }
    // если ширина бокса для текста меньше ширины формы - обрезать не будем. А текст немного сместим.
    $box = imagecreatetruecolor($width, $height);
    // создаем контейнер под всё
    imagefill($box, 0, 0, $transparent);
    // заполняем прозрачностью
    imageSaveAlpha($box, true);
    // созраняем
    imageAlphaBlending($box, false);
    // копировать сюда будем вместе с настройками
    $x = round($width / 2 - 46 / 2);
    // позиционируем картинку с формой посередине
    imageCopy($box, $player, $x, 0, 0, 0, 46, 46);
    //копируем картинку с формой в пустой бокс
    //imageAlphaBlending($box, true); //вертаем настройки прозрачности
    imagettftext($box, 10, 0, $textPosition, $height - 3, $white, $font, $name);
    // накладываем имя-фамилию
    return $box;
    //возвращаем картинку
}
 function applyWatermark($options = array('image_to_modify' => null, 'watermark_image' => null))
 {
     $watermark = $this->openImage($options['watermark_image']);
     //imageCreateFromPNG($options['watermark_image']);
     $watermark_width = imagesx($watermark);
     $watermark_height = imagesy($watermark);
     $image = imageCreateTrueColor($watermark_width, $watermark_height);
     $image = $this->openImage($options['image_to_modify']);
     //imageCreateFromJPEG($options['image_to_modify']);
     $size = getImageSize($options['image_to_modify']);
     $dest_x = $size[0] - $watermark_width - 5;
     $dest_y = $size[1] - $watermark_height - 5;
     imageCopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
     if ($this->saveImage($image, $options['image_to_modify'])) {
         imageDestroy($image);
         imageDestroy($watermark);
         return true;
     } else {
         imageDestroy($image);
         imageDestroy($watermark);
         return false;
     }
 }
Example #17
0
 function Watermark_GD($preview = 0)
 {
     global $watermarkstatus, $watermarktype, $watermarktrans, $watermarkquality, $watermarktext;
     $watermarkstatus = $GLOBALS['forum']['disablewatermark'] ? 0 : $watermarkstatus;
     if ($watermarkstatus && function_exists('imagecopy') && function_exists('imagealphablending') && function_exists('imagecopymerge')) {
         $imagecreatefromfunc = $this->imagecreatefromfunc;
         $imagefunc = $this->imagefunc;
         list($img_w, $img_h) = $this->attachinfo;
         if ($watermarktype < 2) {
             $watermark_file = $watermarktype == 1 ? './images/common/watermark.png' : './images/common/watermark.gif';
             $watermarkinfo = @getimagesize($watermark_file);
             $watermark_logo = $watermarktype == 1 ? @imageCreateFromPNG($watermark_file) : @imageCreateFromGIF($watermark_file);
             if (!$watermark_logo) {
                 return;
             }
             list($logo_w, $logo_h) = $watermarkinfo;
         } else {
             $watermarktextcvt = pack("H*", $watermarktext['text']);
             $box = imagettfbbox($watermarktext['size'], $watermarktext['angle'], $watermarktext['fontpath'], $watermarktextcvt);
             $logo_h = max($box[1], $box[3]) - min($box[5], $box[7]);
             $logo_w = max($box[2], $box[4]) - min($box[0], $box[6]);
             $ax = min($box[0], $box[6]) * -1;
             $ay = min($box[5], $box[7]) * -1;
         }
         $wmwidth = $img_w - $logo_w;
         $wmheight = $img_h - $logo_h;
         if (($watermarktype < 2 && is_readable($watermark_file) || $watermarktype == 2) && $wmwidth > 10 && $wmheight > 10 && !$this->animatedgif) {
             switch ($watermarkstatus) {
                 case 1:
                     $x = +5;
                     $y = +5;
                     break;
                 case 2:
                     $x = ($img_w - $logo_w) / 2;
                     $y = +5;
                     break;
                 case 3:
                     $x = $img_w - $logo_w - 5;
                     $y = +5;
                     break;
                 case 4:
                     $x = +5;
                     $y = ($img_h - $logo_h) / 2;
                     break;
                 case 5:
                     $x = ($img_w - $logo_w) / 2;
                     $y = ($img_h - $logo_h) / 2;
                     break;
                 case 6:
                     $x = $img_w - $logo_w;
                     $y = ($img_h - $logo_h) / 2;
                     break;
                 case 7:
                     $x = +5;
                     $y = $img_h - $logo_h - 5;
                     break;
                 case 8:
                     $x = ($img_w - $logo_w) / 2;
                     $y = $img_h - $logo_h - 5;
                     break;
                 case 9:
                     $x = $img_w - $logo_w - 5;
                     $y = $img_h - $logo_h - 5;
                     break;
             }
             $dst_photo = imagecreatetruecolor($img_w, $img_h);
             $target_photo = @$imagecreatefromfunc($this->targetfile);
             imageCopy($dst_photo, $target_photo, 0, 0, 0, 0, $img_w, $img_h);
             if ($watermarktype == 1) {
                 imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);
             } elseif ($watermarktype == 2) {
                 if (($watermarktext['shadowx'] || $watermarktext['shadowy']) && $watermarktext['shadowcolor']) {
                     $shadowcolorrgb = explode(',', $watermarktext['shadowcolor']);
                     $shadowcolor = imagecolorallocate($dst_photo, $shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]);
                     imagettftext($dst_photo, $watermarktext['size'], $watermarktext['angle'], $x + $ax + $watermarktext['shadowx'], $y + $ay + $watermarktext['shadowy'], $shadowcolor, $watermarktext['fontpath'], $watermarktextcvt);
                 }
                 $colorrgb = explode(',', $watermarktext['color']);
                 $color = imagecolorallocate($dst_photo, $colorrgb[0], $colorrgb[1], $colorrgb[2]);
                 imagettftext($dst_photo, $watermarktext['size'], $watermarktext['angle'], $x + $ax, $y + $ay, $color, $watermarktext['fontpath'], $watermarktextcvt);
             } else {
                 imageAlphaBlending($watermark_logo, true);
                 imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
             }
             $targetfile = !$preview ? $this->targetfile : DISCUZ_ROOT . './forumdata/watermark_temp.jpg';
             clearstatcache();
             if ($this->attachinfo['mime'] == 'image/jpeg') {
                 $imagefunc($dst_photo, $targetfile, $watermarkquality);
             } else {
                 $imagefunc($dst_photo, $targetfile);
             }
             $this->attach['size'] = filesize($targetfile);
         }
     }
 }
 /**
  * Copy the overlay on top
  */
 protected function copyOverlay()
 {
     if ($this->overlay) {
         imageCopy($this->avatar, $this->overlay, 0, 0, 0, 0, imageSX($this->overlay), imageSY($this->overlay));
     }
 }
Example #19
0
 /**
  * copies an image canvas
  *
  * @param image $imgCanvas source canvas
  * @param image $img destination canvas
  * @param int $dest_x destination x
  * @param int $dest_y destination y
  * @param int $src_x source x
  * @param int $src_y source y
  * @param int $w width
  * @param int $h height
  */
 function zp_copyCanvas($imgCanvas, $img, $dest_x, $dest_y, $src_x, $src_y, $w, $h)
 {
     return imageCopy($imgCanvas, $img, $dest_x, $dest_y, $src_x, $src_y, $w, $h);
 }
 /**
  * Appends information about the source image to the thumbnail.
  * 
  * @param	string		$thumbnail
  * @return	string
  */
 protected function appendSourceInfo($thumbnail)
 {
     if (!function_exists('imageCreateFromString') || !function_exists('imageCreateTrueColor')) {
         return $thumbnail;
     }
     $imageSrc = imageCreateFromString($thumbnail);
     // get image size
     $width = imageSX($imageSrc);
     $height = imageSY($imageSrc);
     // increase height
     $heightDst = $height + self::$sourceInfoLineHeight * 2;
     // create new image
     $imageDst = imageCreateTrueColor($width, $heightDst);
     imageAlphaBlending($imageDst, false);
     // set background color
     $background = imageColorAllocate($imageDst, 102, 102, 102);
     imageFill($imageDst, 0, 0, $background);
     // copy image
     imageCopy($imageDst, $imageSrc, 0, 0, 0, 0, $width, $height);
     imageSaveAlpha($imageDst, true);
     // get font size
     $font = 2;
     $fontWidth = imageFontWidth($font);
     $fontHeight = imageFontHeight($font);
     $fontColor = imageColorAllocate($imageDst, 255, 255, 255);
     // write source info
     $line1 = $this->sourceName;
     // imageString supports only ISO-8859-1 encoded strings
     if (CHARSET != 'ISO-8859-1') {
         $line1 = StringUtil::convertEncoding(CHARSET, 'ISO-8859-1', $line1);
     }
     // truncate text if necessary
     $maxChars = floor($width / $fontWidth);
     if (strlen($line1) > $maxChars) {
         $line1 = $this->truncateSourceName($line1, $maxChars);
     }
     $line2 = $this->sourceWidth . 'x' . $this->sourceHeight . ' ' . FileUtil::formatFilesize($this->sourceSize);
     // write line 1
     // calculate text position
     $textX = 0;
     $textY = 0;
     if ($fontHeight < self::$sourceInfoLineHeight) {
         $textY = intval(round((self::$sourceInfoLineHeight - $fontHeight) / 2));
     }
     if (strlen($line1) * $fontWidth < $width) {
         $textX = intval(round(($width - strlen($line1) * $fontWidth) / 2));
     }
     imageString($imageDst, $font, $textX, $height + $textY, $line1, $fontColor);
     // write line 2
     // calculate text position
     $textX = 0;
     $textY = 0;
     if ($fontHeight < self::$sourceInfoLineHeight) {
         $textY = self::$sourceInfoLineHeight + intval(round((self::$sourceInfoLineHeight - $fontHeight) / 2));
     }
     if (strlen($line2) * $fontWidth < $width) {
         $textX = intval(round(($width - strlen($line2) * $fontWidth) / 2));
     }
     imageString($imageDst, $font, $textX, $height + $textY, $line2, $fontColor);
     // output image
     ob_start();
     if ($this->imageType == 1 && function_exists('imageGIF')) {
         @imageGIF($imageDst);
         $this->mimeType = 'image/gif';
     } else {
         if (($this->imageType == 1 || $this->imageType == 3) && function_exists('imagePNG')) {
             @imagePNG($imageDst);
             $this->mimeType = 'image/png';
         } else {
             if (function_exists('imageJPEG')) {
                 @imageJPEG($imageDst, null, 90);
                 $this->mimeType = 'image/jpeg';
             } else {
                 return false;
             }
         }
     }
     @imageDestroy($imageDst);
     $thumbnail = ob_get_contents();
     ob_end_clean();
     return $thumbnail;
 }
Example #21
0
<?php

$renderthis = imageCreateFromPNG('icon_forumunread.png');
if (isset($_GET['number']) && $_GET['number'] != '') {
    $numberpositions = array(0, 6, 10, 16, 22, 28, 34, 40, 46, 52);
    $numbersizes = array(6, 4, 6, 6, 6, 6, 6, 6, 6, 6);
    $numbers = imageCreateFromPNG('numbers.png');
    $getit = strval(intval($_GET['number']));
    $renderx = 19;
    for ($idx = strlen($getit) - 1; $idx >= 0; $idx--) {
        $thisone = intval($getit[$idx]);
        $renderx -= $numbersizes[$thisone] - 1;
        imageCopy($renderthis, $numbers, $renderx, 11, $numberpositions[$thisone], 0, $numbersizes[$thisone], 9);
    }
    imageDestroy($numbers);
}
header('Content-type: image/png');
imagePNG($renderthis);
imageDestroy($renderthis);
 /**
  * Crop the image
  *
  * @param Asido_TMP &$tmp
  * @param integer $x
  * @param integer $y
  * @param integer $width
  * @param integer $height
  * @return boolean
  * @access protected
  */
 function __crop(&$tmp, $x, $y, $width, $height)
 {
     $t = imageCreateTrueColor($width, $height);
     imageAlphaBlending($t, true);
     $transparent = imagecolortransparent($t, imagecolorallocatealpha($t, 0, 0, 0, 127));
     imagefill($t, 0, 0, $transparent);
     imagesavealpha($t, true);
     $r = imageCopy($t, $tmp->target, 0, 0, $x, $y, $width, $height);
     imageAlphaBlending($t, false);
     $this->__destroy_target($tmp);
     $tmp->target = $t;
     $tmp->image_width = $width;
     $tmp->image_height = $height;
     return $r;
 }
Example #23
0
 /**
  * 头像生成接口
  * @return array  头像地址
  */
 public function uploadImage()
 {
     if (!$this->input['user_id']) {
         $userinfo = $this->mUser->verify_credentials();
     } else {
         $userinfo['id'] = intval($this->input['user_id']);
     }
     if (!$userinfo['id']) {
         $this->errorOutput(USENAME_NOLOGIN);
     }
     $files = $_FILES['files'];
     include_once ROOT_DIR . 'lib/class/gdimage.php';
     //源文件
     $uploadedfile = $files['tmp_name'];
     //源文件类型
     $tmp = explode('.', $uploadedfile);
     $file_type = $tmp[1];
     //文件名
     $file_name = $userinfo['id'] . ".jpg";
     //目录
     $file_dir = AVATAR_DIR . ceil($userinfo['id'] / NUM_IMG) . "/";
     //文件路径
     $file_path = $file_dir . $file_name;
     $size = array("larger" => array(LARGER_IMG_WIDTH, LARGER_IMG_HEIGHT), "middle" => array(MIDDLE_IMG_WIDTH, MIDDLE_IMG_HEIGHT), "small" => array(SMALL_IMG_WIDTH, SMALL_IMG_HEIGHT));
     if (!hg_mkdir($file_dir)) {
         $this->errorOutput(UPLOAD_ERR_NO_FILE);
     }
     if (!move_uploaded_file($uploadedfile, $file_path)) {
         $this->errorOutput(UPLOAD_ERR_NO_FILE);
     }
     //如果传递了裁剪信息
     if ($this->input['cut_info']) {
         $cut_info = urldecode($this->input['cut_info']);
         $info = explode(',', $cut_info);
         //裁剪的起点坐标
         $src_x = $info[0];
         $src_y = $info[1];
         //裁剪图片的大小
         $src_w = $info[2];
         $src_h = $info[3];
         $src_img = imagecreatefromjpeg($file_path);
         $dst_img = imageCreateTrueColor($src_w, $src_h);
         imageCopy($dst_img, $src_img, 0, 0, $src_x, $src_y, $src_w, $src_h);
         imageJPEG($dst_img, $file_path, 100);
     }
     $img = new GDImage($file_path, $file_path, '');
     $info = array();
     foreach ($size as $key => $value) {
         $save_file_path = $file_dir . $key . '_' . $file_name;
         $img->init_setting($file_path, $save_file_path, '');
         $img->maxWidth = $value[0];
         $img->maxHeight = $value[1];
         $img->makeThumb(3, false);
         $info[$key] = AVATAR_URL . ceil($userinfo['id'] / NUM_IMG) . "/" . $key . '_' . $file_name . "?" . hg_rand_num(7);
     }
     $info['ori'] = AVATAR_URL . ceil($userinfo['id'] / NUM_IMG) . "/" . $file_name . "?" . hg_rand_num(7);
     $sql = "UPDATE " . DB_PREFIX . "member \r\n\t\tSET avatar = '" . $userinfo['id'] . ".jpg' \r\n\t\tWHERE id=" . $userinfo['id'];
     $this->db->query($sql);
     $info['id'] = $userinfo['id'];
     $this->setXmlNode('img', 'imagefile');
     $this->addItem($info);
     return $this->output();
 }
Example #24
0
 function copyTo($dest, $left = 0, $top = 0)
 {
     imageCopy($dest->getHandle(), $this->handle, $left, $top, 0, 0, $this->getWidth(), $this->getHeight());
 }
Example #25
0
 public static function water($source_file, $target_file, $water, $pos = 0, $pct = 30, $quality = 80)
 {
     $ispng = false;
     // 加载水印图片
     $info = self::getImageInfo($water);
     if (!empty($info[0])) {
         $water_w = $info[0];
         $water_h = $info[1];
         $type = $info['type'];
         $fun = 'imagecreatefrom' . $type;
         $waterimg = $fun($water);
         if ($type == 'png') {
             $ispng = true;
         }
     } else {
         return false;
     }
     // 加载背景图片
     $info = self::getImageInfo($source_file);
     if (!empty($info[0])) {
         $old_w = $info[0];
         $old_h = $info[1];
         $type = $info['type'];
         $fun = 'imagecreatefrom' . $type;
         $source_file = $fun($source_file);
     } else {
         return false;
     }
     // 剪切水印
     $water_w > $old_w && ($water_w = $old_w);
     $water_h > $old_h && ($water_h = $old_h);
     // 水印位置
     switch ($pos) {
         case 0:
             //随机
             $posX = rand(0, $old_w - $water_w);
             $posY = rand(0, $old_h - $water_h);
             break;
         case 1:
             //1为顶端居左
             $posX = 0;
             $posY = 0;
             break;
         case 2:
             //2为顶端居中
             $posX = ($old_w - $water_w) / 2;
             $posY = 0;
             break;
         case 3:
             //3为顶端居右
             $posX = $old_w - $water_w;
             $posY = 0;
             break;
         case 4:
             //4为中部居左
             $posX = 0;
             $posY = ($old_h - $water_h) / 2;
             break;
         case 5:
             //5为中部居中
             $posX = ($old_w - $water_w) / 2;
             $posY = ($old_h - $water_h) / 2;
             break;
         case 6:
             //6为中部居右
             $posX = $old_w - $water_w;
             $posY = ($old_h - $water_h) / 2;
             break;
         case 7:
             //7为底端居左
             $posX = 0;
             $posY = $old_h - $water_h;
             break;
         case 8:
             //8为底端居中
             $posX = ($old_w - $water_w) / 2;
             $posY = $old_h - $water_h;
             break;
         case 9:
             //9为底端居右
             $posX = $old_w - $water_w;
             $posY = $old_h - $water_h;
             break;
         default:
             //随机
             $posX = rand(0, $old_w - $water_w);
             $posY = rand(0, $old_h - $water_h);
             break;
     }
     if ($ispng) {
         $watermark_photo = imagecreatetruecolor($old_w, $old_h);
         imageCopy($watermark_photo, $source_file, 0, 0, 0, 0, $old_w, $old_h);
         imageCopy($watermark_photo, $waterimg, $posX, $posY, 0, 0, $water_w, $water_h);
         $source_file = $watermark_photo;
     } else {
         // 设定图像的混色模式
         imagealphablending($source_file, true);
         // 添加水印
         imagecopymerge($source_file, $waterimg, $posX, $posY, 0, 0, $water_w, $water_h, $pct);
     }
     $fun = 'image' . $type;
     if ($fun == 'imagejpeg') {
         imagejpeg($source_file, $target_file, $quality);
     } else {
         $fun($source_file, $target_file);
     }
     imagedestroy($source_file);
     imagedestroy($waterimg);
     if (!file_exists($target_file)) {
         return '';
     }
     return $target_file;
 }
Example #26
0
 /**
  * Crop the image 
  *
  * @param Asido_TMP &$tmp
  * @param integer $x
  * @param integer $y
  * @param integer $width
  * @param integer $height
  * @return boolean
  * @access protected
  */
 function __crop(&$tmp, $x, $y, $width, $height)
 {
     $t = imageCreateTrueColor($width, $height);
     imageAlphaBlending($t, true);
     $r = imageCopy($t, $tmp->target, 0, 0, $x, $y, $width, $height);
     imageAlphaBlending($t, false);
     $this->__destroy_target($tmp);
     $tmp->target = $t;
     $tmp->image_width = $width;
     $tmp->image_height = $height;
     return $r;
 }
Example #27
0
 /**
  * (non-PHPdoc)
  * @see WideImage_Image#asTrueColor()
  */
 function asTrueColor()
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $new = WideImage::createTrueColorImage($width, $height);
     if ($this->isTransparent()) {
         $new->copyTransparencyFrom($this);
     }
     if (!imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height)) {
         throw new WideImage_GDFunctionResultException("imagecopy() returned false");
     }
     return $new;
 }
Example #28
0
 function makeThumbWatermark($width = 128, $height = 128)
 {
     $this->fileCheck();
     $image_info = $this->getInfo($this->src_image_name);
     if (!$image_info) {
         return false;
     }
     $src_image_type = $image_info["type"];
     $img = $this->createImage($src_image_type, $this->src_image_name);
     if (!$img) {
         return false;
     }
     $width = $width == 0 ? $image_info["width"] : $width;
     $height = $height == 0 ? $image_info["height"] : $height;
     $width = $width > $image_info["width"] ? $image_info["width"] : $width;
     $height = $height > $image_info["height"] ? $image_info["height"] : $height;
     $srcW = $image_info["width"];
     $srcH = $image_info["height"];
     if ($srcH * $width > $srcW * $height) {
         $width = round($srcW * $height / $srcH);
     } else {
         $height = round($srcH * $width / $srcW);
     }
     //*
     $src_image = @imagecreatetruecolor($width, $height);
     $white = @imagecolorallocate($src_image, 0xff, 0xff, 0xff);
     @imagecolortransparent($src_image, $white);
     @imagefilltoborder($src_image, 0, 0, $white, $white);
     if ($src_image) {
         ImageCopyResampled($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     } else {
         $src_image = imagecreate($width, $height);
         ImageCopyResized($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     }
     $src_image_w = ImageSX($src_image);
     $src_image_h = ImageSY($src_image);
     if ($this->wm_image_name) {
         $wm_image_info = $this->getInfo($this->wm_image_name);
         if (!$wm_image_info) {
             return false;
         }
         $wm_image_type = $wm_image_info["type"];
         $wm_image = $this->createImage($wm_image_type, $this->wm_image_name);
         $wm_image_w = ImageSX($wm_image);
         $wm_image_h = ImageSY($wm_image);
         $temp_wm_image = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos, $wm_image);
         if ($this->emboss && function_exists("imagefilter")) {
             imagefilter($wm_image, IMG_FILTER_EMBOSS);
             $bgcolor = imagecolorclosest($wm_image, 0x7f, 0x7f, 0x7f);
             imagecolortransparent($wm_image, $bgcolor);
         }
         if (function_exists("ImageAlphaBlending") && IMAGETYPE_PNG == $wm_image_info['type']) {
             ImageAlphaBlending($src_image, true);
         }
         $wm_image_x = $temp_wm_image["dest_x"];
         $wm_image_y = $temp_wm_image["dest_y"];
         if (IMAGETYPE_PNG == $wm_image_info['type']) {
             imageCopy($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h);
         } else {
             imageCopyMerge($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h, $this->wm_image_transition);
         }
     }
     if ($this->wm_text) {
         $this->wm_text = $this->wm_text;
         $temp_wm_text = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos);
         $wm_text_x = $temp_wm_text["dest_x"];
         $wm_text_y = $temp_wm_text["dest_y"];
         if (preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->wm_text_color, $color)) {
             $red = hexdec($color[1]);
             $green = hexdec($color[2]);
             $blue = hexdec($color[3]);
             $wm_text_color = imagecolorallocate($src_image, $red, $green, $blue);
         } else {
             $wm_text_color = imagecolorallocate($src_image, 255, 255, 255);
         }
         imagettftext($src_image, $this->wm_text_size, $this->wm_angle, $wm_text_x, $wm_text_y, $wm_text_color, $this->wm_text_font, $this->wm_text);
     }
     if ($this->save_file) {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     $src_img = ImageGIF($src_image, $this->save_file);
                 } else {
                     $src_img = ImagePNG($src_image, $this->save_file);
                 }
                 break;
             case 2:
                 $src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
                 break;
             case 3:
                 $src_img = ImagePNG($src_image, $this->save_file);
                 break;
             default:
                 $src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
                 break;
         }
     } else {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     header("Content-type: image/gif");
                     $src_img = ImageGIF($src_image);
                 } else {
                     header("Content-type: image/png");
                     $src_img = ImagePNG($src_image);
                 }
                 break;
             case 2:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($src_image, "", $this->jpeg_quality);
                 break;
             case 3:
                 header("Content-type: image/png");
                 $src_img = ImagePNG($src_image);
                 break;
             case 6:
                 header("Content-type: image/bmp");
                 $src_img = imagebmp($src_image);
                 break;
             default:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($src_image, "", $this->jpeg_quality);
                 break;
         }
     }
     imagedestroy($src_image);
     imagedestroy($img);
     return true;
 }
Example #29
0
 function Watermark_GD($type = 'forum')
 {
     if (!function_exists('imagecreatetruecolor')) {
         return -4;
     }
     $imagefunc =& $this->imagefunc;
     if ($this->param['watermarktype'][$type] != 'text') {
         if (!function_exists('imagecopy') || !function_exists('imagecreatefrompng') || !function_exists('imagecreatefromgif') || !function_exists('imagealphablending') || !function_exists('imagecopymerge')) {
             return -4;
         }
         $watermarkinfo = @getimagesize($this->param['watermarkfile'][$type]);
         if ($watermarkinfo === FALSE) {
             return -3;
         }
         $watermark_logo = $this->param['watermarktype'][$type] == 'png' ? @imageCreateFromPNG($this->param['watermarkfile'][$type]) : @imageCreateFromGIF($this->param['watermarkfile'][$type]);
         if (!$watermark_logo) {
             return 0;
         }
         list($logo_w, $logo_h) = $watermarkinfo;
     } else {
         if (!function_exists('imagettfbbox') || !function_exists('imagettftext') || !function_exists('imagecolorallocate')) {
             return -4;
         }
         if (!class_exists('Chinese')) {
             include libfile('class/chinese');
         }
         $watermarktextcvt = pack("H*", $this->param['watermarktext']['text'][$type]);
         $box = imagettfbbox($this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);
         $logo_h = max($box[1], $box[3]) - min($box[5], $box[7]);
         $logo_w = max($box[2], $box[4]) - min($box[0], $box[6]);
         $ax = min($box[0], $box[6]) * -1;
         $ay = min($box[5], $box[7]) * -1;
     }
     $wmwidth = $this->imginfo['width'] - $logo_w;
     $wmheight = $this->imginfo['height'] - $logo_h;
     if ($wmwidth > 10 && $wmheight > 10 && !$this->imginfo['animated']) {
         switch ($this->param['watermarkstatus'][$type]) {
             case 1:
                 $x = 5;
                 $y = 5;
                 break;
             case 2:
                 $x = ($this->imginfo['width'] - $logo_w) / 2;
                 $y = 5;
                 break;
             case 3:
                 $x = $this->imginfo['width'] - $logo_w - 5;
                 $y = 5;
                 break;
             case 4:
                 $x = 5;
                 $y = ($this->imginfo['height'] - $logo_h) / 2;
                 break;
             case 5:
                 $x = ($this->imginfo['width'] - $logo_w) / 2;
                 $y = ($this->imginfo['height'] - $logo_h) / 2;
                 break;
             case 6:
                 $x = $this->imginfo['width'] - $logo_w;
                 $y = ($this->imginfo['height'] - $logo_h) / 2;
                 break;
             case 7:
                 $x = 5;
                 $y = $this->imginfo['height'] - $logo_h - 5;
                 break;
             case 8:
                 $x = ($this->imginfo['width'] - $logo_w) / 2;
                 $y = $this->imginfo['height'] - $logo_h - 5;
                 break;
             case 9:
                 $x = $this->imginfo['width'] - $logo_w - 5;
                 $y = $this->imginfo['height'] - $logo_h - 5;
                 break;
         }
         if ($this->imginfo['mime'] != 'image/png') {
             $color_photo = imagecreatetruecolor($this->imginfo['width'], $this->imginfo['height']);
         }
         $dst_photo = $this->loadsource();
         if ($dst_photo < 0) {
             return $dst_photo;
         }
         imagealphablending($dst_photo, true);
         imagesavealpha($dst_photo, true);
         if ($this->imginfo['mime'] != 'image/png') {
             imageCopy($color_photo, $dst_photo, 0, 0, 0, 0, $this->imginfo['width'], $this->imginfo['height']);
             $dst_photo = $color_photo;
         }
         if ($this->param['watermarktype'][$type] == 'png') {
             imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);
         } elseif ($this->param['watermarktype'][$type] == 'text') {
             if (($this->param['watermarktext']['shadowx'][$type] || $this->param['watermarktext']['shadowy'][$type]) && $this->param['watermarktext']['shadowcolor'][$type]) {
                 $shadowcolorrgb = explode(',', $this->param['watermarktext']['shadowcolor'][$type]);
                 $shadowcolor = imagecolorallocate($dst_photo, $shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]);
                 imagettftext($dst_photo, $this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $x + $ax + $this->param['watermarktext']['shadowx'][$type], $y + $ay + $this->param['watermarktext']['shadowy'][$type], $shadowcolor, $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);
             }
             $colorrgb = explode(',', $this->param['watermarktext']['color'][$type]);
             $color = imagecolorallocate($dst_photo, $colorrgb[0], $colorrgb[1], $colorrgb[2]);
             imagettftext($dst_photo, $this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $x + $ax, $y + $ay, $color, $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);
         } else {
             imageAlphaBlending($watermark_logo, true);
             imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $this->param['watermarktrans'][$type]);
         }
         clearstatcache();
         if ($this->imginfo['mime'] == 'image/jpeg') {
             @$imagefunc($dst_photo, $this->target, $this->param['watermarkquality'][$type]);
         } else {
             @$imagefunc($dst_photo, $this->target);
         }
     }
     return 1;
 }
 public function generate($name, $colorScheme, $backgroundStyle)
 {
     list($bgColor1, $bgColor2, $textColor) = self::$colorSchemes[$colorScheme];
     $this->avatar = imageCreateTrueColor($this->width, $this->height);
     imageFill($this->avatar, 0, 0, $bgColor1);
     // Draw some random chars into the background. Unlike the other GD drawing functions
     // (imageFilledArc, imageFilledPolygon etc.) imageTTFText is anti-aliased.
     $sizeFactor = $this->width / 40;
     switch ($backgroundStyle) {
         case 0:
             imageTTFText($this->avatar, 190 * $sizeFactor, 10, 0, 35 * $sizeFactor, $bgColor2, $this->fontFace, 'O');
             break;
         case 1:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, 'o');
             break;
         case 2:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 30 * $sizeFactor, $bgColor2, $this->fontFace, '>');
             break;
         case 3:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, '//');
             break;
     }
     // Draw the first few chars of the name
     imageTTFText($this->avatar, $this->fontSize, 0, 4, $this->height - $this->fontSize / 2, $textColor, $this->fontFace, mb_substr($name, 0, $this->chars));
     // Copy the overlay on top
     if ($this->overlay) {
         imageCopy($this->avatar, $this->overlay, 0, 0, 0, 0, imageSX($this->overlay), imageSY($this->overlay));
     }
 }