Example #1
1
 public static function translucentWatermark($originalImage, $watermark, $saveFile = null, $outputFileTipe = 'jpg')
 {
     $tempFolder = "temp/";
     //$fileRandomValue = 0;
     $cache = $tempFolder . $saveFile . '.' . $outputFileTipe;
     // Load the stamp and the photo to apply the watermark to
     if (strstr($originalImage, '.jpg') !== false) {
         $im = imagecreatefromjpeg($originalImage);
     } elseif (strstr($originalImage, '.png') !== false) {
         $im = imagecreatefrompng($originalImage);
     }
     // First we create our stamp image manually from GD
     $stamp = imagecreatetruecolor(100, 70);
     imagefilledrectangle($stamp, 0, 0, 99, 69, 0xff);
     imagefilledrectangle($stamp, 9, 9, 90, 60, 0xffffff);
     //$im = imagecreatefromjpeg('photo.jpeg');
     imagestring($stamp, 5, 20, 20, 'libGD', 0xff);
     imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0xff);
     // Set the margins for the stamp and get the height/width of the stamp image
     $marge_right = 10;
     $marge_bottom = 10;
     $sx = imagesx($stamp);
     $sy = imagesy($stamp);
     // Merge the stamp onto our photo with an opacity of 50%
     imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
     // Save the image to file and free memory
     imagepng($im, $cache);
     imagedestroy($im);
 }
Example #2
1
 /**
  * Overlay an image onto the current image.
  *
  * @param  string $image
  * @param  int    $x
  * @param  int    $y
  * @throws Exception
  * @return Gd
  */
 public function overlay($image, $x = 0, $y = 0)
 {
     imagealphablending($this->image->resource(), true);
     // Create an image resource from the overlay image.
     if (stripos($image, '.gif') !== false) {
         $overlay = imagecreatefromgif($image);
     } else {
         if (stripos($image, '.png') !== false) {
             $overlay = imagecreatefrompng($image);
         } else {
             if (stripos($image, '.jp') !== false) {
                 $overlay = imagecreatefromjpeg($image);
             } else {
                 throw new Exception('Error: The overlay image must be either a JPG, GIF or PNG.');
             }
         }
     }
     if ($this->opacity > 0) {
         if ($this->opacity == 100) {
             imagecopy($this->image->resource(), $overlay, $x, $y, 0, 0, imagesx($overlay), imagesy($overlay));
         } else {
             imagecopymerge($this->image->resource(), $overlay, $x, $y, 0, 0, imagesx($overlay), imagesy($overlay), $this->opacity);
         }
     }
     return $this;
 }
 /**
  * (non-PHPdoc)
  * @see \imagemanipulation\filter\IImageFilter::applyFilter()
  */
 public function applyFilter(ImageResource $resource)
 {
     if ($this->radius === 0) {
         return;
     }
     $source_image = $resource->getResource();
     $source_width = $resource->getX();
     $source_height = $resource->getY();
     $corner_image = imagecreatetruecolor($this->radius, $this->radius);
     $clear_colour = imagecolorallocate($corner_image, 0, 0, 0);
     imagecolortransparent($corner_image, $clear_colour);
     $solid_colour = imagecolorallocate($corner_image, $this->color->getRed(), $this->color->getGreen(), $this->color->getBlue());
     imagefill($corner_image, 0, 0, $solid_colour);
     imagefilledellipse($corner_image, $this->radius, $this->radius, $this->radius * 2, $this->radius * 2, $clear_colour);
     /*
      * render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask
      */
     imagecopymerge($source_image, $corner_image, 0, 0, 0, 0, $this->radius, $this->radius, 100);
     $corner_image = imagerotate($corner_image, 90, 0);
     imagecopymerge($source_image, $corner_image, 0, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100);
     $corner_image = imagerotate($corner_image, 90, 0);
     imagecopymerge($source_image, $corner_image, $source_width - $this->radius, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100);
     $corner_image = imagerotate($corner_image, 90, 0);
     imagecopymerge($source_image, $corner_image, $source_width - $this->radius, 0, 0, 0, $this->radius, $this->radius, 100);
 }
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $width = $aResource->getX();
     $height = $aResource->getY();
     $lineRes = imagecreatetruecolor($width, 1);
     $bgc = imagecolorallocatealpha($lineRes, $this->backgroundColor->getRed(), $this->backgroundColor->getGreen(), $this->backgroundColor->getBlue(), $this->backgroundColor->getAlpha());
     // Background color
     imagefilledrectangle($lineRes, 0, 0, $width, 1, $bgc);
     $rotateFilter = new ImageFilterRotate(180, $this->backgroundColor);
     $rotateFilter->applyFilter($aResource);
     $bg = imagecreatetruecolor($width, $this->height);
     imagecopyresampled($bg, $aResource->getResource(), 0, 0, 0, 0, $width, $height, $width, $height);
     $im = $bg;
     $bg = imagecreatetruecolor($width, $this->height);
     for ($x = 0; $x < $width; $x++) {
         imagecopy($bg, $im, $x, 0, $width - $x, 0, 1, $this->height);
     }
     $im = $bg;
     $in = 100 / $this->height;
     for ($i = 0; $i <= $this->height; $i++) {
         imagecopymerge($im, $lineRes, 0, $i, 0, 0, $width, 1, $this->startOpacity);
         if ($this->startOpacity < 100) {
             $this->startOpacity += $in;
         }
     }
     imagecopymerge($im, $lineRes, 0, 0, 0, 0, $width, $this->divLineHeight, 100);
     // Divider
     $aResource->setResource($im);
 }
