Ejemplo n.º 1
0
 public static function hashImage($res, $size = 8)
 {
     $res = imagecreatefromstring(file_get_contents($res));
     // make sure this is a resource
     $rescached = imagecreatetruecolor($size, $size);
     imagecopyresampled($rescached, $res, 0, 0, 0, 0, $size, $size, imagesx($res), imagesy($res));
     imagecopymergegray($rescached, $res, 0, 0, 0, 0, $size, $size, 50);
     $w = imagesx($rescached);
     $h = imagesy($rescached);
     $pixels = array();
     for ($y = 0; $y < $size; $y++) {
         for ($x = 0; $x < $size; $x++) {
             $rgb = imagecolorsforindex($rescached, imagecolorat($rescached, $x, $y));
             $r = $rgb['red'];
             $g = $rgb['green'];
             $b = $rgb['blue'];
             $gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
             $gs = floor($gs);
             $pixels[] = $gs;
         }
     }
     // find the average value in the array
     $avg = self::arrayAverage($pixels);
     // create a hash (1 for pixels above the mean, 0 for average or below)
     $index = 0;
     foreach ($pixels as $px) {
         $hash[$index] = $px > $avg;
         $index += 1;
     }
     return $hash;
 }
 public function make_grayscale()
 {
     // create a copy
     $dest = $this->image;
     unset($this->image);
     $this->load();
     if (is_resource($dest)) {
         // Apply grayscale filter
         imagecopymergegray($dest, $this->image, 0, 0, 0, 0, $this->size['width'], $this->size['height'], 0);
         imagegammacorrect($dest, 1.0, apply_filters('grayscale_gamma_correction', 0.7));
         imagedestroy($this->image);
         $this->image = $dest;
         return true;
     }
 }
Ejemplo n.º 3
0
 function waterMark($source, $logo, $alpha = 50, $isstream = false)
 {
     list($swidth, $sheight) = getimagesize($source);
     list($width, $height) = getimagesize($logo);
     $fl =& $this->bd->make('fl');
     $ext = $fl->getFileExtName($source, false);
     $ext2 = $fl->getFileExtName($logo, false);
     $s_pic = $this->createImage($source, $ext);
     imagealphablending($s_pic, true);
     $l_pic = $this->createImage($logo, $ext2);
     imagecopymergegray($s_pic, $l_pic, intval($swidth - $width), intval($sheight - $height), 0, 0, $width, $height, $alpha);
     if ($this->writeImage($s_pic, $source, 100, $ext)) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
 public function apply($resource)
 {
     // Extract arguments
     @(list(, $image, $method, $x1, $y1, $x2, $y2, $src_w, $src_h, $pct) = func_get_args());
     $x1 = (int) $x1;
     $y1 = (int) $y1;
     $x2 = (int) $x2;
     $y2 = (int) $y2;
     $src_w = (int) $src_w;
     $src_h = (int) $src_h;
     $pct = (int) $pct;
     // Verify
     if ($image instanceof Imagix\AbstractImage) {
         $image = $image->getResource();
     } elseif (!is_resource($image)) {
         throw new Exception("The 'image' parameter must be a valid GD resource or a Lumy\\Image\\AbstractImage child object");
     }
     // Normalize
     if (!$src_w) {
         $src_w = imagesx($image);
     }
     if (!$src_h) {
         $src_h = imagesy($image);
     }
     if ($pct === null) {
         $pct = 50;
     } elseif ($pct < 0) {
         $pct = 0;
     } elseif ($pct > 100) {
         $pct = 100;
     }
     // Merge images
     switch ($method) {
         case self::GRAYSCALE:
             imagecopymergegray($resource, $image, $x1, $y1, $x2, $y2, $src_w, $src_h, $pct);
             break;
         case self::NORMAL:
         default:
             imagecopymerge($resource, $image, $x1, $y1, $x2, $y2, $src_w, $src_h, $pct);
     }
     return $resource;
 }
Ejemplo n.º 5
0
function Thaiza($Header, $Birth_Date, $Image_1, $Image_2)
{
    $Now = date("j F Y");
    $Total_Day = datediff('d', $Now, $Birth_Date, false);
    if ($Total_Day <= 0) {
        $Week = 0;
        $Day = 0;
    } else {
        $Week = floor($Total_Day / 7);
        $Day = $Total_Day % 7;
    }
    $px_w = (40 - $Week) * 10;
    if ($px_w >= 360) {
        $px_w = 360;
    }
    if ($px_w <= 40) {
        $px_w = 40;
    }
    $String_2 = "{$Week} weeks and {$Day} days pregnant. Only {$Total_Day} days to go.";
    $image_1 = imagecreate(400, 100);
    $background_color = imagecolorallocate($image_1, 255, 255, 255);
    $image_2 = imagecreatefromjpeg($Image_1);
    $image_3 = imagecreatefromjpeg($Image_2);
    imagecopy($image_1, $image_2, 0, 20, 0, 0, 400, 60);
    imagecopymergegray($image_1, $image_3, $px_w, 20, 0, 0, 40, 60, 70);
    $Color = imagecolorallocate($image_1, 0, 0, 0);
    $px_1 = (imagesx($image_1) - 7.5 * strlen($Header)) / 2;
    $py_1 = imagesy($image_1) - 90;
    imagestring($image_1, 3, $px_1, $py_1, $Header, $Color);
    $px_2 = (imagesx($image_1) - 7.5 * strlen($String_2)) / 2;
    $py_2 = imagesy($image_1) - 20;
    imagestring($image_1, 3, $px_2, $py_2, $String_2, $Color);
    Header("Content-type: image/jpeg");
    imagepng($image_1);
    imagedestroy($image_1);
}
Ejemplo n.º 6
0
 static function copy(&$image, $picture, $param, $mode = 5)
 {
     switch ($mode) {
         case 1:
             //拷贝
             return imagecopy($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5]);
         case 2:
             //拷贝+合并
             return imagecopymerge($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6]);
         case 3:
             //灰度拷贝+合并
             return imagecopymergegray($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6]);
         case 4:
             //拷贝+调整大小
             return imagecopyresized($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6], $param[7]);
         case 5:
             //采样+拷贝+调整大小
         //采样+拷贝+调整大小
         default:
             return imagecopyresampled($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6], $param[7]);
     }
 }
