Exemple #1
0
 /**
  * Create Thumbnail Image
  *
  * Create a new image from video source based on the specified parameters. 
  * This method will allows video to convert to image.
  * This method will add watermark to image
  *
  *  
  * @access public
  * @since  Method available since Release 1.0.0
  * @param  video_path      Video resource source path 
  * @param  storage_path    Image resource destination path
  * @param  thumbnail_name  Image name for output
  * @param  height                                                  [optional]
  * @param  width                                                   [optional]
  * @param  tts             Time to take screenshot                 [optional]
  * @param  water_mark      Thmbnail paly button image              [optional]
  * @param  wm              if true the only it inserts play button [optional]
  * @author lakshmajim <*****@*****.**>
  * @return boolean 
  */
 public function getThumbnail($video_path, $storage_path, $thumnail_name, $height = 320, $width = 240, $tts = 50, $water_mark = '', $wm = false)
 {
     try {
         $ffmpeg = FFMpeg::create();
         $video = $ffmpeg->open($video_path);
         $result_image = $storage_path . '/' . $thumnail_name;
         $video->filters()->resize(new Coordinate\Dimension($height, $width))->synchronize();
         //320, 240
         $video->frame(Coordinate\TimeCode::fromSeconds($tts))->save($result_image);
         if ($video) {
             if ($wm) {
                 $src = imagecreatefrompng($water_mark);
                 $got_image = imagecreatefromjpeg($result_image);
                 // Get dimensions of image screen shot
                 $width = imagesx($got_image);
                 $height = imagesy($got_image);
                 // final output image dimensions
                 $newwidth = env('THUMBNAIL_IMAGE_WIDTH');
                 $newheight = env('THUMBNAIL_IMAGE_HEIGHT');
                 $tmp = imagecreatetruecolor($newwidth, $newheight);
                 imagecopyresampled($tmp, $got_image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                 // Set the brush
                 imagesetbrush($tmp, $src);
                 // Draw a couple of brushes, each overlaying each
                 imageline($tmp, imagesx($tmp) / 2, imagesy($tmp) / 2, imagesx($tmp) / 2, imagesy($tmp) / 2, IMG_COLOR_BRUSHED);
                 imagejpeg($tmp, $result_image, 100);
             }
             return true;
         } else {
             return false;
         }
     } catch (Exception $thumbnailException) {
         // error processing request
         echo "Got Bad Cookie";
     }
 }
			$y=$yend-($dataarray[$key][$i]-$minvalue2)*$ym2;
			
			$brush1="brush_".($k+3)."_1";
			$brush2="brush_".($k+3)."_2";
			if ($xp and $yp)
			{
			//	$tan=($y-$yp)/($x-$xp);
			//	if (abs($tan)>=1) 
					imagesetbrush($im,$$brush1);
			//	else 
			//		imagesetbrush($im,$$brush2);
				
				imageline($im,$xp,$yp,$x,$y,IMG_COLOR_BRUSHED);
				
			}
			imagesetbrush($im,$$brush1);
			imagefilledellipse ($im, $x, $y, 5, 5, IMG_COLOR_BRUSHED);
			$yp=$y;
			$xp=$x;
		}
	}
	//imagefilledellipse ($im, $xp, $yp, 6, 6, IMG_COLOR_BRUSHED);
	$l++;
}

//imagestring($im,1,$xmax-40,$ysize-12,date("d.m.y",$datearray[($datasize-1)]),$color[1]);
//imagestring($im,1,$xmin-2,$ysize-12,date("d.m.y",$datearray[0]),$color[1]);

imageline($im,$xmin,$ymax,$xmax,$ymax,$color[1]);
if ($showindex) 
	imageline($im,$xmin,$ymin,$xmin,$ymax,$color[1]);
Exemple #3
0
 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);
     }
 }
<?php