Example #5
0
 public static function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct)
 {
     $cut = imagecreatetruecolor($src_w, $src_h);
     imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
     imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
     imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
 }
 function ApplyWatermark($watermark_path)
 {
     $this->watermark_path = $watermark_path;
     // Determine image size and type
     $size = getimagesize($this->image_path);
     $size_x = $size[0];
     $size_y = $size[1];
     $image_type = $size[2];
     // 1 = GIF, 2 = JPG, 3 = PNG
     // load source image
     $image = $this->ImageCreateFromType($image_type, $this->image_path);
     // Determine watermark size and type
     $wsize = getimagesize($watermark_path);
     $watermark_x = $wsize[0];
     $watermark_y = $wsize[1];
     $watermark_type = $wsize[2];
     // 1 = GIF, 2 = JPG, 3 = PNG
     // load watermark
     $watermark = $this->ImageCreateFromType($watermark_type, $watermark_path);
     // where do we put watermark on the image?
     $dest_x = $size_x - $watermark_x - $this->offset_x;
     $dest_y = $size_y - $watermark_y - $this->offset_y;
     imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_x, $watermark_y, 100);
     $this->image =& $image;
     $this->watermark =& $watermark;
     $this->image_type = $image_type;
 }
function hacknrollify($picfilename)
{
    $logofilename = "logo.png";
    $logoPicPath = "logopics/" . $logofilename;
    $originalPicPath = "originalpics/" . $picfilename;
    $editedfilename = "hnr_" . $picfilename;
    $editedPicPath = "editedpics/" . $editedfilename;
    // read the original image from file
    $profilepic = imagecreatefromjpeg($originalPicPath);
    $profilepicWidth = imagesx($profilepic);
    $profilepicHeight = imagesy($profilepic);
    // create the black image overlay
    $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
    imagecolorallocate($blackoverlay, 0, 0, 0);
    // then merge the black and profilepic
    imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
    imagedestroy($blackoverlay);
    // merge the resized logo
    $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
    imageAlphaBlending($logo, false);
    imageSaveAlpha($logo, true);
    $logoWidth = imagesx($logo);
    $logoHeight = imagesy($logo);
    $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
    $horizontalOffset = 40;
    imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
    $mergeSuccess = imagejpeg($profilepic, $editedPicPath);
    if (!$mergeSuccess) {
        echo "Image merge failed!";
    }
    imagedestroy($profilepic);
    imagedestroy($logo);
    return $editedPicPath;
}
 public function addWatermark($watermark)
 {
     if (!$this->gd) {
         return;
     }
     $newGD = imagecreatetruecolor($this->width, $this->height);
     // Preserves transparency between images
     imagealphablending($newGD, true);
     imagesavealpha($newGD, true);
     imagecopy($newGD, $this->gd, 0, 0, 0, 0, $this->width, $this->height);
     // Load the stamp and the photo to apply the watermark to
     $stamp = imagecreatefrompng($watermark->getFullPath());
     // Set the margins for the stamp and get the height/width of the stamp image
     $sx = imagesx($stamp);
     $sy = imagesy($stamp);
     //bang in the middle
     $dest_x = ceil($this->width / 2);
     $dest_x -= ceil($watermark->width / 2);
     $dest_y = ceil($this->height / 2);
     $dest_y -= ceil($watermark->width / 2);
     //be safe prevent negatives
     if ($dest_x < 0) {
         $dest_x = 0;
     }
     if ($dest_y < 0) {
         $dest_y = 0;
     }
     // SS_Log::log('dest x: '.$dest_x.' dest y: '.$dest_y, SS_Log::ERR);
     // Copy the stamp image onto our photo using the margin offsets and the photo
     // width to calculate positioning of the stamp.
     imagecopymerge($newGD, $stamp, $dest_x, $dest_y, 0, 0, imagesx($stamp), imagesy($stamp), 50);
     $output = clone $this;
     $output->setImageResource($newGD);
     return $output;
 }