Ejemplo n.º 7
0
 /**
  * add grayscale effect for given gd resource<br/>
  * <b>Note :</b>
  * gray method work with imagefilter function or imagecopymergegray if exist but if not
  * it will also work but it will take more time
  * @param resource $virtual_image gd resource
  * @return boolean true on success false otherwise
  */
 public static function gray($virtual_image)
 {
     if (@get_resource_type($virtual_image) != TIP_RT) {
         self::logger("gray", " Not A GD Resource");
         return false;
     }
     $is_exist = function_exists('imagefilter');
     if ($is_exist == true) {
         self::activateAlphaChannel($virtual_image);
         return @imagefilter($virtual_image, IMG_FILTER_GRAYSCALE);
     } else {
         self::activateAlphaChannel($virtual_image);
         $width = self::getWidth($virtual_image);
         $height = self::getHeight($virtual_image);
         $result = @imagecopymergegray($virtual_image, $virtual_image, 0, 0, 0, 0, $width, $height, 0);
         if ($result) {
             return true;
         }
         self::logger("gray", "GD Lib Does Not Support Gray Advanced Method Running Slow Mode", TULIP_NOTICE);
         for ($x = 0; $x < $width; $x++) {
             for ($y = 0; $y < $height; $y++) {
                 $color_index = @imagecolorat($virtual_image, $x, $y);
                 $rgb = @imagecolorsforindex($virtual_image, $color_index);
                 $fixed_rgb = @round(($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3);
                 $new_color = @imagecolorallocate($virtual_image, $fixed_rgb, $fixed_rgb, $fixed_rgb);
                 if (!@imagesetpixel($virtual_image, $x, $y, $new_color)) {
                     self::logger("gray", "Error Setting Pixels");
                     return false;
                 }
             }
         }
         return true;
     }
 }
Ejemplo n.º 8
0
 static function copy($res, $res_img, $mode, $arr)
 {
     if ($mode == 1) {
         //拷贝
         return imagecopy($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5]);
     }
     if ($mode == 2) {
         //拷贝+合并
         return imagecopymerge($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6]);
     }
     if ($mode == 3) {
         //灰度拷贝+合并
         return imagecopymergegray($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6]);
     }
     if ($mode == 4) {
         //拷贝+调整大小
         return imagecopyresized($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], $arr[7]);
     }
     if ($mode == 5) {
         //采样+拷贝+调整大小
         return imagecopyresampled($res, $res_img, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], $arr[7]);
     }
 }
 public function HashImage($res, $rot = 0, $mir = 0, $size = 8, $WhichHash = 'aHash')
 {
     $res = $this->NormalizeAsResource($res);
     // make sure this is a resource
     $rescached = imagecreatetruecolor($size, $size);
     imagecopyresampled($rescached, $res, 0, 0, 0, 0, $size, $size, imagesx($res), imagesy($res));
     imagecopymergegray($rescached, $res, 0, 0, 0, 0, $size, $size, 50);
     $w = imagesx($rescached);
     $h = imagesy($rescached);
     $pixels = array();
     for ($y = 0; $y < $size; $y++) {
         for ($x = 0; $x < $size; $x++) {
             /* 	instead of rotating the image, we'll rotate the position of the pixels to allow us to generate a hash
             				we can use to judge if one image is a rotated or flipped version of the other, without actually creating
             				an extra image resource. This currently only works at all for 90 degree rotations and mirrors. */
             switch ($rot) {
                 case 90:
                     $rx = $h - 1 - $y;
                     $ry = $x;
                     break;
                 case 180:
                     $rx = $w - $x - 1;
                     $ry = $h - 1 - $y;
                     break;
                 case 270:
                     $rx = $y;
                     $ry = $h - $x - 1;
                     break;
                 default:
                     $rx = $x;
                     $ry = $y;
             }
             switch ($mir) {
                 case 1:
                     $rx = $w - $rx - 1;
                     break;
                 case 2:
                     $ry = $h - $ry;
                     break;
                 case 3:
                     $rx = $w - $rx - 1;
                     $ry = $h - $ry;
                     break;
                 default:
                     break;
             }
             $rgb = imagecolorsforindex($rescached, imagecolorat($rescached, $rx, $ry));
             $r = $rgb['red'];
             $g = $rgb['green'];
             $b = $rgb['blue'];
             $gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
             $gs = floor($gs);
             $pixels[] = $gs;
             //$index++;
         }
     }
     // find the average value in the array
     $avg = $this->ArrayAverage($pixels);
     // create a hash (1 for pixels above the mean, 0 for average or below)
     $index = 0;
     // Legendante - Added a check to use one of two hashes
     // Use the difference hash (dHash) as per Dr. Neal Krawetz
     // http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
     if ($WhichHash == 'dHash') {
         foreach ($pixels as $ind => $px) {
             // Legendante - Uses the original 8*8 comparison originally suggested to Dr. Krawetz
             // not the modified 9*8 as suggested by Dr. Krawetz
             if (!isset($pixels[$ind + 1])) {
                 $ind = -1;
             }
             if ($px > $pixels[$ind + 1]) {
                 $hash[] = 1;
             } else {
                 $hash[] = 0;
             }
         }
     } else {
         foreach ($pixels as $px) {
             if ($px > $avg) {
                 $hash[$index] = 1;
             } else {
                 $hash[$index] = 0;
             }
             $index += 1;
         }
     }
     // return the array
     return $hash;
 }