define("WIDTH", 450);
define("HEIGHT", 450);
define("B_WIDTH", 20);
define("B_HEIGHT", 20);
$img = imagecreate(WIDTH, HEIGHT);
$background = $white = imagecolorallocate($img, 0xff, 0xff, 0xff);
$black = imagecolorallocate($img, 0, 0, 0);
$brush = imagecreate(B_WIDTH, B_HEIGHT);
$b_bkgr = $b_white = imagecolorallocate($brush, 0xff, 0xff, 0xff);
$b_black = imagecolorallocate($brush, 0, 0, 0);
imagecolortransparent($brush, $b_bkgr);
imageellipse($brush, B_WIDTH / 2, B_HEIGHT / 2, B_WIDTH / 2, B_HEIGHT / 2, $black);
imagerectangle($img, 0, 0, WIDTH - 1, HEIGHT - 1, $black);
imagesetbrush($img, $brush);
$style_a = array_fill(0, B_WIDTH / 2, 0);
$style_a[] = 1;
imagesetstyle($img, $style_a);
imageline($img, 0, 50, WIDTH - 1, 50, IMG_COLOR_STYLEDBRUSHED);
$style_b = array_fill(0, B_WIDTH / 4, 0);
$style_b[] = 1;
imagesetstyle($img, $style_b);
imageline($img, 0, 100, WIDTH - 1, 100, IMG_COLOR_STYLEDBRUSHED);
$style_c = array_fill(0, B_WIDTH / 8, 0);
$style_c[] = 1;
imagesetstyle($img, $style_c);
imageline($img, 0, 150, WIDTH - 1, 150, IMG_COLOR_STYLEDBRUSHED);
header("Content-Type: image/png");
imagepng($img);
 function renderGeometry($pointArrayQuery, $geometry, $brush, $r, $b, $g)
 {
     $this->renderGeometryArray[] = array($this->convertpointarray($pointArrayQuery), $geometry, $brush, $r, $b, $g);
     global $render_im;
     $imgName = "render.png";
     if (!$render_im[$this->controlId]) {
         $render_im[$this->controlId] = imagecreate($this->width, $this->height);
     }
     $background_color = imagecolorallocate($render_im[$this->controlId], 255, 255, 255);
     $NewPointArray = explode("|", $pointArrayQuery);
     $line_color = imagecolorallocate($render_im[$this->controlId], 34, 255, 91);
     $brush_im = imagecreate($brush, $brush);
     $brush_color = imagecolorallocate($brush_im, $r, $b, $g);
     imageLine($brush_im, 8, 0, 8, 16, $brush_color);
     imageLine($brush_im, 0, 8, 16, 8, $brush_color);
     imagesetbrush($render_im[$this->controlId], $brush_im);
     $geometry = strtoupper($geometry);
     if ($geometry == "MULTIPOINT") {
         $geometry = "POINT";
     }
     if ($geometry == "MULTILINE" || $geometry == "MULTILINESTRING" || $geometry == "LINESTRING") {
         $geometry = "LINE";
     }
     if ($geometry == "MULTIPOLYGON") {
         $geometry = "LINE";
     }
     //echo "<script>alert('$geometry')</script>";
     switch ($geometry) {
         case "POINT":
             for ($i = 0; $i < sizeof($NewPointArray); $i++) {
                 $pixCoord = explode(",", $NewPointArray[$i]);
                 $marker_im = imagecreate(11, 11);
                 $background_color = imagecolorallocate($marker_im, 255, 255, 255);
                 $line_color = imagecolorallocate($marker_im, $r, $b, $g);
                 imageLine($marker_im, 5, 0, 5, 11, $line_color);
                 imageLine($marker_im, 0, 5, 11, 5, $line_color);
                 imagecopy($render_im[$this->controlId], $marker_im, $pixCoord[0] - 5, $pixCoord[1] - 5, 0, 0, 11, 11);
                 imagedestroy($marker_im);
             }
             break;
         case "LINE":
             //	echo "<script>alert('line')</script>";
             for ($i = 0; $i < sizeof($NewPointArray); $i++) {
                 for ($u = 0; $u < 2; $u++) {
                     $pixCoord[$u] = explode(",", $NewPointArray[$i + $u]);
                 }
                 if ($pixCoord[1][0]) {
                     imageLine($render_im[$this->controlId], $pixCoord[0][0], $pixCoord[0][1], $pixCoord[1][0], $pixCoord[1][1], IMG_COLOR_BRUSHED);
                 }
                 //		echo "<script>alert('".$pixCoord[1][0]."','".$pixCoord[1][1]."');</script>";
             }
             break;
         case "POLYGON":
             //echo "<script>alert('polygon')</script>";
             $pointArrayQuery = str_replace("|", ",", $pointArrayQuery);
             $array = explode(",", $pointArrayQuery);
             @imagepolygon($render_im[$this->controlId], $array, sizeof($NewPointArray), IMG_COLOR_BRUSHED);
             break;
     }
     //$test=imagepng($render_im[$this -> controlId], "render.png");
     //echo "<script>alert('render=$test')</script>";
     imagedestroy($brush_im);
 }
 function linie_grafic($im, $x1, $y1, $x2, $y2, $g, $culori, $gr, $pos)
 {
     if ($this->is_gradient($culori)) {
         $culori = $this->fa_stil($culori);
         $sir = $this->gradient_liniar($g, $culori);
         $gradient = $this->fa_culori_grade($im, $sir, $gr);
     }
     $ca = abs(abs($x2) - abs($x1));
     $cb = abs(abs($y2) - abs($y1));
     $ip = sqrt($ca * $ca + $cb * $cb);
     if ($ip == 0) {
         $ip = 1;
     }
     $sin = $cb / $ip;
     $cos = $ca / $ip;
     $c = imagecolorallocate($im, 255, 255, 0);
     if ($g < 4) {
         $gro = max($g, 1);
     } else {
         $gro = 2;
     }
     imagesetthickness($im, $gro);
     for ($i = 0; $i < $g; $i++) {
         if ($x1 < $x2) {
             $x3 = $x1 + $i * cos(acos($cos) - pi() / 2);
             $x4 = $x2 + $i * cos(acos($cos) - pi() / 2);
         } else {
             $x3 = $x1 + $i * cos(acos($cos) + pi() / 2);
             $x4 = $x2 + $i * cos(acos($cos) + pi() / 2);
         }
         if ($y1 > $y2) {
             $y3 = $y1 + $i * sin(asin($sin) + pi() / 2);
             $y4 = $y2 + $i * sin(asin($sin) + pi() / 2);
         } else {
             $y3 = abs($y1 + $g + $i * sin(asin($sin) - pi() / 2));
             $y4 = abs($y2 + $g + $i * sin(asin($sin) - pi() / 2));
         }
         $x5 = $g / 9.5 * $cos;
         $y5 = $g / 9.5 * $sin;
         if ($y1 > $y2) {
             $culo = min(sizeof($gradient) - 1, $i);
         } else {
             $culo = min(sizeof($gradient) - 1, $g - $i);
         }
         if (!$this->is_gradient($culori)) {
             if ($this->acolors[$pos][1] == 0) {
                 imageline($im, $x3 + $x5, $y3 + $g / 2 - $y5, $x4 - $x5, $y4 + $g / 2 + $y5, $this->acolors[$pos][0]);
             } elseif ($this->acolors[$pos][2] == 1) {
                 imageline($im, $x3 + $x5, $y3 + $g / 2 - $y5, $x4 - $x5, $y4 + $g / 2 + $y5, $gradient[$culo]);
             } else {
                 imagesetbrush($this->imagine, $this->acolors[$pos][0]);
                 imageline($im, $x3 + $x5, $y3 + $g / 2 - $y5, $x4 - $x5, $y4 + $g / 2 + $y5, IMG_COLOR_BRUSHED);
             }
         }
         if ($this->showshaddow && $g > 1) {
             $sx = $this->shaddow_x;
             $sy = $this->shaddow_y;
             imageline($im, $x3 + $sx + $x5, $y3 + $g / 2 + $sy - $y5, $x4 + $sx - $x5, $y4 + $g / 2 + $sy + $y5, $this->bc_alpha($this->imagine, "shaddow", $this->shaddow_alpha));
         }
     }
 }