Example #9
0
function make_captcha_img()
{
    global $CaptchaBGs;
    $Length = 6;
    $ImageHeight = 75;
    $ImageWidth = 300;
    $Chars = 'abcdefghjkmprstuvwxyzABCDEFGHJKLMPQRSTUVWXY23456789';
    $CaptchaString = '';
    for ($i = 0; $i < $Length; $i++) {
        $CaptchaString .= $Chars[mt_rand(0, strlen($Chars) - 1)];
    }
    for ($x = 0; $x < $Length; $x++) {
        $FontDisplay[$x]['size'] = mt_rand(24, 32);
        $FontDisplay[$x]['top'] = mt_rand($FontDisplay[$x]['size'] + 5, $ImageHeight - $FontDisplay[$x]['size'] / 2);
        $FontDisplay[$x]['angle'] = mt_rand(-30, 30);
        $FontDisplay[$x]['font'] = get_font();
    }
    $Img = imagecreatetruecolor($ImageWidth, $ImageHeight);
    $BGImg = imagecreatefrompng(SERVER_ROOT . '/captcha/' . $CaptchaBGs[mt_rand(0, count($CaptchaBGs) - 1)]);
    imagecopymerge($Img, $BGImg, 0, 0, 0, 0, 300, 75, 50);
    $ForeColor = imagecolorallocatealpha($Img, 255, 255, 255, 65);
    for ($i = 0; $i < strlen($CaptchaString); $i++) {
        $CharX = $ImageWidth / $Length * ($i + 1) - $ImageWidth / $Length * 0.75;
        imagettftext($Img, $FontDisplay[$i]['size'], $FontDisplay[$i]['angle'], $CharX, $FontDisplay[$i]['top'], $ForeColor, $FontDisplay[$i]['font'], $CaptchaString[$i]);
    }
    header('Content-type: image/png');
    imagepng($Img);
    imagedestroy($Img);
    return $CaptchaString;
}
Example #10
0
 /**
  * (non-PHPdoc)
  * @see \Simplify\Thumb\Plugin::process()
  */
 protected function process(\Simplify\Thumb\Processor $thumb, $overlayImage = null, $dst_x = 0, $dst_y = 0, $src_x = 0, $src_y = 0, $src_w = null, $src_h = null, $pct = 0)
 {
     $overlay = \Simplify\Thumb\Functions::load($overlayImage);
     $src_w = is_null($src_w) ? imagesx($overlay) : $src_w;
     $src_h = is_null($src_h) ? imagesy($overlay) : $src_h;
     imagecopymerge($thumb->image, $overlay, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct);
 }
Example #11
0
 public static function water($source, $water, $saveName = null, $pos = 0, $alpha = 80, $quality = 100)
 {
     if (!FileUtil::fileExists($source) || !FileUtil::fileExists($water)) {
         return false;
     }
     $sInfo = self::getImageInfo($source);
     $wInfo = self::getImageInfo($water);
     if ($sInfo["width"] < $wInfo["width"] || $sInfo["height"] < $wInfo["height"]) {
         return false;
     }
     $sCreateFunction = "imagecreatefrom" . $sInfo["type"];
     $sImage = $sCreateFunction($source);
     $wCreateFunction = "imagecreatefrom" . $wInfo["type"];
     $wImage = $wCreateFunction($water);
     imagealphablending($wImage, true);
     list($posX, $posY) = self::getPos($sInfo, $wInfo, $pos);
     if ($wInfo["type"] == "png") {
         imagecopy($sImage, $wImage, $posX, $posY, 0, 0, $wInfo["width"], $wInfo["height"]);
     } else {
         imagealphablending($wImage, true);
         imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo["width"], $wInfo["height"], $alpha);
     }
     $imageFun = "image" . $sInfo["type"];
     if (!$saveName) {
         $saveName = $source;
         @unlink($source);
     }
     if ($sInfo["mime"] == "image/jpeg") {
         $imageFun($sImage, $saveName, $quality);
     } else {
         $imageFun($sImage, $saveName);
     }
     imagedestroy($sImage);
     return true;
 }
Example #12
0
 /**
  * Method draws a collage from friends avatars.
  *
  * @param $x
  * @param $y
  * @return resource
  * @throws \Exception
  */
 public function drawCollage($x, $y)
 {
     $username = '******';
     $friends = $this->getFriendsList($username);
     $posX = 0;
     $posY = 0;
     if (!isset($x) && !isset($y)) {
         throw new \Exception("height and width must be set!");
     }
     $collage = imagecreatetruecolor($x, $y);
     while ($posY <= $y) {
         foreach ($friends['users'] as $user) {
             $image = imagecreatefromstring(file_get_contents($user['profile_image_url']));
             imagecopymerge($collage, $image, $posX, $posY, 5, 5, 50, 50, 100);
             $posX += 50;
             if ($posX >= $x) {
                 $posY += 50;
                 $posX = 0;
             }
             if ($posX >= $x && $posY >= $y) {
                 break;
             }
         }
     }
     return $collage;
 }