Ejemplo n.º 10
0
 public function grayscale()
 {
     //$newImage=$this->createImage($this->_width, $this->_height, $this->trueColor);
     $newImage = imagecreatetruecolor($this->_width, $this->_height);
     imagecopy($newImage, $this->_image, 0, 0, 0, 0, $this->_width, $this->_height);
     imagecopymergegray($newImage, $newImage, 0, 0, 0, 0, $this->_width, $this->_height, 0);
     imagedestroy($this->_image);
     $this->_image = $newImage;
     return $this;
 }
Ejemplo n.º 11
0
function convert_theme($in_name, $out_name, $ws, $hs)
{
    global $message;
    // debug
    // echo '--- THEME resize called : ' . $in_name . ' - ' . $out_name . ' - ' . $ws . 'x' . $hs ;
    $image_info = getimagesize($in_name);
    // get source image width/height
    //
    $sw = $image_info[0];
    $sh = $image_info[1];
    $parts = pathinfo($out_name);
    $file_ext = strtolower($parts['extension']);
    // $file_name = $parts['filename'];
    $base_name = $parts['basename'];
    $pos = strrpos($base_name, ".");
    $file_name = substr($base_name, 0, $pos);
    $file_path = $parts['dirname'];
    // create & load original image
    //
    $img = false;
    if ($file_ext == 'jpg' or $file_ext == 'jpeg') {
        $img = imagecreatefromjpeg($in_name);
    } else {
        if ($file_ext == 'gif') {
            $img = imagecreatefromgif($in_name);
        } else {
            if ($file_ext == 'png') {
                $img = imagecreatefrompng($in_name);
            }
        }
    }
    if ($img == false) {
        $message = "Cannot load image";
        return -5;
    }
    //
    $dw = $ws[0];
    $dh = $hs[0];
    $out_img = imagecreatetruecolor($dw, $dh);
    imagecopyresized($out_img, $img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
    $out_file = $file_path . '/' . $file_name . '_big.' . $file_ext;
    $ret = save_image_by_type($out_img, $out_file, $file_ext);
    if ($ret == false) {
        $message = "Cannot write image";
        return -3;
    }
    //
    // icon
    //
    $dw = $ws[1];
    $dh = $hs[1];
    imageDestroy($out_img);
    $out_img = imagecreatetruecolor($dw, $dh);
    imagecopyresized($out_img, $img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
    $out_file = $file_path . '/' . $file_name . '_yes.' . $file_ext;
    $ret = save_image_by_type($out_img, $out_file, $file_ext);
    if ($ret == false) {
        $message = "Cannot write image";
        return -3;
    }
    $out_file = $file_path . '/' . $file_name . '_off.' . $file_ext;
    $gray_img = imagecreatetruecolor($dw, $dh);
    imagecopymergegray($gray_img, $out_img, 0, 0, 0, 0, $dw, $dh, 60);
    $ret = save_image_by_type($gray_img, $out_file, $file_ext);
    if ($ret == false) {
        $message = "Cannot write image";
        return -3;
    }
    imageDestroy($gray_img);
    $out_file = $file_path . '/' . $file_name . '_on.' . $file_ext;
    $ret = save_image_by_type($out_img, $out_file, $file_ext);
    if ($ret == false) {
        $message = "Cannot write image";
        return -3;
    }
    $out_file = $file_path . '/' . $file_name . '_ov.' . $file_ext;
    $ret = save_image_by_type($out_img, $out_file, $file_ext);
    if ($ret == false) {
        $message = "Cannot write image";
        return -3;
    }
    // wap icon
    //
    $dw = $ws[2];
    $dh = $hs[2];
    imageDestroy($out_img);
    $out_img = imagecreatetruecolor($dw, $dh);
    imagecopyresized($out_img, $img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
    $ret = imagetruecolortopalette($out_img, true, 255);
    // image, dither, ncolors
    $out_file = $file_path . '/' . $file_name . '_wap.png';
    $ret = imagepng($out_img, $out_file, $file_ext);
    chmod($out_file, 0755);
    if ($ret == false) {
        $message = "Cannot write image";
        return -3;
    }
    imageDestroy($out_img);
    imageDestroy($img);
    return 0;
}
Ejemplo n.º 12
0
 public function mixGray($source, array $settings) : InternalGD
 {
     if (!is_resource($source)) {
         throw new InvalidArgumentException('Error', 'resourceParameter', '1.($source)');
     }
     $xt = isset($settings['xt']) ? $settings['xt'] : 0;
     $yt = isset($settings['yt']) ? $settings['yt'] : 0;
     $xs = isset($settings['xs']) ? $settings['xs'] : 0;
     $ys = isset($settings['ys']) ? $settings['ys'] : 0;
     $width = isset($settings['width']) ? $settings['width'] : 0;
     $height = isset($settings['height']) ? $settings['height'] : 0;
     $percent = isset($settings['percent']) ? $settings['percent'] : 0;
     imagecopymergegray($this->canvas, $source, $xt, $yt, $xs, $ys, $width, $height, $percent);
     return $this;
 }
Ejemplo n.º 13
0
Archivo: GD.php Proyecto: joeymetal/v1
 /**
  * Converts the image to greyscale
  *
  * @return bool|PEAR_Error TRUE or a PEAR_Error object on error
  * @access public
  */
 function greyscale()
 {
     imagecopymergegray($this->imageHandle, $this->imageHandle, 0, 0, 0, 0, $this->new_x, $this->new_y, 0);
     return true;
 }
Ejemplo n.º 14
0
<?php

define("SRC_FILE", "php.png");
$img = imagecreatefrompng(SRC_FILE);
$img_copy = imagecreatefrompng(SRC_FILE);
imagecopymergegray($img_copy, $img, 10, 10, 0, 0, imagesx($img), imagesy($img), 50);
header("Content-Type: image/png");
imagepng($img_copy);
Ejemplo n.º 15
0
 /**
  * 给源图片打上图片水印
  * (貌似有些打出来达不到想要的效果)
  * 水印图片如果是 png 的话,貌似全透明的效果出不来
  * 如果源图是png8貌似打出来效果不好
  * @see Lib_Image_Abstract::watermarkImage()
  * @param string $watermarkPath 水印图片的绝对路径
  * @param string $place 打水印的位置(position);取值见常量。默认southeast:右下角;center:中间;southwest:左下角;northeast:右上角; northwest:左上角
  * @param integer $x 打水印的开始位置,X轴;如果传入了$place,此值将做为偏移量
  * @param integer $y 打水印的开始位置,Y轴;如果传入了$place,此值将做为偏移量
  * @param integer $alpha 水印图片的透明度,取值0(全透明)-100(不透明);仅对 jpg 格式的水印图片有效(暂不支持)
  * @param integer $angle TODO 水印图片的旋转角度
  * @return boolean
  */
 public function watermarkImage($watermarkPath, $place = 'southeast', $x = 18, $y = 18, $alpha = 52, $angle = 0)
 {
     if (!is_file($watermarkPath)) {
         $this->_error = '水印图片不存在!';
         $this->_im = null;
         return false;
     }
     if (!$this->_isExistIm()) {
         return false;
     }
     $watermarkExt = strtolower(strrchr($watermarkPath, '.'));
     if (!in_array($watermarkExt, $this->_allowExt)) {
         // 仅通过后缀名进行判断和创建图像资源; TODO 真实的文件类型
         $this->_error = '水印图片文件类型不符,只支持 ' . implode('、', $this->_allowExt) . ' 格式的图片';
         $this->_im = null;
         return false;
     }
     $watermarkType = substr($watermarkExt, 1);
     if ($watermarkType == 'jpg') {
         $watermarkType = 'jpeg';
     }
     $imageFunction = 'imagecreatefrom' . $watermarkType;
     $watermarkImg = $imageFunction($watermarkPath);
     $watermarkW = imagesx($watermarkImg);
     $watermarkH = imagesy($watermarkImg);
     if ($this->_sourceWidth < $watermarkW || $this->_sourceHeight < $watermarkH) {
         // 多于判断,有时候没有必要考虑
         $this->setError('源图片的宽或高小于水印图片的宽或高,无法生成水印图!');
         $this->_im = null;
         return false;
     }
     switch ($place) {
         case self::PLACE_NORTHWEST:
             break;
         case self::PLACE_NORTHEAST:
             $x = $this->_sourceWidth - ($watermarkW + $x);
             break;
         case self::PLACE_CENTER:
             $x = ($this->_sourceWidth - $watermarkW) / 2;
             $y = ($this->_sourceHeight - $watermarkH) / 2;
             break;
         case self::PLACE_SOUTHWEST:
             $y = $this->_sourceHeight - ($watermarkH + $y);
             break;
         case self::PLACE_SOUTHEAST:
             $x = $this->_sourceWidth - ($watermarkW + $x);
             $y = $this->_sourceHeight - ($watermarkH + $y);
             break;
         default:
             break;
     }
     imagealphablending($this->_im, true);
     // 设定图像的混色模式;  貌似这里没有什么用,用不用都一样
     $boolean = imagecopymergegray($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH, $alpha);
     // ubuntu 64 位下测试不行; ubuntu 32 位下测试可以
     // 用灰度拷贝并合并图像的一部分;拷贝水印到目标文件
     //$boolean = imagecopy($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH); // ubuntu 64 位下测试还可以
     //$boolean = imagecopymerge($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH, 100); // ubuntu 64 位下测试不行
     //$boolean = imagecopyresized($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH, $watermarkW, $watermarkH); // ubuntu 64 位下测试还可以
     //$boolean = imagecopyresampled($this->_im, $watermarkImg, $x, $y, 0, 0, $watermarkW, $watermarkH, $watermarkW, $watermarkH); // ubuntu 64 位下测试还可以
     // int imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h); 拷贝图像的一部分
     //imagecopyresized($this->_im, $watermarkImg, $start['x'], $start['y'], 0, 0, $watermarkW, $watermarkH, $watermarkW, $watermarkH); // 这个写法就和上面的一模一样
     //int imagecopymerge ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct ) 拷贝并合并图像的一部分
     // 将 src_im 图像中坐标从 src_x,src_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_x 和 dst_y 的位置上。两图像将根据 pct 来决定合并程度,其值范围从 0 到 100。
     // 当 pct = 0 时,实际上什么也没做 当为 100 时本函数和 imagecopy() 完全一样。
     // imagecopymergegray 和 imagecopymerge() 完全一样只除了合并时通过在拷贝操作前将目标像素转换为灰度级来保留了原色度。
     if ($boolean) {
         return true;
     } else {
         $this->_error = '拷贝并合并图像时出错';
         $this->_im = null;
         return false;
     }
 }
Ejemplo n.º 16
0
	function Filter() {//途中
		//imagegammacorrect($this->image,200,255);
		if($_GET["gray"]) {//グレイスケール処理
			$val	= $_GET["gray"];
			if($val < 0) $val	= 0;
			else if(100 < $val) $val	= 100;
			imagecopymergegray($this->image,$this->image,0,0,0,0,$this->img_x,$this->img_y,$val);
		}
		//$image_p = imagecreatetruecolor(240, 100);//縮小
		//imagecopyresampled($image_p, $this->image, 0, 0, 0, 0, 240, 100, $this->img_x, $this->img_y);
		//$this->image	= $image_p;
	}
Ejemplo n.º 17
0
$ext = $exp[count($exp) - 1];
switch (strtolower($ext)) {
    case 'jpg':
        $image = imagecreatefromjpeg($imgPath);
        break;
    case 'gif':
        $image = imagecreatefromgif($imgPath);
        break;
    case 'png':
        $image = imagecreatefrompng($imgPath);
        break;
}
$imagePb = $image;
$imgFrame = imagecreatetruecolor($pRate, $pRate);
imagecopyresampled($imgFrame, $imagePb, 0, 0, 0, 0, $pRate, $pRate, imagesx($imagePb), imagesy($imagePb));
imagecopymergegray($imgFrame, $image, 0, 0, 0, 0, imagesx($image), imagesy($image), 0);
$imageFinal = $imgFrame;
imagejpeg($imageFinal, $nImgPath, 100);
for ($line = 0; $line < $pRate; $line++) {
    for ($column = 0; $column < $pRate; $column++) {
        $color = imagecolorat($imageFinal, $line, $column);
        $rgb = imagecolorsforindex($imageFinal, $color);
        $gray = ($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3;
        $indexes[$line][$column] = $gray * 100 / 255;
        $blocks .= "<div style='background: rgb({$gray}, {$gray}, {$gray})';></div>";
    }
}
//print_r($indexes);
?>

<html>
Ejemplo n.º 18
0
 /**
  * @return bool
  * @desc Creates the mask image and determines position and size of mask
  *       based on the _maskOption value and image size.  If the image is
  *       smaller than the mask (and the mask isn't set to resize) then the
  *       mask defaults to the top-left position and will be cut off.
  */
 function _getMaskImage()
 {
     $isx = imagesx($this->_img['final']);
     $isy = imagesy($this->_img['final']);
     $msx = imagesx($this->_mask['orig']);
     $msy = imagesy($this->_mask['orig']);
     $this->_mask['gray'] = imagecreatetruecolor($isx, $isy);
     imagefill($this->_mask['gray'], 0, 0, imagecolorallocate($this->_mask['gray'], 0, 0, 0));
     if ($this->_mask['gray']) {
         switch ($this->_maskDynamic) {
             case mdTOPLEFT:
                 $sx = $sy = 0;
                 break;
             case mdTOP:
                 $sx = ceil(($isx - $msx) / 2);
                 $sy = 0;
                 break;
             case mdTOPRIGHT:
                 $sx = $isx - $msx;
                 $sy = 0;
                 break;
             case mdLEFT:
                 $sx = 0;
                 $sy = ceil(($isy - $msy) / 2);
                 break;
             case mdCENTRE:
                 $sx = ceil(($isx - $msx) / 2);
                 $sy = ceil(($isy - $msy) / 2);
                 break;
             case mdRIGHT:
                 $sx = $isx - $msx;
                 $sy = ceil(($isy - $msy) / 2);
                 break;
             case mdBOTTOMLEFT:
                 $sx = 0;
                 $sy = $isy - $msy;
                 break;
             case mdBOTTOM:
                 $sx = ceil(($isx - $msx) / 2);
                 $sy = $isy - $msy;
                 break;
             case mdBOTTOMRIGHT:
                 $sx = $isx - $msx;
                 $sy = $isy - $msy;
                 break;
         }
         if ($isx < $msx) {
             $sx = 0;
         }
         if ($isy < $msy) {
             $sy = 0;
         }
         if ($this->_maskDynamic == mdRESIZE) {
             $this->_mask['temp'] = imagecreatetruecolor($isx, $isy);
             imagecopyresampled($this->_mask['temp'], $this->_mask['orig'], 0, 0, 0, 0, $isx, $isy, $msx, $msy);
             imagecopymergegray($this->_mask['gray'], $this->_mask['temp'], 0, 0, 0, 0, $isx, $isy, 100);
             imagedestroy($this->_mask['temp']);
         } else {
             imagecopymergegray($this->_mask['gray'], $this->_mask['orig'], $sx, $sy, 0, 0, $msx, $msy, 100);
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 19
0
 function Filter()
 {
     if ($_GET["gray"]) {
         $val = $_GET["gray"];
         if ($val < 0) {
             $val = 0;
         } else {
             if (100 < $val) {
                 $val = 100;
             }
         }
         imagecopymergegray($this->image, $this->image, 0, 0, 0, 0, $this->img_x, $this->img_y, $val);
     }
 }
Ejemplo n.º 20
0
 public function watermark($dst_img, $logo, $image, $arrConfig = array())
 {
     $pct = isset($arrConfig['pct']) ? $arrConfig['pct'] : 100;
     $postion = isset($arrConfig['postion']) ? $arrConfig['postion'] : 'SouthEast';
     $intQuality = isset($arrConfig['quality']) ? $arrConfig['quality'] : 90;
     //压缩率
     switch ($postion) {
         case 'NorthWest':
             $x = 0;
             $y = 0;
             break;
             //西北
         //西北
         case 'NorthEast':
             $x = 100;
             $y = 0;
             break;
             //东北
         //东北
         case 'SouthWest':
             $x = 0;
             $y = 100;
             break;
             //西南
         //西南
         case 'SouthEast':
             $x = 100;
             $y = 100;
             break;
             //东南
     }
     list($dst_w, $dst_h, $dst_type) = getimagesize($dst_img);
     list($logo_w, $logo_h, $logo_type) = getimagesize($logo);
     $dst_x_max = $dst_w - $logo_w;
     $dst_y_max = $dst_h - $logo_h;
     //防止x坐标超出范围
     if ($x > 100 || $x == '') {
         $x = 100;
     } elseif ($x < 0) {
         $x = 0;
     }
     $x = intval($dst_x_max * $x / 100);
     //防止y坐标超出范围
     if ($y > 100 || $y == '') {
         $y = 100;
     } elseif ($y < 0) {
         $y = 0;
     }
     $y = intval($dst_y_max * $y / 100);
     //防止pct透明度超出范围
     if ($pct < 0) {
         $pct = 0;
     } else {
         $pct = 100;
     }
     if ($dst_type == 2) {
         $dst_img = imagecreatefromjpeg($dst_img);
     } elseif ($dst_type == 3) {
         $dst_img = imagecreatefrompng($dst_img);
     }
     if ($logo_type == 2) {
         $logo = imagecreatefromjpeg($logo);
     } elseif ($logo_type == 3) {
         $logo = imagecreatefrompng($logo);
     }
     imagecopymergegray($dst_img, $logo, $x, $y, 0, 0, $logo_w, $logo_h, $pct);
     imagejpeg($dst_img, $image, $intQuality);
 }
Ejemplo n.º 21
0
 public function grayscale()
 {
     $newImage = imagecreatetruecolor($this->width, $this->height);
     imagecopy($newImage, $this->image, 0, 0, 0, 0, $this->width, $this->height);
     imagecopymergegray($newImage, $newImage, 0, 0, 0, 0, $this->width, $this->height, 0);
     imagedestroy($this->image);
     $this->image = $newImage;
     return $this;
 }
Ejemplo n.º 22
0
 public function pasteImage($img, $point = array(0, 0), $alpha = 100)
 {
     if (!$this->checkImage()) {
         return false;
     }
     if (!$this->checkPoint($point)) {
         $point = array(0, 0);
     }
     if ($alpha <= 0) {
         return imagecopymergegray($this->img, $img, $point[0], $point[1], 0, 0, imagesx($img), imagesy($img), $alpha);
     } elseif ($alpha > 0 && $alpha <= 100) {
         return imagecopymerge($this->img, $img, $point[0], $point[1], 0, 0, imagesx($img), imagesy($img), $alpha);
     } else {
         return imagecopy($this->img, $img, $point[0], $point[1], 0, 0, imagesx($img), imagesy($img));
     }
 }
Ejemplo n.º 23
0
 /**
  * Converts an image into grayscale colors
  *
  * @access  public
  * @return  mixed True or Jaws_Error on error
  */
 function grayscale()
 {
     $res = imagecopymergegray($this->_hImage, $this->_hImage, 0, 0, 0, 0, $this->_img_w, $this->_img_h, 0);
     if (false === $res) {
         return Jaws_Error::raiseError('Failed transformation: grayscale().', __FUNCTION__);
     }
     return true;
 }
Ejemplo n.º 24
0
 /**
  * Passe une image en niveau de gris
  * @return true si l'image a bien été modifiée
  * @param object $fileAdresse
  * @param object $largeur
  * @param object $hauteur
  * @param object $fileSaveAdresse[optional]
  * @param object $jpeg_quality[optional]
  */
 public static function desaturation($fileAdresse, $largeur, $hauteur, $fileSaveAdresse = '', $jpeg_quality = '70')
 {
     if (empty($fileSaveAdresse)) {
         $fileSaveAdresse = $fileAdresse;
     }
     $image = SBImage::loadFromFile($fileAdresse);
     if ($image == false) {
         // Retour avec erreur pour non rechargement de l'image
         return false;
     }
     imagecopymergegray($image, $image, 0, 0, 0, 0, $largeur, $hauteur, 0);
     SBImage::saveIntoFile($image, $fileSaveAdresse, $jpeg_quality);
     return true;
 }
Ejemplo n.º 25
0
 static function copy(&$image, $picture, $mode, $param)
 {
     if ($mode == 1) {
         //拷贝
         return imagecopy($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5]);
     }
     if ($mode == 2) {
         //拷贝+合并
         return imagecopymerge($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6]);
     }
     if ($mode == 3) {
         //灰度拷贝+合并
         return imagecopymergegray($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6]);
     }
     if ($mode == 4) {
         //拷贝+调整大小
         return imagecopyresized($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6], $param[7]);
     }
     if ($mode == 5) {
         //采样+拷贝+调整大小
         return imagecopyresampled($image, $picture, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $param[6], $param[7]);
     }
 }
Ejemplo n.º 26
0
 public function mixGray($source = '', $settings = array())
 {
     if (!is_resource($source)) {
         Error::set(lang('Error', 'resourceParameter', '1.(source)'));
         return $this;
     }
     $xt = isset($settings['xt']) ? $settings['xt'] : 0;
     $yt = isset($settings['yt']) ? $settings['yt'] : 0;
     $xs = isset($settings['xs']) ? $settings['xs'] : 0;
     $ys = isset($settings['ys']) ? $settings['ys'] : 0;
     $width = isset($settings['width']) ? $settings['width'] : 0;
     $height = isset($settings['height']) ? $settings['height'] : 0;
     $percent = isset($settings['percent']) ? $settings['percent'] : 0;
     imagecopymergegray($this->canvas, $source, $xt, $yt, $xs, $ys, $width, $height, $percent);
     return $this;
 }