Exemple #7
0
 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);
     }
 }
function noisecolor()
{
    global $img, $noisecolorchar, $ink, $bg, $brushsize;
    switch ($noisecolorchar) {
        case 1:
            $noisecol = $ink;
            break;
        case 2:
            $noisecol = $bg;
            break;
        case 3:
        default:
            $noisecol = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
            break;
    }
    if ($brushsize and $brushsize > 1 and function_exists('imagesetbrush')) {
        $brush = imagecreatetruecolor($brushsize, $brushsize);
        imagefill($brush, 0, 0, $noisecol);
        imagesetbrush($img, $brush);
        $noisecol = IMG_COLOR_BRUSHED;
    }
    return $noisecol;
}
 function drawPlotGraph($Data, $DataDescription, $BigRadius = 5, $SmallRadius = 2, $R2 = -1, $G2 = -1, $B2 = -1, $Shadow = FALSE)
 {
     /* Validate the Data and DataDescription array */
     $this->validateDataDescription("drawPlotGraph", $DataDescription);
     $this->validateData("drawPlotGraph", $Data);
     $GraphID = 0;
     $Ro = $R2;
     $Go = $G2;
     $Bo = $B2;
     foreach ($DataDescription["Values"] as $Key2 => $ColName) {
         $ID = 0;
         foreach ($DataDescription["Description"] as $keyI => $ValueI) {
             if ($keyI == $ColName) {
                 $ColorID = $ID;
             }
             $ID++;
         }
         $R = $this->Palette[$ColorID]["R"];
         $G = $this->Palette[$ColorID]["G"];
         $B = $this->Palette[$ColorID]["B"];
         $R2 = $Ro;
         $G2 = $Go;
         $B2 = $Bo;
         if (isset($DataDescription["Symbol"][$ColName])) {
             $Is_Alpha = (ord(file_get_contents($DataDescription["Symbol"][$ColName], false, null, 25, 1)) & 6 & 4) == 4;
             $Infos = getimagesize($DataDescription["Symbol"][$ColName]);
             $ImageWidth = $Infos[0];
             $ImageHeight = $Infos[1];
             $Symbol = imagecreatefrompng($DataDescription["Symbol"][$ColName]);
         }
         $XPos = $this->GArea_X1 + $this->GAreaXOffset;
         $Hsize = round($BigRadius / 2);
         $R3 = -1;
         $G3 = -1;
         $B3 = -1;
         $d_count = count($Data);
         $foreach_i = 0;
         foreach ($Data as $Key => $Values) {
             $foreach_i++;
             $Value = $Data[$Key][$ColName];
             $YPos = $this->GArea_Y2 - ($Value - $this->VMin) * $this->DivisionRatio;
             /* Save point into the image map if option activated */
             if ($this->BuildMap) {
                 $this->addToImageMap($XPos - $Hsize, $YPos - $Hsize, $XPos + 1 + $Hsize, $YPos + $Hsize + 1, $DataDescription["Description"][$ColName], $Data[$Key][$ColName] . $DataDescription["Unit"]["Y"], "Plot");
             }
             if (is_numeric($Value)) {
                 if (!isset($DataDescription["Symbol"][$ColName])) {
                     if ($Shadow) {
                         if ($R3 != -1 && $G3 != -1 && $B3 != -1) {
                             $this->drawFilledCircle($XPos + 2, $YPos + 2, $BigRadius, $R3, $G3, $B3);
                         } else {
                             $R3 = $this->Palette[$ColorID]["R"] - 20;
                             if ($R3 < 0) {
                                 $R3 = 0;
                             }
                             $G3 = $this->Palette[$ColorID]["G"] - 20;
                             if ($G3 < 0) {
                                 $G3 = 0;
                             }
                             $B3 = $this->Palette[$ColorID]["B"] - 20;
                             if ($B3 < 0) {
                                 $B3 = 0;
                             }
                             $this->drawFilledCircle($XPos + 2, $YPos + 2, $BigRadius, $R3, $G3, $B3);
                         }
                     }
                     $this->drawFilledCircle($XPos + 1, $YPos + 1, $BigRadius, $R, $G, $B);
                     if ($SmallRadius != 0) {
                         if ($R2 != -1 && $G2 != -1 && $B2 != -1) {
                             $this->drawFilledCircle($XPos + 1, $YPos + 1, $SmallRadius, $R2, $G2, $B2);
                         } else {
                             $R2 = $this->Palette[$ColorID]["R"] - 15;
                             if ($R2 < 0) {
                                 $R2 = 0;
                             }
                             $G2 = $this->Palette[$ColorID]["G"] - 15;
                             if ($G2 < 0) {
                                 $G2 = 0;
                             }
                             $B2 = $this->Palette[$ColorID]["B"] - 15;
                             if ($B2 < 0) {
                                 $B2 = 0;
                             }
                             $this->drawFilledCircle($XPos + 1, $YPos + 1, $SmallRadius, $R2, $G2, $B2);
                         }
                     }
                 } else {
                     if ($foreach_i == $d_count && isset($DataDescription["SymbolLast"][$ColName])) {
                         $last_img = $DataDescription["SymbolLast"][$ColName];
                         $Infos = getimagesize($last_img);
                         $ImageWidth = $Infos[0];
                         $ImageHeight = $Infos[1];
                         $Symbol = imagecreatefrompng($last_img);
                     }
                     imagesetbrush($this->Picture, $Symbol);
                     imageline($this->Picture, $XPos, $YPos, $XPos, $YPos, IMG_COLOR_BRUSHED);
                     //imagecopymerge($this->Picture,$Symbol,$XPos+1-$ImageWidth/2,$YPos+1-$ImageHeight/2,0,0,10,10,50);
                 }
             }
             $XPos = $XPos + $this->DivisionWidth;
         }
         $GraphID++;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function apply(CanvasInterface $canvas, AbstractStyledDrawable $drawable)
 {
     $interval = array_merge(array_fill(0, $this->getShowTime(), 1), $this->getHideTime() == 0 ? array() : array_fill(0, $this->getHideTime(), 0));
     if (false == @imagesetstyle($canvas->getHandler(), $interval) || false == @imagesetbrush($canvas->getHandler(), $this->brush->getHandler())) {
         throw new DrawableException('Could Not Set The Brush And Interval');
     }
     return new StyledBrushedColor();
 }
Exemple #11
0
        $watermark_pos_x = abs($w / 2 - $w_width / 2);
        $watermark_pos_y = abs($h / 2 - $w_height / 2);
        //--大小換算
        $target_w = abs($w_width * ($w / $w_width) * $pi_w);
        $target_h = abs($w_height * ($h / $w_height) * $pi_h);
        // 浮水印的圖若是透明背景、透明底圖, 需要用下述兩行
        $case_in = $_GET["in"] ? $_GET["in"] : 5;
        $temp_png_w_array = png_water_inpos($w, $h, $target_w, $target_h, $case_in);
        $watermark_pos_x = $temp_png_w_array[0];
        $watermark_pos_y = $temp_png_w_array[1];
        $image_p = imagecreatetruecolor($target_w, $target_h);
        //--建立空圖
        imagealphablending($image_p, false);
        imagecopyresampled($image_p, $watermark, 0, 0, 0, 0, $target_w, $target_h, $w_width, $w_height);
        $watermark = $image_p;
        imagesetbrush($image, $watermark);
        imageline($image, $watermark_pos_x, $watermark_pos_y, $watermark_pos_x, $watermark_pos_y, IMG_COLOR_BRUSHED);
        imageinterlace($image, 1);
        //--將圖片轉換為漸進式模
        imagejpeg($image);
        imagedestroy($image);
        break;
}
imageinterlace($image, 1);
//--將圖片轉換為漸進式模
imagedestroy($image);
//●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
/*
	使用 function 參數
*/
//--位置定位
Exemple #12
0
 function onImage($image, $fontName, $x, $y, $size, $color, $shadowOffset)
 {
     $fontFile = StyleParser::getFont($fontName, $this->style & (StyleParser::BOLD | StyleParser::ITALIC));
     if ($this->style & StyleParser::COLORED) {
         $color = Color::Rgb12ToRgb24($this->style & 0xfff);
         if (StyleParser::getBackground() !== null && StyleParser::getContrast() !== null) {
             $color = Color::Contrast($color, StyleParser::getBackground(), StyleParser::getContrast());
         }
     }
     $width = 0;
     $extraSpace = $size / 5;
     if ($this->style & StyleParser::WIDE || $this->style & StyleParser::NARROW) {
         $ratio = $this->style & StyleParser::WIDE ? 1.5 : 1 / 1.5;
         $extraSpace *= $ratio;
         foreach ((array) $this->text as $char) {
             $bBox = imagettfbbox($size, 0, $fontFile, $char);
             //echo print_r($bBox, true).'<br>';
             $temp = imagecreatetruecolor(($bBox[2] - $bBox[0]) * 2, ($bBox[3] - $bBox[5]) * 2);
             imagefill($temp, 0, 0, 0x7fffffff);
             $brush = imagecreatetruecolor(imagesx($temp) * $ratio, imagesy($temp));
             imagefill($brush, 0, 0, 0x7fffffff);
             $brushX = $x + $width + imagesx($brush) / 2;
             $brushY = $y;
             if ($this->style & StyleParser::SHADOWED) {
                 imagettftext($temp, $size, 0, -$bBox[0] + $shadowOffset, $bBox[3] - $bBox[5] + $shadowOffset, 0x3f000000, $fontFile, $char);
             }
             imagettftext($temp, $size, 0, -$bBox[0], $bBox[3] - $bBox[5], $color, $fontFile, $char);
             imagecopyresampled($brush, $temp, 0, 0, 0, 0, imagesx($brush), imagesy($brush), imagesx($temp), imagesy($temp));
             imagesetbrush($image, $brush);
             imageline($image, $brushX, $brushY, $brushX, $brushY, IMG_COLOR_BRUSHED);
             imagedestroy($temp);
             imagedestroy($brush);
             $width += ($bBox[2] - $bBox[0] + $extraSpace) * $ratio;
         }
     } else {
         foreach ((array) $this->text as $char) {
             $bBox = imagettfbbox($size, 0, $fontFile, $char);
             if ($this->style & StyleParser::SHADOWED) {
                 imagettftext($image, $size, 0, $x + $width - $bBox[0] + $shadowOffset, $y + $shadowOffset, 0x3f000000, $fontFile, $char);
             }
             imagettftext($image, $size, 0, $x + $width - $bBox[0], $y, $color, $fontFile, $char);
             $width += $bBox[2] - $bBox[0] + $extraSpace;
         }
     }
     return $width;
 }
Exemple #13
0
 private function mergeWatermark($image, $original_name, $suffix)
 {
     $watermark = config('fileapi.watermark');
     if (!File::exists(base_path($watermark))) {
         return null;
     }
     $watermark_image = $this->setTmpImage(base_path($watermark));
     imagesavealpha($watermark_image, true);
     imagesetbrush($image, $watermark_image);
     $watermark_pos_x = imagesx($image) - imagesy($watermark_image) - 100;
     $watermark_pos_y = (imagesy($image) - imagesy($image) * 1 / 1.91) / 2;
     imageline($image, $watermark_pos_x, $watermark_pos_y, $watermark_pos_x, $watermark_pos_y, IMG_COLOR_BRUSHED);
     imagesavealpha($image, true);
     $main_image = $original_name . '.' . $suffix;
     $tmp_filename = 'tmp' . DIRECTORY_SEPARATOR . $main_image;
     $tmp_path = \Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix();
     $watermark_filename = $this->basepath . $original_name . '_W' . '.' . $suffix;
     // save thumbnail image
     imagepng($image, $tmp_path . $tmp_filename);
     $tmp_file = \Storage::disk('local')->get($tmp_filename);
     \Storage::put($watermark_filename, $tmp_file);
     // remove tmp image
     \Storage::disk('local')->delete($tmp_filename);
 }
Exemple #14
0
 public function setLine($thickness = 1, $style = NULL, $brush = NULL)
 {
     if (!$this->checkImage()) {
         return false;
     }
     imagesetthickness($this->img, $thickness);
     if (is_array($style)) {
         $style_lst = array();
         $max_count = count($style);
         for ($i = 0; $i < $max_count; $i++) {
             if (isset($this->color_lst[$style[$i]])) {
                 $style_lst[] = $this->color_lst[$style[$i]];
             }
         }
         imagesetstyle($this->img, $style_lst);
     }
     if (!is_null($brush)) {
         if (!$this->checkImage($brush)) {
             $brush = loadImage($brush);
         }
         if ($brush) {
             imagesetbrush($this->img, $brush);
         }
     }
     return;
 }
Exemple #15
0
 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';
 }
 /**
  * Sets a brush
  *
  * @see     xp://img.ImgBrush
  * @param   img.ImgBrush brush
  * @return  img.ImgBrush the new style object
  * @throws  lang.IllegalArgumentException if style is not an ImgBrush object
  */
 public function setBrush(ImgBrush $brush)
 {
     if (NULL !== $brush->style) {
         imagesetstyle($this->handle, $brush->style->getPixels());
     }
     imagesetbrush($this->handle, $brush->image->handle);
     return $brush;
 }