Example #13
0
 public static function water($dst, $water, $save = NULL, $pos = 2, $alpha = 50)
 {
     //先保证两个图片存在
     if (!file_exists($dst) || !file_exists($water)) {
         return false;
     }
     //首先保证水印不能比待操作图片大
     $dinfo = self::imageInfo($dst);
     $winfo = self::imageInfo($water);
     if ($winfo['height'] > $dinfo['height'] || $winfo['width'] > $dinfo['width']) {
         return false;
     }
     //两张图,读到画布上,但是图片可能是png,可能是jpeg,用什么函数读
     $dfunc = 'imagecreatefrom' . $dinfo['ext'];
     $wfunc = 'imagecreatefrom' . $winfo['ext'];
     if (!function_exists($dfunc) || !function_exists($wfunc)) {
         return false;
     }
     //动态加载函数来创建画布
     $dim = $dfunc($dst);
     //创建待操作画布
     $wim = $wfunc($water);
     // 创建水印画布
     //根据水印的位置,计算粘贴的坐标
     switch ($pos) {
         case 0:
             //左上角
             $posx = 0;
             $posy = 0;
             break;
         case 1:
             //右上角
             $posx = $dinfo['width'] - $winfo['width'];
             $posy = 0;
             break;
         case 3:
             //左下角
             $posx = 0;
             $posy = $dinfo['height'] - $winfo['height'];
             break;
         default:
             //右下角
             $posx = $dinfo['width'] - $winfo['width'];
             $posy = $dinfo['height'] - $winfo['height'];
             break;
     }
     //加水印
     imagecopymerge($dim, $wim, $posx, $posy, 0, 0, $winfo['width'], $winfo['height'], $alpha);
     //保存
     if (!$save) {
         $save = $dst;
         unlink($dst);
         //删除原图
     }
     $createfunc = 'image' . $dinfo['ext'];
     $createfunc($dim, $save);
     imagedestroy($dim);
     imagedestroy($wim);
     return true;
 }
Example #14
0
function create_watermark($source_file_path, $output_file_path)
{
    list($source_width, $source_height, $source_type) = getimagesize($source_file_path);
    if ($source_type === NULL) {
        return false;
    }
    switch ($source_type) {
        case IMAGETYPE_GIF:
            $source_gd_image = imagecreatefromgif($source_file_path);
            break;
        case IMAGETYPE_JPEG:
            $source_gd_image = imagecreatefromjpeg($source_file_path);
            break;
        case IMAGETYPE_PNG:
            $source_gd_image = imagecreatefrompng($source_file_path);
            break;
        default:
            return false;
    }
    $overlay_gd_image = imagecreatefrompng(WATERMARK_OVERLAY_IMAGE);
    $overlay_width = imagesx($overlay_gd_image);
    $overlay_height = imagesy($overlay_gd_image);
    imagecopymerge($source_gd_image, $overlay_gd_image, $source_width - $overlay_width, $source_height - $overlay_height, 0, 0, $overlay_width, $overlay_height, WATERMARK_OVERLAY_OPACITY);
    imagejpeg($source_gd_image, $output_file_path, WATERMARK_OUTPUT_QUALITY);
    imagedestroy($source_gd_image);
    imagedestroy($overlay_gd_image);
    //unlink($source_file_path);
}
 function by_lines($image, &$size_x, &$size_y)
 {
     $lines = array();
     $size_x = imagesx($image->get_handle());
     $size_y = imagesy($image->get_handle());
     $dest_img = imagecreatetruecolor($size_x, $size_y);
     imagecopymerge($dest_img, $image->get_handle(), 0, 0, 0, 0, $size_x, $size_y, 100);
     // initialize line length counter
     $ctr = 0;
     for ($y = 0; $y < $size_y; $y++) {
         $line = "";
         for ($x = 0; $x < $size_x; $x++) {
             // Save image pixel to the stream data
             $rgb = ImageColorAt($dest_img, $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $line .= sprintf("%02X%02X%02X", min(max($r, 0), 255), min(max($g, 0), 255), min(max($b, 0), 255));
             // Increate the line length counter; check if stream line needs to be terminated
             $ctr += 6;
             if ($ctr > MAX_LINE_LENGTH) {
                 $line .= "\n";
                 $ctr = 0;
             }
         }
         $lines[] = $line;
     }
     return $lines;
 }
Example #16
0
 function background()
 {
     $im = imagecreatetruecolor($this->width, $this->height);
     $bgs = array();
     if ($this->style & 8 && function_exists('imagecreatefromjpeg') && function_exists('imagecopymerge')) {
         if ($fp = @opendir($GLOBALS['imgdir'] . '/ck/bg/')) {
             while ($flie = @readdir($fp)) {
                 if (preg_match('/\\.jpg$/i', $flie)) {
                     $bgs[] = $GLOBALS['imgdir'] . '/ck/bg/' . $flie;
                 }
             }
             @closedir($fp);
         }
     }
     if ($bgs) {
         $imbg = imagecreatefromjpeg($bgs[array_rand($bgs)]);
         imagecopymerge($im, $imbg, 0, 0, mt_rand(0, 200 - $this->width), mt_rand(0, 80 - $this->height), $this->width, $this->height, 100);
         imagedestroy($imbg);
     } else {
         $c = array();
         for ($i = 0; $i < 3; $i++) {
             $c[$i] = mt_rand(200, 255);
             $step[$i] = (mt_rand(100, 150) - $c[$i]) / $this->width;
         }
         for ($i = 0; $i < $this->width; $i++) {
             imageline($im, $i, 0, $i, $this->height, imagecolorallocate($im, $c[0], $c[1], $c[2]));
             $c[0] += $step[0];
             $c[1] += $step[1];
             $c[2] += $step[2];
         }
     }
     return $im;
 }
 public function reflect()
 {
     $transparency_step = (100 - $this->transparency) / $this->gradient_height;
     $background = imagecreatetruecolor($this->imgWidth, $this->gradient_height + $this->imgHeight);
     $gdGradientColor = ImageColorAllocate($background, 255, 255, 255);
     $newImage = imagecreatetruecolor($this->imgWidth, $this->imgHeight);
     for ($x = 0; $x < $this->imgWidth; $x++) {
         for ($y = 0; $y < $this->imgHeight; $y++) {
             imagecopy($newImage, $this->img, $x, $this->imgHeight - $y - 1, $x, $y, 1, 1);
         }
     }
     imagecopymerge($background, $newImage, 0, $this->imgHeight, 0, 0, $this->imgWidth, $this->imgHeight, 100);
     imagecopymerge($background, $this->img, 0, 0, 0, 0, $this->imgWidth, $this->imgHeight, 100);
     $gradient_line = imagecreatetruecolor($this->imgWidth, 1);
     //voir si on garde ça et la suite
     // Next we draw a GD line into our gradient_line
     imageline($gradient_line, 0, 0, $this->imgWidth, 0, $gdGradientColor);
     for ($i = $this->imgHeight; $i < $this->gradient_height + $this->imgHeight; $i++) {
         imagecopymerge($background, $gradient_line, 0, $i, 0, 0, $this->imgWidth, 1, $this->transparency);
         if ($this->transparency != 100) {
             $this->transparency += $transparency_step;
         }
     }
     $this->img = $background;
 }
Example #18
0
 /**
  * 图片打水印
  *
  * @param string $sourceImage 源图片
  * @param string $waterMarkImage 水印
  * @param null|string $saveName 保存路径,默认为覆盖原图
  * @param int $alpha 水印透明度
  * @param null $positionW 水印位置 相对原图横坐标
  * @param null $positionH 水印位置 相对原图纵坐标
  * @param int $quality 生成的图片的质量 jpeg有效
  *
  * @return mixed
  */
 public static function addWaterMark($sourceImage, $waterMarkImage, $saveName = null, $alpha = 80, $positionW = null, $positionH = null, $quality = 100)
 {
     if (!is_file($sourceImage) || !is_file($waterMarkImage)) {
         return false;
     }
     //获取图片信息
     $sourceImageInfo = self::getImageInfo($sourceImage);
     $waterMarkImageInfo = self::getImageInfo($waterMarkImage);
     if ($sourceImageInfo['width'] < $waterMarkImageInfo['width'] || $sourceImageInfo['height'] < $waterMarkImageInfo['height'] || $sourceImageInfo['ext'] == 'bmp' || $waterMarkImageInfo['bmp']) {
         return false;
     }
     //创建图像
     $sourceImageCreateFunc = "imagecreatefrom{$sourceImageInfo['ext']}";
     $sourceCreateImage = $sourceImageCreateFunc($sourceImage);
     $waterMarkImageCreateFunc = "imagecreatefrom{$waterMarkImageInfo['ext']}";
     $waterMarkCreateImage = $waterMarkImageCreateFunc($waterMarkImage);
     //设置混色模式
     imagealphablending($waterMarkImage, true);
     $posX = is_null($positionW) ? $sourceImageInfo['width'] - $waterMarkImageInfo['width'] : $sourceImageInfo['width'] - $positionW;
     $posY = is_null($positionH) ? $sourceImageInfo['height'] - $waterMarkImageInfo['height'] : $sourceImageInfo['height'] - $positionH;
     //生成混合图像
     imagecopymerge($sourceCreateImage, $waterMarkCreateImage, $posX, $posY, 0, 0, $waterMarkImageInfo['width'], $waterMarkImageInfo['height'], $alpha);
     //生成处理后的图像
     if (is_null($saveName)) {
         $saveName = $sourceImage;
         @unlink($sourceImage);
     }
     self::output($sourceCreateImage, $sourceImageInfo['ext'], $saveName, $quality);
     return true;
 }
 function download()
 {
     global $STYLE;
     if (!isset($_GET["id"])) {
         throw new Exception("No 'id' or 'name' param provided.");
     }
     /* call get_document.php to get the image */
     ob_start();
     include 'get_document.php';
     $data = ob_get_contents();
     ob_end_clean();
     if (ENABLE_IMAGE_WATERMARKING) {
         /* create a gd object from data */
         $im = @imagecreatefromstring($data);
         if (!$im) {
             throw new Exception("Ressource is not an image!");
         } else {
             /* Watermark settings - Implement a company specifil logo here later. */
             $transition = 85;
             $watermarkfile = imagecreatefrompng(PATH_PUBLIC . 'styles/' . $STYLE . '/images/logo_bdz.png');
             //TODO: Change the path here!
             $waternarkpic_width = imagesx($watermarkfile);
             $waternarkpic_height = imagesy($watermarkfile);
             $watermarkdest_x = 15;
             $watermarkdest_y = 15;
             imagecopymerge($im, $watermarkfile, $watermarkdest_x, $watermarkdest_y, 0, 0, $waternarkpic_width, $waternarkpic_height, $transition);
             imagejpeg($im);
         }
     } else {
         echo $data;
     }
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 protected function execute(array $arguments)
 {
     if ($arguments['opacity'] === 100) {
         // Use imagecopy() if watermark opacity is 100%.
         return imagecopy($this->getToolkit()->getResource(), $arguments['watermark_image']->getToolkit()->getResource(), $arguments['x_offset'], $arguments['y_offset'], 0, 0, $arguments['watermark_image']->getToolkit()->getWidth(), $arguments['watermark_image']->getToolkit()->getHeight());
     } else {
         // If opacity is below 100%, use the approach described in
         // http://php.net/manual/it/function.imagecopymerge.php#92787
         // to preserve watermark alpha.
         // Create a cut resource.
         // @todo when #2583041 is committed, add a check for memory
         // availability before crating the resource.
         $cut = imagecreatetruecolor($arguments['watermark_image']->getToolkit()->getWidth(), $arguments['watermark_image']->getToolkit()->getHeight());
         if (!is_resource($cut)) {
             return FALSE;
         }
         // Copy relevant section from destination image to the cut resource.
         $success = imagecopy($cut, $this->getToolkit()->getResource(), 0, 0, $arguments['x_offset'], $arguments['y_offset'], $arguments['watermark_image']->getToolkit()->getWidth(), $arguments['watermark_image']->getToolkit()->getHeight());
         if (!$success) {
             imagedestroy($cut);
             return FALSE;
         }
         // Copy relevant section from watermark image to the cut resource.
         $success = imagecopy($cut, $arguments['watermark_image']->getToolkit()->getResource(), 0, 0, 0, 0, $arguments['watermark_image']->getToolkit()->getWidth(), $arguments['watermark_image']->getToolkit()->getHeight());
         if (!$success) {
             imagedestroy($cut);
             return FALSE;
         }
         // Insert cut resource to destination image.
         $success = imagecopymerge($this->getToolkit()->getResource(), $cut, $arguments['x_offset'], $arguments['y_offset'], 0, 0, $arguments['watermark_image']->getToolkit()->getWidth(), $arguments['watermark_image']->getToolkit()->getHeight(), $arguments['opacity']);
         imagedestroy($cut);
         return $success;
     }
 }
Example #21
0
 /**
  * Function copied from: http://www.php.net/manual/en/function.imagecopymerge.php#92787
  * Does the same as "imagecopymerge" but preserves the alpha-channel
  */
 protected function imageCopyMergeAlpha(&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct)
 {
     $cut = imagecreatetruecolor($src_w, $src_h);
     imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
     imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
     imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct);
 }
Example #22
0
function watermarkImage($SourceFile, $WaterMark, $DestinationFile = NULL, $opacity)
{
    $main_img = $SourceFile;
    $watermark_img = $WaterMark;
    $padding = 3;
    $opacity = $opacity;
    $watermark = imagecreatefromgif($watermark_img);
    // create watermark
    $image = imagecreatefromjpeg($main_img);
    // create main graphic
    if (!$image || !$watermark) {
        die("Error: main image or watermark could not be loaded!");
    }
    $watermark_size = getimagesize($watermark_img);
    $watermark_width = $watermark_size[0];
    $watermark_height = $watermark_size[1];
    $image_size = getimagesize($main_img);
    $dest_x = $image_size[0] - $watermark_width - $padding;
    $dest_y = $image_size[1] - $watermark_height - $padding;
    // copy watermark on main image
    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $opacity);
    if ($DestinationFile != '') {
        imagejpeg($image, $DestinationFile, 100);
    } else {
        header('Content-Type: image/jpeg');
        imagejpeg($image);
    }
    imagedestroy($image);
    imagedestroy($watermark);
}
Example #23
0
 public static function water($dst, $water, $save = NULL, $alpha = 50, $pos = 2)
 {
     //首先得保证两个图片存在
     if (!file_exists($dst) || !file_exists($water)) {
         return false;
     }
     //保证水印不能比待操作图片大
     $dstInfo = self::imageInfo($dst);
     $waterInfo = self::imageInfo($water);
     if ($waterInfo["height"] > $dstInfo["height"] || $waterInfo["width"] > $dstInfo["width"]) {
         return false;
     }
     //两张图得读到画布上,但是图片可能是png 也可能是jpeg 用什么函数读?
     $dstFunc = "imagecreatefrom" . $dstInfo["ext"];
     $waterFunc = "imagecreatefrom" . $waterInfo["ext"];
     if (!function_exists($dstFunc) || !function_exists($waterFunc)) {
         return false;
     }
     //动态加载函数来创建画布
     $dstImg = $dstFunc($dst);
     //创建待操作的画布
     $waterImg = $waterFunc($water);
     //创建水印画布
     //根据水印位置 计算粘贴的坐标
     switch ($pos) {
         case 0:
             //左上角
             $posx = 0;
             $posy = 0;
             break;
         case 1:
             //右上角
             $posx = $dstInfo["width"] - $waterInfo["width"];
             $posy = 0;
             break;
         case 3:
             //左下角
             $posx = 0;
             $posy = $dstInfo["height"] - $waterInfo["height"];
             break;
         default:
             $posx = $dstInfo["width"] - $waterInfo["width"];
             $posy = $dstInfo["height"] - $waterInfo["height"];
     }
     //加水印
     imagecopymerge($dstImg, $waterImg, $posx, $posy, 0, 0, $waterInfo["width"], $waterInfo["height"], $alpha);
     //保存
     if (!$save) {
         $save = $dst;
         unlink($dst);
         //删掉原图
     }
     $createFunc = "image" . $dstInfo["ext"];
     $createFunc($dstImg, $save);
     //释放图片资源
     imagedestroy($dstImg);
     imagedestroy($waterImg);
     return true;
 }