Exemple #17
0
 function imageCopyMergeAlpha($image1, $image2, $filename)
 {
     $ext = strtolower(substr(strrchr($image2, "."), 1));
     if (!in_array($ext, array('jpg', 'jpeg'))) {
         $tempsrc = "temp.jpg";
         $temp = imagecreatefromgif($image2);
         imagejpeg($temp, $tempsrc);
         $image2 = $tempsrc;
     }
     $src = imagecreatefromstring(file_get_contents($image1));
     $dest = imagecreatefromstring(file_get_contents($image2));
     // Set the brush
     imagesetbrush($dest, $src);
     // Draw a couple of brushes, each overlaying each
     imageline($dest, imagesx($dest) / 2, imagesy($dest) / 2, imagesx($dest) / 2, imagesy($dest) / 2, IMG_COLOR_BRUSHED);
     //header('Content-Type: $mimetype');
     imagejpeg($dest, $filename);
 }
Exemple #18
0
<?php

// Create the brush image
$img = imagecreate(10, 10);
// Create the main image, 100x100
$mainimg = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($img, 255, 0, 0);
imagefilledrectangle($img, 0, 0, 299, 99, $white);
// Set the brush
imagesetbrush($mainimg, $img);
// Draw a couple of brushes, each overlaying each
imageline($mainimg, 50, 50, 50, 60, IMG_COLOR_BRUSHED);
// Get output and generate md5 hash
ob_start();
imagepng($mainimg, null, 9);
$result_image = ob_get_contents();
ob_end_clean();
echo md5(base64_encode($result_image));
Exemple #19
0
function watermark($from_filename, $watermark_filename, $save_filename = NULL, $act = true)
{
    $allow_format = array('jpeg', 'png', 'gif');
    $sub_name = $t = '';
    //--判斷目標圖片空值則取代原圖
    if ($save_filename == NULL) {
        $save_filename = $from_filename;
    }
    // 原圖
    $img_info = getimagesize($from_filename);
    $width = $img_info['0'];
    $height = $img_info['1'];
    $mime = $img_info['mime'];
    list($t, $sub_name) = explode('/', $mime);
    if ($sub_name == 'jpg') {
        $sub_name = 'jpeg';
    }
    if (!in_array($sub_name, $allow_format)) {
        return false;
    }
    $function_name = 'imagecreatefrom' . $sub_name;
    $image = $function_name($from_filename);
    // 浮水印
    $img_info = getimagesize($watermark_filename);
    $w_width = $img_info['0'];
    $w_height = $img_info['1'];
    $w_mime = $img_info['mime'];
    list($t, $sub_name) = explode('/', $w_mime);
    if (!in_array($sub_name, $allow_format)) {
        return false;
    }
    $function_name = 'imagecreatefrom' . $sub_name;
    $watermark = $function_name($watermark_filename);
    $watermark_pos_x = abs($width - $w_width);
    $watermark_pos_y = abs($height - $w_height);
    if (!$act) {
        //--非透明背景圖
        imagecopymerge($image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $w_width, $w_height, 100);
    } else {
        // 浮水印的圖若是透明背景、透明底圖, 需要用下述兩行
        imagesetbrush($image, $watermark);
        imageline($image, $watermark_pos_x, $watermark_pos_y, $watermark_pos_x, $watermark_pos_y, IMG_COLOR_BRUSHED);
    }
    imageinterlace($image, 1);
    //--將圖片轉換為漸進式模
    return imagejpeg($image, $save_filename);
}
Exemple #20
0
 /**
  * Defines the brush used on the $image attribute
  *
  * @return bool Always true
  */
 private function setBrush()
 {
     $noise_color = imagecolorallocate($this->image, $this->captcha['noise_color']['red'], $this->captcha['noise_color']['green'], $this->captcha['noise_color']['blue']);
     if ($this->config['brush_size'] && $this->config['brush_size'] > 1 && function_exists('imagesetbrush')) {
         $brush = imagecreatetruecolor($this->config['brush_size'], $this->config['brush_size']);
         imagefill($brush, 0, 0, $noise_color);
         imagesetbrush($this->image, $brush);
         $this->captcha['noise_brush'] = IMG_COLOR_BRUSHED;
         $this->captcha['brush'] = $brush;
     } else {
         $this->captcha['noise_brush'] = $noise_color;
     }
     return true;
 }