function getImgs($url)
{
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
    $html = curl_exec($curl);
    preg_match_all("/<img .*>/", $html, $r);
    $tmp = array();
    $format = array("png", "jpg", "jpeg");
    foreach ($r[0] as $key => $value) {
        preg_match("/src=[\\'|\"]([^\\'|\"]*)/", $value, $urlImg);
        if ($urlImg) {
            $urlImg = $urlImg[1];
            if (!preg_match("/^http/", $urlImg)) {
                if (preg_match("/^\\/{2}/", $urlImg)) {
                    $urlImg = "http:" . $urlImg;
                } elseif (preg_match("/^\\//", $urlImg)) {
                    preg_match("/^(http:\\/\\/|https:\\/\\/)([^\\/]*)/", $url, $t);
                    $urlImg = $t[0] . $urlImg;
                }
            }
            preg_match("/\\.([^\\.]*)\$/", $urlImg, $r);
            if (!isset($r[1])) {
                continue;
            }
            $currentFormat = strtolower($r[1]);
            if (in_array($currentFormat, $format)) {
                if ($currentFormat == "png") {
                    $im = imagecreatefrompng($urlImg);
                } else {
                    $im = imagecreatefromjpeg($urlImg);
                }
                // Tout d'abord, nous créons un cachet manuellement grâce à GD
                $stamp = imagecreatetruecolor(100, 70);
                imagefilledrectangle($stamp, 0, 0, 99, 69, 0xff);
                imagefilledrectangle($stamp, 9, 9, 90, 60, 0xffffff);
                imagestring($stamp, 5, 20, 20, 'WAOOOW', 0xff);
                imagestring($stamp, 3, 20, 40, 'MVOOOM', 0xff);
                // Définit les marges du cachet et récupère la largeur et la hauteur du cachet
                $marge_right = 10;
                $marge_bottom = 10;
                $sx = imagesx($stamp);
                $sy = imagesy($stamp);
                // Fusionne le cachet dans notre photo avec une opacité de 50%
                imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
                // Sauvegarde l'image dans un fichier et libère la mémoire
                ob_start();
                imagejpeg($im);
                // no second parameter, will do output instead of writing to file
                $imgTransform = ob_get_clean();
                $tmp[] = base64_encode($imgTransform);
                imagedestroy($im);
            } else {
                continue;
            }
        }
    }
    return $tmp;
}
Example #25
0
function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct)
{
    // function patch for respecting alpha work find on http://php.net/manual/fr/function.imagecopymerge.php
    $cut = imagecreatetruecolor($src_w, $src_h);
    imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
    imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
    imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
}
Example #26
0
 public function imagemark($water_url, $local, $alpha)
 {
     $info2 = getimagesize($water_url);
     $info2 = array('width' => $info2[0], 'height' => $info2[1], 'type' => image_type_to_extension($info2[2], false), 'mime' => $info2['mime']);
     $fun2 = "imagecreatefrom{$info2['type']}";
     $water = $fun2($water_url);
     imagecopymerge($this->image, $water, $local['x'], $local['y'], 0, 0, $info2['width'], $info2['height'], $alpha);
     imagedestroy($water);
 }
function show_image($coords)
{
    $ref = imagecreatefrompng('options3.png');
    $loc = imagecreatefrompng('crosshair.png');
    $white = imagecolorallocate($loc, 255, 255, 255);
    imagecolortransparent($loc, $white);
    imagecopymerge($ref, $loc, 310 - imagesx($loc) / 2 + 10 * $coords['x'], 310 - imagesy($loc) / 2 - 10 * $coords['y'], 0, 0, imagesx($loc), imagesy($loc), 100);
    imagepng($ref);
}
Example #28
0
 public function imageMark($source, $local, $alpha)
 {
     $infoMark = getimagesize($source);
     $MarkType = image_type_to_extension($infoMark[2], false);
     $fun2 = "imagecreatefrom{$MarkType}";
     $Mark = $fun2($source);
     imagecopymerge($this->image, $Mark, $local['x'], $local['y'], 0, 0, $infoMark[0], $infoMark[1], $alpha);
     imagedestroy($Mark);
 }
Example #29
0
 function background()
 {
     $this->im = imagecreatetruecolor($this->width, $this->height);
     $backgrounds = $c = array();
     if ($this->background && function_exists('imagecreatefromjpeg') && function_exists('imagecolorat') && function_exists('imagecopymerge') && function_exists('imagesetpixel') && function_exists('imageSX') && function_exists('imageSY')) {
         if ($handle = @opendir(PUBLIC_ROOT . './verify/background/')) {
             while ($bgfile = @readdir($handle)) {
                 if (preg_match('/\\.jpg$/i', $bgfile)) {
                     $backgrounds[] = PUBLIC_ROOT . './verify/background/' . $bgfile;
                 }
             }
             @closedir($handle);
         }
         if ($backgrounds) {
             $imwm = imagecreatefromjpeg($backgrounds[array_rand($backgrounds)]);
             $colorindex = imagecolorat($imwm, 0, 0);
             $c = imagecolorsforindex($imwm, $colorindex);
             $colorindex = imagecolorat($imwm, 1, 0);
             imagesetpixel($imwm, 0, 0, $colorindex);
             $c[0] = $c['red'];
             $c[1] = $c['green'];
             $c[2] = $c['blue'];
             imagecopymerge($this->im, $imwm, 0, 0, mt_rand(0, 200 - $this->width), mt_rand(0, 80 - $this->height), imageSX($imwm), imageSY($imwm), 100);
             imagedestroy($imwm);
         }
     }
     if (!$this->background || !$backgrounds) {
         for ($i = 0; $i < 3; $i++) {
             $start[$i] = mt_rand(200, 255);
             $end[$i] = mt_rand(100, 150);
             $step[$i] = ($end[$i] - $start[$i]) / $this->width;
             $c[$i] = $start[$i];
         }
         for ($i = 0; $i < $this->width; $i++) {
             $color = imagecolorallocate($this->im, $c[0], $c[1], $c[2]);
             imageline($this->im, $i, 0, $i, $this->height, $color);
             $c[0] += $step[0];
             $c[1] += $step[1];
             $c[2] += $step[2];
         }
         $c[0] -= 20;
         $c[1] -= 20;
         $c[2] -= 20;
     }
     ob_start();
     if (function_exists('imagepng')) {
         imagepng($this->im);
     } else {
         imagejpeg($this->im, '', 100);
     }
     imagedestroy($this->im);
     $bgcontent = ob_get_contents();
     ob_end_clean();
     $this->fontcolor = $c;
     return $bgcontent;
 }
 /**
  * (non-PHPdoc)
  * @see \imagemanipulation\filter\IImageFilter::applyFilter()
  */
 public function applyFilter(ImageResource $aResource)
 {
     $placeholder = imagecreatetruecolor($aResource->getX(), $aResource->getY());
     imagealphablending($placeholder, false);
     imagesavealpha($placeholder, true);
     $destWidth = $this->fill ? $aResource->getX() : $this->overlay->getX();
     $destHeight = $this->fill ? $aResource->getY() : $this->overlay->getY();
     imagecopyresized($placeholder, $this->overlay->getResource(), 0, 0, 0, 0, $destWidth, $destHeight, $this->overlay->getX(), $this->overlay->getY());
     imagecopymerge($aResource->getResource(), $placeholder, $this->startX, $this->startY, 0, 0, $destWidth, $destHeight, $this->opacity);
 }