Exemple #21
0
 function createthumb($name, $filename, $new_w, $new_h, $formatfile)
 {
     if ($formatfile == "JPG") {
         $src_img = imagecreatefromjpeg($name);
         $color = imagecolorallocate($src_img, 220, 220, 200);
         imagerotate($src_img, 20, $color);
     }
     if ($formatfile == "PNG") {
         $src_img = imagecreatefrompng($name);
     }
     if ($formatfile == "BMP") {
         $src_img = imagecreatefromjpeg("./Error.JPG");
     }
     if ($formatfile == "GIF") {
         $src_img = imagecreatefromgif($name);
     }
     $old_x = imagesx($src_img);
     $old_y = imagesy($src_img);
     $old_size = filesize($name);
     if ($old_x > $old_y) {
         $thumb_w = $new_w;
         $thumb_h = $old_y * ($new_h / $old_x);
     }
     if ($old_x < $old_y) {
         $thumb_w = $old_x * ($new_w / $old_y);
         $thumb_h = $new_h;
     }
     if ($old_x == $old_y) {
         $thumb_w = $new_w;
         $thumb_h = $new_h;
     }
     if ($thumb_h < 60) {
         $thumb_h = 60;
     }
     $dst_img = imagecreatetruecolor(150, $thumb_h);
     if ($t_img != "BMP") {
         $xaa = intval(imagesx($src_img) - imagesx($dst_img)) / 2;
         $yaa = intval(150 - $old_y) / 2;
         // Define the size and color of the brush
         if ($old_y >= 150) {
             imagefilledrectangle($dst_img, 0, $alt - 20, 150, 150, 220822);
             imagecopyresampled($dst_img, $src_img, 75 - $thumb_w / 2, $y12 * 20, 0, 0, $thumb_w, $thumb_h - 20, $old_x, $old_y);
         } else {
             if ($old_x > $old_y) {
                 imagefilledrectangle($dst_img, 0, $alt - 20, $thumb_w, $thumb_w, 00);
                 imagecopyresampled($dst_img, $src_img, $x12 * 20, $y12 * 20, 0, 0, $thumb_w, $thumb_h - 20, $old_x, $old_y);
             } else {
                 $ub_x = 150 / 2;
                 $ub_y = 150 / 2;
                 imagefilledrectangle($dst_img, 0, $alt - 20, 150, 150, 220822);
                 imagecopyresampled($dst_img, $src_img, 75 - $old_x / 2, 75 - $old_y / 2, 0, 0, $old_x, $old_y, $old_x, $old_y);
             }
         }
     } else {
         imagecopyresampled($dst_img, $src_img, $x12, $y12, 0, 0, $anchor12, $myx12 - 20, $old_x, $old_y);
     }
     $thumb_w = 150;
     // Here start to generate the borders!
     $anchor = $thumb_w;
     $alt = $thumb_h;
     $neg = imagecolorallocate($dst_img, 0, 0, 0);
     $pick = imagecolorallocate($dst_img, 255, 255, 255);
     if ($formatfile != "BMP") {
         $text = $old_x . "x" . $old_y;
     } else {
         list($anchor, $myx, $tip, $atr) = getimagesize($name);
         $text = $anchor . "x" . $myx;
     }
     $long = strlen($text) * imagefontwidth(2);
     // size of the brush
     $brush = imagecreate(4, 4);
     // Colors of the brush
     $amp = imagecolorallocate($brush, 0, 0, 0);
     $neg = imagecolorallocate($brush, 0, 0, 0);
     // In the brush
     imagefilledrectangle($brush, 0, 0, 3, 3, $neg);
     imagefilledrectangle($brush, 2, 2, 4, 4, $neg);
     // This define what brush wil be used
     imagesetbrush($dst_img, $brush);
     // Drawings...
     if ($formatfile != "BMP") {
         imagerectangle($dst_img, 0, 0, $anchor, $alt, IMG_COLOR_BRUSHED);
     } else {
         imagecopy($dst_img, $src_img, 0, 0, 0, 0, 150, 150);
         imagerectangle($dst_img, 0, 0, 150, 150, IMG_COLOR_BRUSHED);
     }
     if ($formatfile != "BMP") {
         imagefilledrectangle($dst_img, 0, $alt - 20, $anchor, $alt, $neg);
         imagestring($dst_img, 2, $anchor - $long - 10, $alt - 17, $text, $pick);
     } else {
         imagefilledrectangle($dst_img, 0, 150 - 20, 150, 150, $neg);
         imagesetthickness($dst_img, 3);
         imagestring($dst_img, 2, 150 - $long - 10, 150 - 17, $text, $pick);
     }
     if ($formatfile == "PNG") {
         imagepng($dst_img, $filename);
     }
     if ($formatfile == "BMP") {
         imagewbmp($dst_img, $filename);
     }
     if ($formatfile == "GIF") {
         imagegif($dst_img, $filename);
     }
     if ($formatfile == "JPG") {
         imagejpeg($dst_img, $filename);
     }
     imagedestroy($dst_img);
     if ($formatfile != "BMP") {
         imagedestroy($src_img);
     }
 }