示例#1
0
function test_composite(&$canvas)
{
    $draw = new ImagickDraw();
    $fblogo = new Imagick(__DIR__ . '/facebook.png');
    $draw->composite(Imagick::COMPOSITE_ATOP, 1, 1, 175, 50, $fblogo);
    $canvas->drawImage($draw);
}
示例#2
0
 public function renderImage()
 {
     //Create a ImagickDraw object to draw into.
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     //http://www.imagemagick.org/Usage/compose/#compose_terms
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor('white');
     $draw->setStrokeWidth(2);
     $draw->setFontSize(72);
     $draw->setStrokeOpacity(1);
     $draw->setStrokeColor($darkColor);
     $draw->setStrokeWidth(2);
     $draw->setFont("../fonts/CANDY.TTF");
     $draw->setFontSize(140);
     $draw->setFillColor('none');
     $draw->rectangle(0, 0, 1000, 300);
     $draw->setFillColor('white');
     $draw->annotation(50, 180, "Lorem Ipsum!");
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
     //Create an image object which the draw commands can be rendered into
     $imagick = new \Imagick();
     $imagick->newImage(1000, 300, "SteelBlue2");
     $imagick->setImageFormat("png");
     //Render the draw commands in the ImagickDraw object
     //into the image.
     $imagick->drawImage($draw);
     //Send the image to the browser
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
示例#3
0
 public function watermark($waterImage, $pos = 5, $Opacity = 0.2)
 {
     $water = new \Imagick($waterImage);
     $water->setImageOpacity($Opacity);
     $dw = new \ImagickDraw();
     $dw->setGravity($pos);
     $dw->composite($water->getImageCompose(), 0, 0, 50, 0, $water);
     $this->_handle->drawImage($dw);
     $water->destroy();
     $dw->destroy();
 }
示例#4
0
 function renderImage()
 {
     //Create a ImagickDraw object to draw into.
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     //http://www.imagemagick.org/Usage/compose/#compose_terms
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor('white');
     $draw->setStrokeWidth(2);
     $draw->setFontSize(72);
     $draw->setStrokeOpacity(1);
     $draw->setStrokeColor($darkColor);
     $draw->setStrokeWidth(2);
     $draw->setFont("../fonts/CANDY.TTF");
     $draw->setFontSize(140);
     $draw->setFillColor('none');
     $draw->rectangle(0, 0, 1000, 300);
     $draw->setFillColor('white');
     $draw->annotation(50, 180, "Lorem Ipsum!");
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     //        $compositeModes = [
     //
     //            \Imagick::COMPOSITE_NO, \Imagick::COMPOSITE_ADD, \Imagick::COMPOSITE_ATOP, \Imagick::COMPOSITE_BLEND, \Imagick::COMPOSITE_BUMPMAP, \Imagick::COMPOSITE_CLEAR, \Imagick::COMPOSITE_COLORBURN, \Imagick::COMPOSITE_COLORDODGE, \Imagick::COMPOSITE_COLORIZE, \Imagick::COMPOSITE_COPYBLACK, \Imagick::COMPOSITE_COPYBLUE, \Imagick::COMPOSITE_COPY, \Imagick::COMPOSITE_COPYCYAN, \Imagick::COMPOSITE_COPYGREEN, \Imagick::COMPOSITE_COPYMAGENTA, \Imagick::COMPOSITE_COPYOPACITY, \Imagick::COMPOSITE_COPYRED, \Imagick::COMPOSITE_COPYYELLOW, \Imagick::COMPOSITE_DARKEN, \Imagick::COMPOSITE_DSTATOP, \Imagick::COMPOSITE_DST, \Imagick::COMPOSITE_DSTIN, \Imagick::COMPOSITE_DSTOUT, \Imagick::COMPOSITE_DSTOVER, \Imagick::COMPOSITE_DIFFERENCE, \Imagick::COMPOSITE_DISPLACE, \Imagick::COMPOSITE_DISSOLVE, \Imagick::COMPOSITE_EXCLUSION, \Imagick::COMPOSITE_HARDLIGHT, \Imagick::COMPOSITE_HUE, \Imagick::COMPOSITE_IN, \Imagick::COMPOSITE_LIGHTEN, \Imagick::COMPOSITE_LUMINIZE, \Imagick::COMPOSITE_MINUS, \Imagick::COMPOSITE_MODULATE, \Imagick::COMPOSITE_MULTIPLY, \Imagick::COMPOSITE_OUT, \Imagick::COMPOSITE_OVER, \Imagick::COMPOSITE_OVERLAY, \Imagick::COMPOSITE_PLUS, \Imagick::COMPOSITE_REPLACE, \Imagick::COMPOSITE_SATURATE, \Imagick::COMPOSITE_SCREEN, \Imagick::COMPOSITE_SOFTLIGHT, \Imagick::COMPOSITE_SRCATOP, \Imagick::COMPOSITE_SRC, \Imagick::COMPOSITE_SRCIN, \Imagick::COMPOSITE_SRCOUT, \Imagick::COMPOSITE_SRCOVER, \Imagick::COMPOSITE_SUBTRACT, \Imagick::COMPOSITE_THRESHOLD, \Imagick::COMPOSITE_XOR,
     //
     //        ];
     $draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
     //Create an image object which the draw commands can be rendered into
     $imagick = new \Imagick();
     $imagick->newImage(1000, 300, "SteelBlue2");
     $imagick->setImageFormat("png");
     //Render the draw commands in the ImagickDraw object
     //into the image.
     $imagick->drawImage($draw);
     //Send the image to the browser
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
示例#5
0
 public function water($source, $locate = THINKIMAGE_WATER_SOUTHEAST)
 {
     if (empty($this->img)) {
         throw new Exception("没有可以被添加水印的图像资源");
     }
     if (!is_file($source)) {
         throw new Exception("水印图像不存在");
     }
     $water = new Imagick(realpath($source));
     $info = array($water->getImageWidth(), $water->getImageHeight());
     switch ($locate) {
         case THINKIMAGE_WATER_SOUTHEAST:
             $x = $this->info["width"] - $info[0];
             $y = $this->info["height"] - $info[1];
             break;
         case THINKIMAGE_WATER_SOUTHWEST:
             $x = 0;
             $y = $this->info["height"] - $info[1];
             break;
         case THINKIMAGE_WATER_NORTHWEST:
             $x = $y = 0;
             break;
         case THINKIMAGE_WATER_NORTHEAST:
             $x = $this->info["width"] - $info[0];
             $y = 0;
             break;
         case THINKIMAGE_WATER_CENTER:
             $x = ($this->info["width"] - $info[0]) / 2;
             $y = ($this->info["height"] - $info[1]) / 2;
             break;
         case THINKIMAGE_WATER_SOUTH:
             $x = ($this->info["width"] - $info[0]) / 2;
             $y = $this->info["height"] - $info[1];
             break;
         case THINKIMAGE_WATER_EAST:
             $x = $this->info["width"] - $info[0];
             $y = ($this->info["height"] - $info[1]) / 2;
             break;
         case THINKIMAGE_WATER_NORTH:
             $x = ($this->info["width"] - $info[0]) / 2;
             $y = 0;
             break;
         case THINKIMAGE_WATER_WEST:
             $x = 0;
             $y = ($this->info["height"] - $info[1]) / 2;
             break;
         default:
             if (is_array($locate)) {
                 $y = $locate[1];
                 $x = $locate[0];
             } else {
                 throw new Exception("不支持的水印位置类型");
             }
     }
     $draw = new ImagickDraw();
     $draw->composite($water->getImageCompose(), $x, $y, $info[0], $info[1], $water);
     if ("gif" == $this->info["type"]) {
         $img = $this->img->coalesceImages();
         $this->img->destroy();
         do {
             $img->drawImage($draw);
         } while ($img->nextImage());
         $this->img = $img->deconstructImages();
         $img->destroy();
     } else {
         $this->img->drawImage($draw);
     }
     $draw->destroy();
     $water->destroy();
 }
示例#6
0
 function __construct($chemin)
 {
     if (filter_var($chemin, FILTER_VALIDATE_URL)) {
         //URL
         $headers = @get_headers($chemin);
         if (strpos($headers[0], '404') != false) {
             //NOT FOUND
             //throw new \Exception("Not Found Image");
             $this->image = new \Imagick();
             $this->image->newImage(600, 600, new \ImagickPixel('white'));
             /* Création d'un nouvel objet imagick */
             $im = new \Imagick();
             /* Création d'une nouvelle image. Elle sera utilisée comme masque de remplissage */
             $im->newPseudoImage(50, 100, "gradient:gray-black");
             /* Création d'un nouvel objet imagickdraw */
             $draw = new \ImagickDraw();
             /* On commence un nouveau masque nommé "gradient" */
             $draw->pushPattern('gradient', 0, 0, 50, 110);
             /* Ajout du dégradé sur le masque */
             $draw->composite(\Imagick::COMPOSITE_OVER, 0, 0, 50, 110, $im);
             /* Fermeture du masque */
             $draw->popPattern();
             /* Utilisation du masque nommé "gradient" comme remplissage */
             $draw->setFillPatternURL('#gradient');
             /* Définition de la taille du texte à 52 */
             $draw->setFontSize(92);
             $draw->setFont(ROOT . DS . 'font/comic.ttf');
             /* Ajout d'un texte */
             $draw->annotation(20, 100, "Not Found !");
             $this->image->drawImage($draw);
         }
     } else {
         if (!file_exists($chemin)) {
             //throw new \Exception("Not Found Image");
             $this->image = new \Imagick();
             $this->image->newImage(600, 600, new \ImagickPixel('white'));
             /* Création d'un nouvel objet imagick */
             $im = new \Imagick();
             /* Création d'une nouvelle image. Elle sera utilisée comme masque de remplissage */
             $im->newPseudoImage(50, 100, "gradient:gray-black");
             /* Création d'un nouvel objet imagickdraw */
             $draw = new \ImagickDraw();
             /* On commence un nouveau masque nommé "gradient" */
             $draw->pushPattern('gradient', 0, 0, 50, 110);
             /* Ajout du dégradé sur le masque */
             $draw->composite(\Imagick::COMPOSITE_OVER, 0, 0, 50, 110, $im);
             /* Fermeture du masque */
             $draw->popPattern();
             /* Utilisation du masque nommé "gradient" comme remplissage */
             $draw->setFillPatternURL('#gradient');
             /* Définition de la taille du texte à 52 */
             $draw->setFontSize(92);
             $draw->setFont(ROOT . DS . 'font/comic.ttf');
             /* Ajout d'un texte */
             $draw->annotation(20, 100, "Not Found !");
             $this->image->drawImage($draw);
         }
     }
     $this->image = new \Imagick($chemin);
     $imageprops = $this->image->getImageGeometry();
     $this->width = $imageprops['width'];
     $this->height = $imageprops['height'];
     $this->image->setImageFormat("jpeg");
 }
 if (!$am) {
     echo "图片压缩失败!";
 } else {
     $im_get = new \Imagick($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name'] . '/' . $lspatharr[0] . '-' . $v['updateid'] . '.' . $lspatharr[1]);
     $im_sta = $im_get->getImageColorspace();
     if (2 == $im_sta) {
         list($bg_width, $bg_height) = getimagesize($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name'] . '/' . $lspatharr[0] . '-' . $v['updateid'] . '.' . $lspatharr[1]);
         $bg_width -= 2;
         $bg_height -= 2;
         $imm = new \Imagick();
         $imm->newImage(2, 2, new \ImagickPixel('#FFFFFE'));
         $im_get->setImageColorSpace(1);
         $dww = new \ImagickDraw();
         $dww->setGravity(5);
         $dww->setFillOpacity(0.1);
         $dww->composite($imm->getImageCompose(), -$bg_width / 2, $bg_height / 2, 0, 0, $imm);
         $im_get->drawImage($dww);
         $im_get->writeImage($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name'] . '/' . $lspatharr[0] . '-' . $v['updateid'] . '.' . $lspatharr[1]);
     }
     $im_get->clear();
     $im_get->destroy();
     $query_update = "UPDATE hb_orders_goods SET diy_print_path='/Uploads/" . $YMD . "/" . $v['cate_id'] . "/" . $v['attri_name'] . "/" . $lspatharr[0] . "-" . $v['updateid'] . "." . $lspatharr[1] . "' WHERE id=" . $v['updateid'];
     $result = mysql_query($query_update);
     $filename = $path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name'] . '/' . $lspatharr[0] . '-' . $v['updateid'] . '.' . $lspatharr[1];
     $file = file_get_contents($filename);
     //数据块长度为9
     $len = pack("N", 9);
     //数据块类型标志为pHYs
     $sign = pack("A*", "pHYs");
     //X方向和Y方向的分辨率均为300DPI(1像素/英寸=39.37像素/米),单位为米(0为未知,1为米)
     $data = pack("NNC", 72 * 39.37, 72 * 39.37, 0x1);
示例#8
0
 /**
  * 加给图片加水印
  *
  * @param strimg $groundImage 要加水印地址
  * @param int $waterPos 水印位置
  * @param string $waterImage 水印图片地址
  * @param string $waterText 文本文字
  * @param int $textFont 文字大小
  * @param string $textColor 文字颜色
  * @param int $minWidth 小于此值不加水印
  * @param int $minHeight 小于此值不加水印
  * @param float $alpha 透明度
  * @return FALSE
  */
 public static function waterMark($groundImage, $waterPos = 0, $waterImage = "", $waterText = "", $textFont = 15, $textColor = "#FF0000", $minWidth = '100', $minHeight = '100', $alpha = 0.9)
 {
     $isWaterImg = FALSE;
     $bg_h = $bg_w = $water_h = $water_w = 0;
     //获取背景图的高,宽
     if (is_file($groundImage) && !empty($groundImage)) {
         $bg = new Imagick();
         $bg->readImage($groundImage);
         $bg_h = $bg->getImageHeight();
         $bg_w = $bg->getImageWidth();
     }
     //获取水印图的高,宽
     if (is_file($waterImage) && !empty($waterImage)) {
         $water = new Imagick($waterImage);
         $water_h = $water->getImageHeight();
         $water_w = $water->getImageWidth();
     }
     //如果背景图的高宽小于水印图的高宽或指定的高和宽则不加水印
     if ($bg_h < $minHeight || $bg_w < $minWidth || $bg_h < $water_h || $bg_w < $water_w) {
         return;
     } else {
         $isWaterImg = TRUE;
     }
     //加水印
     if ($isWaterImg) {
         $dw = new ImagickDraw();
         //加图片水印
         if (is_file($waterImage)) {
             $water->setImageOpacity($alpha);
             $dw->setGravity($waterPos);
             $dw->composite($water->getImageCompose(), 0, 0, 50, 0, $water);
             $bg->drawImage($dw);
             if (!$bg->writeImage($groundImage)) {
                 return FALSE;
             }
         } else {
             //加文字水印
             $dw->setFontSize($textFont);
             $dw->setFillColor($textColor);
             $dw->setGravity($waterPos);
             $dw->setFillAlpha($alpha);
             $dw->annotation(0, 0, $waterText);
             $bg->drawImage($dw);
             if (!$bg->writeImage($groundImage)) {
                 return FALSE;
             }
         }
     }
 }
示例#9
0
 public function add_watermark($path, $x = 0, $y = 0)
 {
     $watermark = new Imagick($path);
     $draw = new ImagickDraw();
     $draw->composite($watermark->getImageCompose(), $x, $y, $watermark->getImageWidth(), $watermark->getimageheight(), $watermark);
     if ($this->type == 'gif') {
         $image = $this->image;
         $canvas = new Imagick();
         $images = $image->coalesceImages();
         foreach ($image as $frame) {
             $img = new Imagick();
             $img->readImageBlob($frame);
             $img->drawImage($draw);
             $canvas->addImage($img);
             $canvas->setImageDelay($img->getImageDelay());
         }
         $image->destroy();
         $this->image = $canvas;
     } else {
         $this->image->drawImage($draw);
     }
 }
示例#10
0
 /**
  * @return mixed
  */
 protected function waterMark()
 {
     $oWaterMarkImg = new Imagick($this->_sWaterMarkImgPath);
     $iWaterMarkWidth = $oWaterMarkImg->getimagewidth();
     $iWaterMarkHeight = $oWaterMarkImg->getimageheight();
     $iImgWidth = $this->oImage->getimagewidth();
     $iImgHeight = $this->oImage->getimageheight();
     //图片大小小于水印大小加上30 就不打水印了
     if ($iImgWidth < $iWaterMarkWidth + 30 || $iImgHeight < $iWaterMarkHeight + 30) {
         return true;
     }
     switch ($this->_sWaterMarkPosition) {
         //左下
         case "bottom-left":
             $iDesX = 30;
             $iDesY = $iImgHeight - $iWaterMarkHeight - 30;
             break;
             //右下
         //右下
         case "bottom-right":
             $iDesX = $iImgWidth - $iWaterMarkWidth - 30;
             $iDesY = $iImgHeight - $iWaterMarkHeight - 30;
             break;
             //中下
         //中下
         case "bottom-middle":
             $iDesX = $iImgHeight / 2 - 15;
             $iDesY = $iImgHeight - $iWaterMarkHeight - 30;
             break;
             //左上
         //左上
         case "top-left":
             $iDesX = 30;
             $iDesY = 30;
             break;
             break;
             //中上
         //中上
         case "top-middle":
             $iDesX = $iImgHeight / 2 - 15;
             $iDesY = 30;
             break;
             break;
             //右上
         //右上
         case "top-right":
             $iDesX = $iImgWidth - $iWaterMarkWidth - 30;
             $iDesY = 30;
             break;
             break;
             //默认右下
         //默认右下
         default:
             $iDesX = $iImgWidth - $iWaterMarkWidth - 30;
             $iDesY = $iImgHeight - $iWaterMarkHeight - 30;
             break;
     }
     if ($this->oImage->getimageformat() == 'GIF') {
         $aFrame = $this->oImage->coalesceImages();
         $draw = new ImagickDraw();
         $draw->composite($oWaterMarkImg->getImageCompose(), $iDesX, $iDesY, $iWaterMarkWidth, $iWaterMarkHeight, $oWaterMarkImg);
         foreach ($aFrame as $frame) {
             $frame->drawImage($draw);
         }
         $aFrame->optimizeimagelayers();
         $this->oImage = $aFrame;
     } else {
         $draw = new ImagickDraw();
         $draw->composite($oWaterMarkImg->getImageCompose(), $iDesX, $iDesY, $iWaterMarkWidth, $iWaterMarkHeight, $oWaterMarkImg);
         $this->oImage->drawImage($draw);
     }
 }
示例#11
0
文件: index.php 项目: noikiy/zays
function material_imgactive()
{
    header("Content-Type: text/plain");
    $temp_path = 'data/upload/images/tmp/';
    $dst_im = trim(MooGetGPC('dstim', 'string', 'G'));
    $src_im = trim(MooGetGPC('srcim', 'string', 'G'));
    $photo_img = base64_decode($dst_im);
    //原图片地址
    $fileInfo = pathinfo($photo_img);
    //data/upload/images/photo/2009/11/27/orgin/2009112721102554032.JPG
    $temp_im = str_replace($temp_path, '', $dst_im);
    //list($base64_name, $img_ext) = preg_split("(\_\d\.)",$temp_im);
    $base64_name = $temp_im;
    $temp_img_1 = $temp_path . $dst_im . '_1.' . $fileInfo['extension'];
    $temp_img_2 = $temp_path . $dst_im . '_2.' . $fileInfo['extension'];
    $dst_im = $temp_img_1;
    //echo $temp_img_1;
    $action = trim(MooGetGPC('act', 'string', 'G'));
    $act_arr = array('composite', 'undo', 'redo', 'save');
    if (!file_exists($temp_img_1) || !in_array($action, $act_arr)) {
        echo "{imageFound:false}";
        exit;
    }
    switch ($action) {
        case 'composite':
            //合成
            if (!file_exists($src_im)) {
                echo "{imageFound:false}";
                exit;
            }
            $x1 = MooGetGPC('x1', 'integer', 'G');
            $y1 = MooGetGPC('y1', 'integer', 'G');
            $src_w = MooGetGPC('width', 'integer', 'G');
            $src_h = MooGetGPC('height', 'integer', 'G');
            $dst_im = new Imagick($dst_im);
            $src_im = new Imagick($src_im);
            $dw = new ImagickDraw();
            //$dw->setGravity(Imagick::GRAVITY_SOUTHEAST);//设置位置
            $dw->composite($src_im->getImageCompose(), $x1, $y1, $src_w, $src_h, $src_im);
            $dst_im->drawImage($dw);
            copy($temp_img_1, $temp_img_2);
            $dst_im->writeImage($temp_img_1);
            //保存图片
            break;
        case 'undo':
            if (file_exists($temp_img_2)) {
                copy($temp_img_2, $temp_img_2 . '.tmp');
                rename($temp_img_1, $temp_img_2);
                rename($temp_img_2 . '.tmp', $temp_img_1);
            }
            break;
        case 'redo':
            copy($temp_img_1, $temp_img_2);
            copy($photo_img, $temp_img_1);
            break;
        case 'save':
            //echo 'I am save';exit;
            list($width, $height) = getimagesize($photo_img);
            $temp = explode('/', $photo_img);
            $tmp_name = explode('.', array_pop($temp));
            // 弹出数组最后一个单元(图片名称.扩展)
            array_pop($temp);
            // 弹出 orgin
            $path = implode('/', $temp) . '/';
            if ($_GET['cover'] == 'no') {
                //不覆盖
                $dt = substr($tmp_name[0], 0, 14);
                $pic_date = substr($dt, 0, 4) . '/' . substr($dt, 4, 2) . '/' . substr($dt, 6, 2);
                do {
                    $tmp_name[0] = $dt . rand(1111111111, 9999999999.0);
                    $tmp = $path . 'orgin/' . $tmp_name[0] . '.' . $tmp_name[1];
                } while (file_exists($tmp));
                global $_MooClass, $dbTablePre, $userid;
                //note 查询出来的总数
                $total = $_MooClass['MooMySQL']->getOne("select count(*) as num from `{$dbTablePre}pic` where `uid` = '{$userid}' AND `isimage` = '0'", true);
                if ($total['num'] >= 20) {
                    echo '{imageFound:false,errMsg:"您已经有20张照片了,请选择覆盖保存。"}';
                    exit;
                }
                copy($temp_img_1, $tmp);
                //另存为
                $sql = "INSERT INTO {$dbTablePre}pic (uid,imgurl,pic_date,pic_name) \n\t\t\t\t\tvalues ('{$userid}','{$tmp}','{$pic_date}',\n\t\t\t\t\t\t\t'" . $tmp_name[0] . '.' . $tmp_name[1] . "')";
                $_MooClass['MooMySQL']->query($sql);
            } else {
                copy($temp_img_1, $photo_img);
                //覆盖
            }
            $thumb_name = md5($tmp_name[0]) . '.' . $tmp_name[1];
            //缩略图片name
            $thumb1 = $path . '41_57/';
            $thumb2 = $path . '139_189/';
            $thumb3 = $path . '171_244/';
            $MooImage = MooAutoLoad('MooImage');
            $new_thumb_wh = get_thumb_HW($width, $height, 41, 57);
            $MooImage->config(array('thumbDir' => $thumb1, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_name));
            $MooImage->thumb($new_thumb_wh['width'], $new_thumb_wh['height'], $temp_img_1);
            $new_thumb_wh = get_thumb_HW($width, $height, 139, 189);
            $MooImage->config(array('thumbDir' => $thumb2, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_name));
            $MooImage->thumb($new_thumb_wh['width'], $new_thumb_wh['height'], $temp_img_1);
            $new_thumb_wh = get_thumb_HW($width, $height, 171, 244);
            $MooImage->config(array('thumbDir' => $thumb3, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_name));
            $MooImage->thumb($new_thumb_wh['width'], $new_thumb_wh['height'], $temp_img_1);
            unlink($temp_img_1);
            file_exists($temp_img_2) && unlink($temp_img_2);
            break;
    }
    $temp = explode('_', $temp_img_1);
    $temp_img_1 = str_replace($temp_path, '', $temp[0]);
    echo '{imageFound:true,imageName:"' . $temp_img_1 . '"}';
    exit;
}
示例#12
0
function resize_and_crop()
{
    error_log(print_r($_POST, true));
    $uid = MooGetGPC('uid', 'integer');
    list($width, $height) = getimagesize($_POST["imageSource"]);
    $pWidth = $_POST["imageW"];
    $pHeight = $_POST["imageH"];
    $ext = end(explode(".", $_POST["imageSource"]));
    $function = returnCorrectFunction($ext);
    $image = $function($_POST["imageSource"]);
    $width = imagesx($image);
    $height = imagesy($image);
    // Resample
    $image_p = imagecreatetruecolor($pWidth, $pHeight);
    setTransparency($image, $image_p, $ext);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $pWidth, $pHeight, $width, $height);
    imagedestroy($image);
    $widthR = imagesx($image_p);
    $hegihtR = imagesy($image_p);
    if ($_POST["imageRotate"]) {
        $angle = 360 - $_POST["imageRotate"];
        $image_p = imagerotate($image_p, $angle, 0);
        $pWidth = imagesx($image_p);
        $pHeight = imagesy($image_p);
    }
    if ($pWidth > $_POST["viewPortW"]) {
        $src_x = abs(abs($_POST["imageX"]) - abs(($_POST["imageW"] - $pWidth) / 2));
        $dst_x = 0;
    } else {
        $src_x = 0;
        $dst_x = $_POST["imageX"] + ($_POST["imageW"] - $pWidth) / 2;
    }
    if ($pHeight > $_POST["viewPortH"]) {
        $src_y = abs($_POST["imageY"] - abs(($_POST["imageH"] - $pHeight) / 2));
        $dst_y = 0;
    } else {
        $src_y = 0;
        $dst_y = $_POST["imageY"] + ($_POST["imageH"] - $pHeight) / 2;
    }
    $viewport = imagecreatetruecolor($_POST["viewPortW"], $_POST["viewPortH"]);
    setTransparency($image_p, $viewport, $ext);
    imagecopy($viewport, $image_p, $dst_x, $dst_y, $src_x, $src_y, $pWidth, $pHeight);
    imagedestroy($image_p);
    $selector = imagecreatetruecolor($_POST["selectorW"], $_POST["selectorH"]);
    setTransparency($viewport, $selector, $ext);
    imagecopy($selector, $viewport, 0, 0, $_POST["selectorX"], $_POST["selectorY"], $_POST["viewPortW"], $_POST["viewPortH"]);
    $file = "tmp/test" . time() . "." . $ext;
    parseImage($ext, $selector, $file);
    imagedestroy($viewport);
    //Return value
    echo $file;
    //写水印......fanglin
    $thumb_image_name = $file;
    $first = new Imagick($thumb_image_name);
    //写入水印
    $second = new Imagick('../public/system/images/logo2.png');
    $dw = new ImagickDraw();
    $dw->setGravity(Imagick::GRAVITY_SOUTHEAST);
    //设置位置
    $dw->composite($second->getImageCompose(), 0, 0, 50, 0, $second);
    $first->drawImage($dw);
    $first->writeImage($thumb_image_name);
    chmod($thumb_image_name, 0777);
    //imagick处理.......fanglin
    $bigphoto = $thumb_image_name;
    $thuid = $uid * 3;
    $userpath = "../data/upload/userimg/";
    $jpg = $ext;
    $sizearray = array(0 => array('width' => 320, 'height' => 400), 1 => array('width' => 171, 'height' => 212), 2 => array('width' => 100, 'height' => 125), 3 => array('width' => 60, 'height' => 75));
    $namearray = array(0 => 'big', 1 => 'mid', 2 => 'medium', 3 => 'small');
    foreach ($sizearray as $k => $size) {
        $index_name = $thuid . '_' . $namearray[$k] . '.' . $jpg;
        ImagickResizeImage($bigphoto, $userpath . $index_name, $size['width'], $size['height']);
    }
    $index_name = $thuid . '_' . 'index.' . $jpg;
    $com_name = $thuid . '_' . 'com.' . $jpg;
    $page_name = $thuid . '_' . 'page.' . $jpg;
    list($width, $height) = getimagesize($bigphoto);
    $d = $width / $height;
    $c = 100 / 125;
    //100*125
    if ($d > $c) {
        $g1_width = 100;
        $b = $width / $g1_width;
        $g1_height = $height / $b;
    } else {
        $g1_height = 125;
        $b = $height / $g1_height;
        $g1_width = $width / $b;
    }
    ImagickResizeImage($bigphoto, $userpath . $index_name, $g1_width, $g1_height);
    $c = 50 / 63;
    //100*125
    if ($d > $c) {
        $g2_width = 50;
        $b = $width / $g2_width;
        $g2_height = $height / $b;
    } else {
        $g2_height = 63;
        $b = $height / $g2_height;
        $g2_width = $width / $b;
    }
    ImagickResizeImage($bigphoto, $userpath . $page_name, $g2_width, $g2_height);
    $c = 110 / 138;
    //100*125
    if ($d > $c) {
        $g3_width = 110;
        $b = $width / $g3_width;
        $g3_height = $height / $b;
    } else {
        $g3_height = 138;
        $b = $height / $g3_height;
        $g3_width = $width / $b;
    }
    ImagickResizeImage($bigphoto, $userpath . $com_name, $g3_width, $g3_height);
}
示例#13
0
 /**
  * 添加水印
  */
 public function watermark()
 {
     if (!is_file($this->watermarkFile)) {
         throw new Exception('Watermark file not found');
     }
     $watermark = new Imagick($this->watermarkFile);
     if ($watermark->getImageWidth() > $this->getWidth()) {
         throw new Exception('Watermark file too width');
     }
     if ($watermark->getImageHeight() > $this->getHeight()) {
         throw new Exception('Watermark file too height');
     }
     $dw = new ImagickDraw();
     $dw->setFillOpacity(0.8);
     $dw->setGravity($this->watermarkPosition);
     $dw->composite($watermark->getImageCompose(), 0, 0, 0, 0, $watermark);
     if ($this->getFrames() > 1) {
         foreach ($this->im as $frame) {
             $this->im->drawImage($dw);
         }
         $this->im->writeImages($this->targetName, TRUE);
     } else {
         $this->im->drawImage($dw);
         $this->im->writeImage($this->targetName);
     }
 }
示例#14
0
 /**
  * 加给图片加水印
  * @param string $groundImage 要加水印地址
  * @param int $waterPos 水印位置
  * @param string $waterImage 水印图片地址
  * @param string $waterText 文本文字
  * @param int $textFont 文字大小
  * @param string $textColor 文字颜色
  * @param int $minWidth 小于此值不加水印
  * @param int $minHeight 小于此值不加水印
  * @param float $alpha 透明度
  * @return FALSE
  */
 public static function addWaterMark($groundImage, $waterPos = 0, $waterImage = "", $waterText = "", $textFont = 15, $textColor = "#FF0000", $minWidth = 100, $minHeight = 100, $alpha = 0.9)
 {
     if (!class_exists('\\Imagick', false)) {
         return self::addWaterMark2($groundImage, $waterPos, $waterImage, $waterText, $textFont, $textColor, $minWidth, $minHeight, $alpha);
     }
     if (empty($waterText) and !is_file($waterImage)) {
         return false;
     }
     $bg = null;
     $bg_h = $bg_w = $water_h = $water_w = 0;
     //获取背景图的高,宽
     if (is_file($groundImage) && !empty($groundImage)) {
         $bg = new \Imagick();
         $bg->readImage($groundImage);
         $bg_h = $bg->getImageHeight();
         $bg_w = $bg->getImageWidth();
     }
     //获取水印图的高,宽
     $water = new \Imagick($waterImage);
     $water_h = $water->getImageHeight();
     $water_w = $water->getImageWidth();
     //如果背景图的高宽小于水印图的高宽或指定的高和宽则不加水印
     if ($bg_h < $minHeight || $bg_w < $minWidth || $bg_h < $water_h || $bg_w < $water_w) {
         return false;
     }
     //加水印
     $dw = new \ImagickDraw();
     //加图片水印
     if (is_file($waterImage)) {
         $water->setImageOpacity($alpha);
         $dw->setGravity($waterPos);
         $dw->composite($water->getImageCompose(), 0, 0, 50, 0, $water);
         $bg->drawImage($dw);
         if (!$bg->writeImage($groundImage)) {
             return false;
         }
     } else {
         //加文字水印
         $dw->setFontSize($textFont);
         $dw->setFillColor($textColor);
         $dw->setGravity($waterPos);
         $dw->setFillAlpha($alpha);
         $dw->annotation(0, 0, $waterText);
         $bg->drawImage($dw);
         if (!$bg->writeImage($groundImage)) {
             return false;
         }
     }
     return true;
 }
示例#15
0
 public function transform($operation, $parameters)
 {
     if ($this->properties["mimetype"] == "image/tilepic") {
         return false;
     }
     # no transformations for Tilepic
     if (!$this->handle) {
         return false;
     }
     if (!$this->info["TRANSFORMATIONS"][$operation]) {
         # invalid transformation
         $this->postError(1655, _t("Invalid transformation %1", $operation), "WLPlugImagick->transform()");
         return false;
     }
     # get parameters for this operation
     $sparams = $this->info["TRANSFORMATIONS"][$operation];
     $w = $parameters["width"];
     $h = $parameters["height"];
     $cw = $this->get("width");
     $ch = $this->get("height");
     if ((bool) $this->properties['no_upsampling']) {
         $w = min($cw, round($w));
         $h = min($ch, round($h));
     }
     $do_crop = 0;
     try {
         switch ($operation) {
             # -----------------------
             case 'ANNOTATE':
                 $d = new ImagickDraw();
                 if ($parameters['font']) {
                     $d->setFont($parameters['font']);
                 }
                 $size = $parameters['size'] > 0 ? $parameters['size'] : 18;
                 $d->setFontSize($size);
                 $inset = $parameters['inset'] > 0 ? $parameters['inset'] : 0;
                 $pw = new ImagickPixel();
                 $pw->setColor($parameters['color'] ? $parameters['color'] : "black");
                 $d->setFillColor($pw);
                 switch ($parameters['position']) {
                     case 'north_east':
                         $d->setGravity(imagick::GRAVITY_NORTHEAST);
                         break;
                     case 'north_west':
                         $d->setGravity(imagick::GRAVITY_NORTHWEST);
                         break;
                     case 'north':
                         $d->setGravity(imagick::GRAVITY_NORTH);
                         break;
                     case 'south_east':
                         $d->setGravity(imagick::GRAVITY_SOUTHEAST);
                         break;
                     case 'south':
                         $d->setGravity(imagick::GRAVITY_SOUTH);
                         break;
                     case 'center':
                         $d->setGravity(imagick::GRAVITY_CENTER);
                         break;
                     case 'south_west':
                     default:
                         $d->setGravity(imagick::GRAVITY_SOUTHWEST);
                         break;
                 }
                 $this->handle->annotateImage($d, $inset, $size + $inset, 0, $parameters['text']);
                 break;
                 # -----------------------
             # -----------------------
             case 'WATERMARK':
                 if (!file_exists($parameters['image'])) {
                     break;
                 }
                 $vn_opacity_setting = $parameters['opacity'];
                 if ($vn_opacity_setting < 0 || $vn_opacity_setting > 1) {
                     $vn_opacity_setting = 0.5;
                 }
                 $d = new ImagickDraw();
                 if (($vn_watermark_width = $parameters['width']) < 10) {
                     $vn_watermark_width = $cw / 2;
                 }
                 if (($vn_watermark_height = $parameters['height']) < 10) {
                     $vn_watermark_height = $ch / 2;
                 }
                 switch ($parameters['position']) {
                     case 'north_east':
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = 0;
                         break;
                     case 'north_west':
                         $vn_watermark_x = 0;
                         $vn_watermark_y = 0;
                         break;
                     case 'north':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = 0;
                         break;
                     case 'south_east':
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                     case 'south':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                     case 'center':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = ($ch - $vn_watermark_height) / 2;
                         break;
                     case 'south_west':
                     default:
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                 }
                 $w = new Imagick();
                 if (!$w->readImage($parameters['image'])) {
                     $this->postError(1610, _t("Couldn't load watermark image at %1", $parameters['image']), "WLPlugImagick->transform:WATERMARK()");
                     return false;
                 }
                 //$w->evaluateImage(imagick::COMPOSITE_MINUS, $vn_opacity, imagick::CHANNEL_OPACITY) ; [seems broken with latest imagick circa March 2010?]
                 if (method_exists($w, "setImageOpacity")) {
                     // added in ImageMagick 6.3.1
                     $w->setImageOpacity($vn_opacity_setting);
                 }
                 $d->composite(imagick::COMPOSITE_DISSOLVE, $vn_watermark_x, $vn_watermark_y, $vn_watermark_width, $vn_watermark_height, $w);
                 $this->handle->drawImage($d);
                 break;
                 # -----------------------
             # -----------------------
             case 'SCALE':
                 $aa = $parameters["antialiasing"];
                 if ($aa <= 0) {
                     $aa = 0;
                 }
                 switch ($parameters["mode"]) {
                     # ----------------
                     case "width":
                         $scale_factor = $w / $cw;
                         $h = $ch * $scale_factor;
                         break;
                         # ----------------
                     # ----------------
                     case "height":
                         $scale_factor = $h / $ch;
                         $w = $cw * $scale_factor;
                         break;
                         # ----------------
                     # ----------------
                     case "bounding_box":
                         $scale_factor_w = $w / $cw;
                         $scale_factor_h = $h / $ch;
                         $w = $cw * ($scale_factor_w < $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $h = $ch * ($scale_factor_w < $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         break;
                         # ----------------
                     # ----------------
                     case "fill_box":
                         $crop_from = $parameters["crop_from"];
                         if (!in_array($crop_from, array('center', 'north_east', 'north_west', 'south_east', 'south_west', 'random'))) {
                             $crop_from = '';
                         }
                         $scale_factor_w = $w / $cw;
                         $scale_factor_h = $h / $ch;
                         $w = $cw * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $h = $ch * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $do_fill_box_crop = true;
                         break;
                         # ----------------
                 }
                 $w = round($w);
                 $h = round($h);
                 if ($w > 0 && $h > 0) {
                     $crop_w_edge = $crop_h_edge = 0;
                     if (preg_match("/^([\\d]+)%\$/", $parameters["trim_edges"], $va_matches)) {
                         $crop_w_edge = ceil(intval($va_matches[1]) / 100 * $w);
                         $crop_h_edge = ceil(intval($va_matches[1]) / 100 * $h);
                     } else {
                         if (isset($parameters["trim_edges"]) && intval($parameters["trim_edges"]) > 0) {
                             $crop_w_edge = $crop_h_edge = intval($parameters["trim_edges"]);
                         }
                     }
                     if (!$this->handle->resizeImage($w + $crop_w_edge * 2, $h + $crop_h_edge * 2, imagick::FILTER_CUBIC, $aa)) {
                         $this->postError(1610, _t("Error during resize operation"), "WLPlugImagick->transform()");
                         return false;
                     }
                     if ($do_fill_box_crop) {
                         // use face detection info to intelligently crop
                         if (is_array($this->properties['faces']) && sizeof($this->properties['faces'])) {
                             $va_info = array_shift($this->properties['faces']);
                             $crop_from_offset_x = ceil($va_info['x'] * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h));
                             $crop_from_offset_x -= ceil(0.15 * $parameters["width"]);
                             // since face will be tightly cropped give it some room
                             $crop_from_offset_y = ceil($va_info['y'] * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h));
                             $crop_from_offset_y -= ceil(0.15 * $parameters["height"]);
                             // since face will be tightly cropped give it some room
                             // Don't try to crop beyond image boundaries, you just end up scaling the image, often awkwardly
                             if ($crop_from_offset_x > $w - $parameters["width"]) {
                                 $crop_from_offset_x = 0;
                             }
                             if ($crop_from_offset_y > $h - $parameters["height"]) {
                                 $crop_from_offset_y = 0;
                             }
                             if ($crop_from_offset_x < 0) {
                                 $crop_from_offset_x = 0;
                             }
                             if ($crop_from_offset_y < 0) {
                                 $crop_from_offset_y = 0;
                             }
                         } else {
                             switch ($crop_from) {
                                 case 'north_west':
                                     $crop_from_offset_y = 0;
                                     $crop_from_offset_x = $w - $parameters["width"];
                                     break;
                                 case 'south_east':
                                     $crop_from_offset_x = 0;
                                     $crop_from_offset_y = $h - $parameters["height"];
                                     break;
                                 case 'south_west':
                                     $crop_from_offset_x = $w - $parameters["width"];
                                     $crop_from_offset_y = $h - $parameters["height"];
                                     break;
                                 case 'random':
                                     $crop_from_offset_x = rand(0, $w - $parameters["width"]);
                                     $crop_from_offset_y = rand(0, $h - $parameters["height"]);
                                     break;
                                 case 'north_east':
                                     $crop_from_offset_x = $crop_from_offset_y = 0;
                                     break;
                                 case 'center':
                                 default:
                                     if ($w > $parameters["width"]) {
                                         $crop_from_offset_x = ceil(($w - $parameters["width"]) / 2);
                                     } else {
                                         if ($h > $parameters["height"]) {
                                             $crop_from_offset_y = ceil(($h - $parameters["height"]) / 2);
                                         }
                                     }
                                     break;
                             }
                         }
                         if (!$this->handle->cropImage($parameters["width"], $parameters["height"], $crop_w_edge + $crop_from_offset_x, $crop_h_edge + $crop_from_offset_y)) {
                             $this->postError(1610, _t("Error during crop operation"), "WLPlugImagick->transform()");
                             return false;
                         }
                         $this->properties["width"] = $parameters["width"];
                         $this->properties["height"] = $parameters["height"];
                     } else {
                         if ($crop_w_edge || $crop_h_edge) {
                             if (!$this->handle->cropImage($w, $h, $crop_w_edge, $crop_h_edge)) {
                                 $this->postError(1610, _t("Error during crop operation"), "WLPlugImagick->transform()");
                                 return false;
                             }
                         }
                         $this->properties["width"] = $w;
                         $this->properties["height"] = $h;
                     }
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "ROTATE":
                 $angle = $parameters["angle"];
                 if ($angle > -360 && $angle < 360) {
                     if (!$this->handle->rotateImage("#FFFFFF", $angle)) {
                         $this->postError(1610, _t("Error during image rotate"), "WLPlugImagick->transform()");
                         return false;
                     }
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "DESPECKLE":
                 $radius = $parameters["radius"];
                 if (!$this->handle->despeckleImage()) {
                     $this->postError(1610, _t("Error during image despeckle"), "WLPlugImagick->transform:DESPECKLE()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "MEDIAN":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 if (!$this->handle->medianFilterImage($radius)) {
                     $this->postError(1610, _t("Error during image median filter"), "WLPlugImagick->transform:MEDIAN()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "SHARPEN":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 $sigma = $parameters["sigma"];
                 if ($sigma < 0.1) {
                     $sigma = 1;
                 }
                 if (!$this->handle->sharpenImage($radius, $sigma)) {
                     $this->postError(1610, _t("Error during image sharpen"), "WLPlugImagick->transform:SHARPEN()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "UNSHARPEN_MASK":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 $sigma = $parameters["sigma"];
                 if ($sigma < 0.1) {
                     $sigma = 1;
                 }
                 $threshold = $parameters["threshold"];
                 if ($threshold < 0.1) {
                     $threshold = 1;
                 }
                 $amount = $parameters["amount"];
                 if ($amount < 0.1) {
                     $amount = 1;
                 }
                 if (!$this->handle->unsharpMaskImage($radius, $sigma, $amount, $threshold)) {
                     $this->postError(1610, _t("Error during image unsharp mask"), "WLPlugImagick->transform:UNSHARPEN_MASK()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "SET":
                 while (list($k, $v) = each($parameters)) {
                     $this->set($k, $v);
                 }
                 break;
                 # -----------------------
         }
         return 1;
     } catch (Exception $e) {
         $this->postError(1610, _t("Imagick exception"), "WLPlugImagick->transform");
         return false;
     }
 }
示例#16
0
 public function diyAction()
 {
     Yaf_Dispatcher::getInstance()->autoRender(FALSE);
     $id = $this->_req->getQuery('id', 1);
     if ($this->_req->isPost()) {
         $this->diy = new DiyModel();
         $pre_svg = '<?xml version="1.0" standalone="no" ?>' . trim($_POST['svg_val']);
         $rdate = APPLICATION_PATH . '/public/Uploads/' . date("Ymd", time());
         //文件名
         if (!file_exists($rdate)) {
             chmod(APPLICATION_PATH . '/public/Uploads/', 0777);
             mkdir($rdate);
             //创建目录
         }
         $savename = $this->create_unique();
         $path = $rdate . '/' . $savename;
         if (!($file_svg = fopen($path . '.svg', 'w+'))) {
             echo "不能打开文件 {$path}.'.svg'";
             exit;
         }
         if (fwrite($file_svg, $pre_svg) === FALSE) {
             echo "不能写入到文件 {$path}.'.svg'";
             exit;
         }
         echo "已成功写入";
         fclose($file_svg);
         //$path= APPLICATION_PATH . '/public/Uploads/' . date("Ymd", time()) .'/m-1';
         //添加图片转化
         $im = new Imagick();
         $im->setBackgroundColor(new ImagickPixel('transparent'));
         $svg = file_get_contents($path . '.svg');
         $im->readImageBlob($svg);
         $im->setImageFormat("png");
         $am = $im->writeImage($path . '.png');
         $im->thumbnailImage(579, 660, true);
         /* 改变大小 */
         $ams = $im->writeImage($path . '-t.png');
         $im->clear();
         $im->destroy();
         //图片加水印
         $waterpath = APPLICATION_PATH . '/public/source/source.png';
         $im1 = new Imagick($waterpath);
         $im2 = new Imagick($path . '.png');
         $im2->thumbnailImage(600, 600, true);
         $dw = new ImagickDraw();
         $dw->setGravity(5);
         $dw->setFillOpacity(0.1);
         $dw->composite($im2->getImageCompose(), 0, 0, 50, 0, $im2);
         $im1->drawImage($dw);
         if (!$im1->writeImage($path . '-s.png')) {
             echo '加水印失败';
             exit;
         }
         $im1->clear();
         $im2->clear();
         $im1->destroy();
         $im2->destroy();
         //exit;
         //删除相应的文件
         //unlink($path.'.svg');
         //unlink($path.'.png');
         $filepath = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '.png';
         $data['origin_img'] = $filepath;
         $data['diy_synthetic_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '-s.png';
         $data['diy_preview_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '-s.png';
         $data['user_id'] = 0;
         $data['source'] = 3;
         $data['created'] = date("Y-m-d H:i:s", time());
         $datas['image'] = $data['diy_synthetic_img'];
         $datas['user_id'] = 0;
         $datas['source'] = 2;
         $datas['state'] = 1;
         $datas['createtime'] = date("Y-m-d H:i:s", time());
         $datas['updatetime'] = date("Y-m-d H:i:s", time());
         $diy_picture_id = $this->diy->adddiy($data);
         //$datas['use'] = $tool;
         //$datas['author'] = $userinfo['mobile'];
         $this->userpicture = new UserpictureModel();
         $datas['diy_picture_id'] = $diy_picture_id;
         $this->userpicture->adduserpicture($datas);
         $response_data['origin_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '.png';
         $response_data['diy_preview_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '-s.png';
         $response_data['diy_thumb_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '-t.png';
         $response_data['diy_picture_id'] = $diy_picture_id;
         //$this->getView()->display("/index/buy.html",$response_data);
         $this->_session->set('diypicture', $response_data);
         $this->_redis = new phpredis();
         $this->_redis->set($diy_picture_id, json_encode($response_data));
         header("Location:/index/share?diy=" . $diy_picture_id);
     } else {
         switch ($id) {
             case 1:
                 $this->getView()->display("index/diy_1.html");
                 break;
             case 2:
                 $this->getView()->display("index/diy_2.html");
                 break;
             case 3:
                 $this->getView()->display("index/diy_3.html");
                 break;
             case 4:
                 $this->getView()->display("index/diy_4.html");
                 break;
             case 5:
                 $this->getView()->display("index/diy_5.html");
                 break;
             case 6:
                 $this->getView()->display("index/diy_6.html");
                 break;
             case 7:
                 $this->getView()->display("index/diy_7.html");
                 break;
         }
     }
 }
示例#17
0
function blackBox(&$canvas, $o) {

	$rectangle = new Imagick();
	$rectangle->newPseudoImage($o['w'], $o['h'], "xc:none");
	$draw1 = new ImagickDraw();
	$draw1->pushPattern('gradient', 0, 0, 5, 5);
	$tile = new Imagick();
	$tile->readImage(realpath("assets/diag_tile.png"));
	$draw1->composite(Imagick::COMPOSITE_OVER, 0, 0, 5, 5, $tile);
	$draw1->popPattern();
	$draw1->setFillPatternURL('#gradient');
	$draw1->rectangle(0, 0, $o['w'], $o['h']);
	$rectangle->drawImage($draw1);

	$gradient = new Imagick();
	$gradient->newPseudoImage($o['w'], $o['h'], "gradient:#DDD-#666");

	$rectangle->compositeImage($gradient, Imagick::COMPOSITE_COPYOPACITY, 0, 0);

	$black = new Imagick();
	$black->newPseudoImage($o['w'], $o['h'], "xc:black");

	$layered = new Imagick();
	$layered->newPseudoImage($o['w'] + 20, $o['h'] + 20, "xc:none");
	$layered->compositeImage($black, Imagick::COMPOSITE_OVER, 5, 0);
	$layered->compositeImage($black, Imagick::COMPOSITE_OVER, 5, 5);
	$layered->compositeImage($gradient, Imagick::COMPOSITE_COPYOPACITY, 5, 5);
	$layered->blurImage(4, 5, imagick::CHANNEL_ALPHA);
	$layered->compositeImage($black, Imagick::COMPOSITE_DSTOUT, 0, 0);

	$canvas->compositeImage($layered, Imagick::COMPOSITE_OVER, $o['x'], $o['y']);
	$canvas->compositeImage($rectangle, Imagick::COMPOSITE_OVER, $o['x'], $o['y']);
}
示例#18
0
 function waterMarkImg()
 {
     if (empty($this->param['water_mark_image']) || !file_exists($this->param['water_mark_image'])) {
         return false;
     }
     $bg_h = $this->getHeight();
     $bg_w = $this->getWidth();
     $water_img = new Imagick($this->param['water_mark_image']);
     $water_h = $water_img->getImageHeight();
     $water_w = $water_img->getImageWidth();
     //if($bg_h < $water_h || $bg_w < $water_w )
     //{
     //   return false;
     //}
     if ($this->param['water_mark_opacity']) {
         $water_img->setImageOpacity($this->param['water_mark_opacity'] / 100);
     }
     $draw = new ImagickDraw();
     switch ($this->param['water_mark_pos']) {
         case 0:
         case 1:
             $gravity = Imagick::GRAVITY_NORTHWEST;
             //'NorthWest';
             break;
         case 2:
             $gravity = Imagick::GRAVITY_NORTH;
             //'North';
             break;
         case 3:
             $gravity = Imagick::GRAVITY_NORTHEAST;
             //'NorthEast';
             break;
         case 4:
             $gravity = Imagick::GRAVITY_WEST;
             //'West';
             break;
         case 5:
             $gravity = Imagick::GRAVITY_CENTER;
             //'Center';
             break;
         case 6:
             $gravity = Imagick::GRAVITY_EAST;
             //'East';
             break;
         case 7:
             $gravity = Imagick::GRAVITY_SOUTHWEST;
             //'SouthWest';
             break;
         case 8:
             $gravity = Imagick::GRAVITY_SOUTH;
             //'South';
             break;
         case 9:
             $gravity = Imagick::GRAVITY_SOUTHEAST;
             break;
     }
     $draw->setGravity($gravity);
     $draw->composite($water_img->getImageCompose(), 0, 0, 50, 0, $water_img);
     if ($this->image_type == 'GIF') {
         $color_transparent = new ImagickPixel("transparent");
         //透明色
         $dest = new Imagick();
         foreach ($this->image as $frame) {
             $page = $frame->getImagePage();
             $tmp = new Imagick();
             $tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
             $tmp->compositeImage($frame, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
             $tmp->drawImage($draw);
             $dest->addImage($tmp);
             $dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $dest->setImageDelay($frame->getImageDelay());
             $dest->setImageDispose($frame->getImageDispose());
         }
         $dest->coalesceImages();
         $this->image->destroy();
         $this->image = $dest;
     } else {
         $this->image->drawImage($draw);
     }
 }
示例#19
0
 public function add_full_watermark($path, $x = 0, $y = 0)
 {
     $watermark = new Imagick($path);
     $draw = new ImagickDraw();
     $image = $this->image;
     $image_w = $image->getImageWidth();
     $image_h = $image->getimageheight();
     $water_w = $watermark->getImageWidth();
     $water_h = $watermark->getimageheight();
     $a = floor($image_w / $water_w);
     $b = floor($image_h / $water_h);
     //$offset_x = ($image_w>$water_w)?floor($image_w%$water_w/2):0;
     //$offset_y = ($image_h>$water_h)?floor($image_h%$water_h/2):0;
     $offset_x = $offset_y = 0;
     for ($i = 0; $i <= $a; $i++) {
         for ($j = 0; $j <= $b; $j++) {
             $draw->composite($watermark->getImageCompose(), $i * $water_w + $offset_x, $j * $water_h + $offset_y, $water_w, $water_h, $watermark);
         }
     }
     if ($this->type == 'gif') {
         $image = $this->image;
         $canvas = new Imagick();
         $images = $image->coalesceImages();
         foreach ($image as $frame) {
             $img = new Imagick();
             $img->readImageBlob($frame);
             $img->drawImage($draw);
             $canvas->addImage($img);
             $canvas->setImageDelay($img->getImageDelay());
         }
         $image->destroy();
         $this->image = $canvas;
     } else {
         $this->image->drawImage($draw);
     }
 }
示例#20
0
 /**
  * 添加图片水印 
  * 有个别水印图片打不漂亮;貌似对jpg图片打出来还不错
  * @see Lib_Image_Abstract::watermarkImage()
  * @param string $watermarkPath 水印图片(最好是透明背景的png图片)
  * @param string $place 水印位置;具体对应参数如下(可参见常量)
  *         northwest            northeast 
  *                     center
  *         southwest            southeast
  * @param integer $x 水印位置 ; x(水平坐标轴)轴偏移量
  * @param integer $y 水印位置 ; y(垂直坐标轴)轴偏移量
  * @param integer $alpha 水印透明度。取值0(全透明)-100(完全不透明) ;默认52:半透明
  * @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;
     }
     try {
         $watermark = new Imagick();
         $watermark->readImage($watermarkPath);
         $alpha = $alpha / 100;
         $watermark->setImageOpacity($alpha);
         // 设置透明度,不知道为什么这里如果设了透明度,有些png水印打出来的图片就不漂亮了
         // 在ubuntu 64 位上还是一样
         $watermarkW = $watermark->getimagewidth();
         $watermarkH = $watermark->getimageheight();
         switch ($place) {
             case self::PLACE_NORTHWEST:
                 break;
             case self::PLACE_NORTHEAST:
                 $x = $this->_sourceWidth - ($watermarkW + $x);
                 break;
             case self::PLACE_CENTER:
                 $x = intval(($this->_sourceWidth - $watermarkW) / 2);
                 $y = intval(($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:
                 $x = $this->_sourceWidth - ($watermarkW + $x);
                 $y = $this->_sourceHeight - ($watermarkH + $y);
                 break;
         }
         $compose = $watermark->getImageCompose();
         // 方法一
         //return $this->_im->compositeimage($watermark, $compose, $x, $y);
         // 方法二
         $draw = new ImagickDraw();
         $draw->composite($compose, $x, $y, $watermarkW, $watermarkH, $watermark);
         if ($this->_sourceType == self::TYPE_GIF) {
             $this->_im = $this->_im->coalesceImages();
             $flag = true;
             foreach ($this->_im as $frame) {
                 $boolean = $frame->drawImage($draw);
                 if (!$boolean) {
                     $flag = false;
                     $this->_im = null;
                     $this->_error = '添加水印出错!';
                     break;
                 }
             }
             return $flag;
         }
         return $this->_im->drawImage($draw);
     } catch (Exception $e) {
         $this->_error = '处理水印图片出错';
         $this->_im = null;
         return false;
     }
 }
示例#21
0
文件: album.php 项目: noikiy/zays
function material_photo_upload()
{
    global $_MooClass, $dbTablePre, $userid, $user, $pic_size_arr, $user_arr, $memcached;
    $and_uuid = isset($_GET['uuid']) ? $_GET['uuid'] : '';
    $uid = $_GET['uid'] = isset($_GET['uid']) ? $_GET['uid'] : '';
    if ($uid) {
        $userid = $mem_uid = $memcached->get('uid_' . $uid);
    }
    $checkuuid = check_uuid($and_uuid, $userid);
    if (!$checkuuid) {
        $error = "uuid_error";
        echo return_data($error, false);
        exit;
    }
    $user_arr = $user = MooMembersData($userid);
    $user_rank_id = get_userrank($userid);
    if (MOOPHP_ALLOW_FASTDB) {
        $usercer = MooFastdbGet('certification', 'uid', $userid);
    } else {
        $usercer = $_MooClass['MooMySQL']->getOne("SELECT * FROM {$dbTablePre}certification WHERE uid='{$userid}' LIMIT 1 ", true);
    }
    if ($_POST['isupload'] == '1') {
        //note 设定用户id
        $memberid = $userid;
        //note 设定用户上传图片大小限制 最小10240字节 = 10k 最大419430字节 = 400K
        $minfilesize = 20480;
        $maxfilesize = 1024000;
        $filesize = $_FILES['userfile']['size'];
        if ($filesize > $maxfilesize) {
            $notice = "请上传小于1000KB的照片。";
            echo return_data($notice);
            exit;
        }
        if ($filesize < $minfilesize) {
            $notice = "请上传大于20KB的照片。";
            echo return_data($notice);
            exit;
        }
        //note 判断文件类型
        $flag = '';
        $true_type = file_type($_FILES['userfile']['tmp_name']);
        $extname = strtolower(substr($_FILES['userfile']['name'], strrpos($_FILES['userfile']['name'], '.') + 1));
        $images = array('/jpg/', '/jpeg/', '/gif/', '/png/', '/JPG/', '/JPEG/', '/GIF/', '/PNG/');
        if (in_array('/' . $extname . '/', $images)) {
            foreach ($images as $v) {
                //note http://ask.wangmeng.cn/question/76
                if (preg_match($v, $_FILES['userfile']['type']) && ('image/' . $true_type == $_FILES['userfile']['type'] || 'image/p' . $true_type == $_FILES['userfile']['type'] || 'image/x-' . $true_type == $_FILES['userfile']['type'])) {
                    $file_content = file_get_contents($_FILES['userfile']['tmp_name']);
                    $low_file_content = strtolower($file_content);
                    $pos = strpos($low_file_content, '<?php');
                    if ($pos) {
                        $notice = "照片中含有不安全信息请重新上传";
                        echo return_data($notice);
                        exit;
                    } else {
                        $flag = 1;
                    }
                }
            }
        }
        //echo $true_type,'_',$flag,'_',$_FILES['userfile']['type'];exit;
        if ($flag != 1) {
            $notice = "请上传JPEG,JPG,PNG或GIF格式";
            echo return_data($notice);
            exit;
        }
        //note 设定该用户最多上传20张图片(形象照除外)
        $maxuploadnum = 20;
        //note 查询出来的总数
        $query = $_MooClass['MooMySQL']->getOne("select count(1) as num from `{$dbTablePre}pic` where `uid` = '{$memberid}' AND `isimage` = '0'", true);
        $total = $query['num'];
        //note 还可以上传多少张
        $leave_num = $maxuploadnum - $total;
        if ($leave_num <= 0) {
            $notice = '您已经有' . $maxuploadnum . '张照片了,';
            if ($user_arr['mainimg']) {
                $notice .= '不可以再上传了。';
            } else {
                $notice .= '请在相册中选一张作为形象照。';
            }
            echo return_data($notice);
            exit;
        }
        //note 设定相册名
        $album = '';
        //note 设定全局路径
        $orgin = "orgin";
        //note 原图文件夹名
        $thumb_path = PIC_PATH;
        //图片路径
        $timestat = time();
        $thumb_datedir = date("Y", $timestat) . "/" . date("m", $timestat) . "/" . date("d", $timestat);
        //原图路径
        $main_img_path = $thumb_path . "/" . $thumb_datedir . "/" . $orgin . "/";
        //note 调用文件操作类库,建立无限级目录
        $mkdirs = MooAutoLoad('MooFiles');
        !is_dir($main_img_path) && $mkdirs->fileMake($main_img_path, 0777);
        //note 上传到指定目录(原图),并且获得上传后的文件描述
        $upload = MooAutoLoad('MooUpload');
        $upload->config(array('targetDir' => $main_img_path, 'saveType' => '0'));
        $files = $upload->saveFiles('userfile');
        //note 获得图片路径和缩略图的路径
        $imgurl = $files[0]['path'] . $files[0]['name'] . "." . $files[0]['extension'];
        if ($files[0]['extension'] == 'gif') {
            $output = imagecreatefromgif($imgurl);
            imagegif($output, $imgurl, 100);
            imagedestroy($output);
        }
        $imgurl2 = $files[0]['path'] . $files[0]['name'] . "_nowater." . $files[0]['extension'];
        @copy($imgurl, $imgurl2);
        //拷贝一张无水印图片(用于形象照)
        $pic_name = $files[0]['name'] . "." . $files[0]['extension'];
        $pic_name2 = $files[0]['name'] . "_nowater." . $files[0]['extension'];
        $first = new Imagick($imgurl);
        //写入水印
        $second = new Imagick('public/system/images/logo_original.png');
        //$second->setImageOpacity (0.4);//设置透明度
        $dw = new ImagickDraw();
        $dw->setGravity(Imagick::GRAVITY_SOUTHEAST);
        //设置位置
        //$dw->setGravity(Imagick::GRAVITY_SOUTH);//设置位置
        $dw->composite($second->getImageCompose(), 0, 0, 50, 0, $second);
        $first->drawImage($dw);
        $first->writeImage($imgurl);
        //将第一张图片的大小控制成我们需要的大小
        list($width, $height) = getimagesize($imgurl);
        $d = $width / $height;
        $off_wh = off_WH($width, $height);
        $new_width = $off_wh['width'];
        $new_height = $off_wh['height'];
        unset($off_wh);
        $big_path = $files[0]['path'];
        $big_name = $files[0]['name'] . '.' . $files[0]['extension'];
        $image = MooAutoLoad('MooImage');
        $image->config(array('thumbDir' => $big_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $pic_name, 'waterMarkMinWidth' => '41', 'waterMarkMinHeight' => '57', 'waterMarkStatus' => 9));
        $image->thumb($new_width, $new_height, $imgurl);
        $image->waterMark();
        //note 缩略无水印图片
        $image->config(array('thumbDir' => $big_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $pic_name2, 'waterMarkMinWidth' => '41', 'waterMarkMinHeight' => '57', 'waterMarkStatus' => 9));
        $image->thumb($new_width, $new_height, $imgurl2);
        $image->waterMark();
        $thumb1_width = $pic_size_arr["1"]["width"];
        $thumb1_height = $pic_size_arr["1"]["height"];
        $thumb2_width = $pic_size_arr["2"]["width"];
        $thumb2_height = $pic_size_arr["2"]["height"];
        $thumb3_width = $pic_size_arr["3"]["width"];
        $thumb3_height = $pic_size_arr["3"]["height"];
        //note 生成日期目录
        $thumb1_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb1_width . "_" . $thumb1_height . "/";
        $thumb2_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb2_width . "_" . $thumb2_height . "/";
        $thumb3_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb3_width . "_" . $thumb3_height . "/";
        !is_dir($thumb1_path) && $mkdirs->fileMake($thumb1_path, 0777);
        !is_dir($thumb2_path) && $mkdirs->fileMake($thumb2_path, 0777);
        !is_dir($thumb3_path) && $mkdirs->fileMake($thumb3_path, 0777);
        //note 缩略图文件名
        $thumb_filename = md5($files[0]['name']) . "." . $files[0]['extension'];
        $c = 41 / 57;
        if ($d > $c) {
            $thumb1_width = 41;
            $b = $width / $thumb1_width;
            $thumb1_height = $height / $b;
        } else {
            $thumb1_height = 57;
            $b = $height / $thumb1_height;
            $thumb1_width = $width / $b;
        }
        $image->config(array('thumbDir' => $thumb1_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '41', 'waterMarkMinHeight' => '57', 'waterMarkStatus' => 9));
        $image->thumb($thumb1_width, $thumb1_height, $imgurl);
        $image->waterMark();
        $c = 139 / 189;
        if ($d > $c) {
            $thumb2_width = 139;
            $b = $width / $thumb2_width;
            $thumb2_height = $height / $b;
        } else {
            $thumb2_height = 189;
            $b = $height / $thumb2_height;
            $thumb2_width = $width / $b;
        }
        $image->config(array('thumbDir' => $thumb2_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '139', 'waterMarkMinHeight' => '189', 'waterMarkStatus' => 9));
        $image->thumb($thumb2_width, $thumb2_height, $imgurl);
        $image->waterMark();
        $c = 171 / 244;
        if ($d > $c) {
            $thumb3_width = 171;
            $b = $width / $thumb3_width;
            $thumb3_height = $height / $b;
        } else {
            $thumb3_height = 244;
            $b = $height / $thumb3_height;
            $thumb3_width = $width / $b;
        }
        $image->config(array('thumbDir' => $thumb3_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '171', 'waterMarkMinHeight' => '244', 'waterMarkStatus' => 9));
        $image->thumb($thumb3_width, $thumb3_height, $imgurl);
        $image->waterMark();
        //note 设定是否是形象照 1为形象照,0为普通照
        $isimage = (int) $_POST['isimage'];
        $updatetime = time();
        if ($isimage === 1) {
            $_MooClass['MooMySQL']->query("update `{$dbTablePre}members_base` set `mainimg`='{$imgurl}',`pic_date` = '{$thumb_datedir}',`pic_name` = '{$pic_name}' where `uid` = '{$memberid}'");
            $_MooClass['MooMySQL']->query("update `{$dbTablePre}members_search` set images_ischeck='2'  where `uid` = '{$memberid}'");
            if (MOOPHP_ALLOW_FASTDB) {
                $image_arr = array();
                $image_arr['mainimg'] = $imgurl;
                $image_arr['pic_date'] = $thumb_datedir;
                $image_arr['pic_name'] = $pic_name;
                $members_search['images_ischeck'] = '2';
                MooFastdbUpdate('members_base', 'uid', $memberid, $image_arr);
                MooFastdbUpdate('members_search', 'uid', $memberid, $members_search);
            }
            searchApi("members_man members_women")->updateAttr(array('images_ischeck'), array($memberid => array(0)));
            UpdateMembersSNS($userid, '修改了形象照');
        }
        //note 写入相册表
        $isimage = 0;
        //web_members.mainimg == web_pic.imgurl 即形象照
        $_MooClass['MooMySQL']->query("insert into `{$dbTablePre}pic` set `uid` = '{$memberid}',`isimage` = '{$isimage}',`album` = '{$album}',`imgurl` = '{$imgurl}',`pic_date` = '{$thumb_datedir}',`pic_name` = '{$pic_name}'");
        //提交会员动态makui
        UpdateMembersSNS($userid, '修改了相册');
        $notice = "成功";
        echo return_data($notice);
        exit;
    } else {
        $user1 = $user_arr;
    }
}
示例#22
0
 /**
  * 添加水印
  * @param  string  $source 水印图片路径
  * @param  integer $locate 水印位置
  * @param  integer $alpha  水印透明度
  */
 public function water($source, $locate = Image::IMAGE_WATER_SOUTHEAST)
 {
     //资源检测
     if (empty($this->img)) {
         throw new Exception('没有可以被添加水印的图像资源');
     }
     if (!is_file($source)) {
         throw new Exception('水印图像不存在');
     }
     //创建水印图像资源
     $water = new Imagick(realpath($source));
     $info = array($water->getImageWidth(), $water->getImageHeight());
     /* 设定水印位置 */
     switch ($locate) {
         /* 右下角水印 */
         case Image::IMAGE_WATER_SOUTHEAST:
             $x = $this->info['width'] - $info[0];
             $y = $this->info['height'] - $info[1];
             break;
             /* 左下角水印 */
         /* 左下角水印 */
         case Image::IMAGE_WATER_SOUTHWEST:
             $x = 0;
             $y = $this->info['height'] - $info[1];
             break;
             /* 左上角水印 */
         /* 左上角水印 */
         case Image::IMAGE_WATER_NORTHWEST:
             $x = $y = 0;
             break;
             /* 右上角水印 */
         /* 右上角水印 */
         case Image::IMAGE_WATER_NORTHEAST:
             $x = $this->info['width'] - $info[0];
             $y = 0;
             break;
             /* 居中水印 */
         /* 居中水印 */
         case Image::IMAGE_WATER_CENTER:
             $x = ($this->info['width'] - $info[0]) / 2;
             $y = ($this->info['height'] - $info[1]) / 2;
             break;
             /* 下居中水印 */
         /* 下居中水印 */
         case Image::IMAGE_WATER_SOUTH:
             $x = ($this->info['width'] - $info[0]) / 2;
             $y = $this->info['height'] - $info[1];
             break;
             /* 右居中水印 */
         /* 右居中水印 */
         case Image::IMAGE_WATER_EAST:
             $x = $this->info['width'] - $info[0];
             $y = ($this->info['height'] - $info[1]) / 2;
             break;
             /* 上居中水印 */
         /* 上居中水印 */
         case Image::IMAGE_WATER_NORTH:
             $x = ($this->info['width'] - $info[0]) / 2;
             $y = 0;
             break;
             /* 左居中水印 */
         /* 左居中水印 */
         case Image::IMAGE_WATER_WEST:
             $x = 0;
             $y = ($this->info['height'] - $info[1]) / 2;
             break;
         default:
             /* 自定义水印坐标 */
             if (is_array($locate)) {
                 list($x, $y) = $locate;
             } else {
                 throw new Exception('不支持的水印位置类型');
             }
     }
     //创建绘图资源
     $draw = new ImagickDraw();
     $draw->composite($water->getImageCompose(), $x, $y, $info[0], $info[1], $water);
     if ('gif' == $this->info['type']) {
         $img = $this->img->coalesceImages();
         $this->img->destroy();
         //销毁原图
         do {
             //添加水印
             $img->drawImage($draw);
         } while ($img->nextImage());
         //压缩图片
         $this->img = $img->deconstructImages();
         $img->destroy();
         //销毁零时图片
     } else {
         //添加水印
         $this->img->drawImage($draw);
     }
     //销毁水印资源
     $draw->destroy();
     $water->destroy();
 }
示例#23
0
文件: index.php 项目: noikiy/zays
function myaccount_makepic()
{
    global $_MooClass, $uid, $user, $pic_size_arr, $user_arr, $_MooCookie, $last_login_time;
    global $dbTablePre;
    $a = $_MooCookie['tmp_order'];
    $sql = "select count(*) as c from {$dbTablePre}tmp where uid='{$uid}' and staus=0";
    $tmp_num = $_MooClass['MooMySQL']->getOne($sql);
    $sql2 = "select count(*) as count from {$dbTablePre}pic where uid='{$uid}'";
    $pic_num = $_MooClass['MooMySQL']->getOne($sql2);
    $count = $tmp_num['c'] + $pic_num['count'];
    $succes = 'ok';
    if ($count < 20) {
        if (!empty($a)) {
            $tmp_order = $a;
        } else {
            $pic_url = time();
            MooSetCookie("tmp_order", $pic_url);
            $tmp_order = $pic_url;
        }
        //note 设定全局路径
        $orgin = "orgin";
        //note 原图文件夹名
        $thumb_path = PIC_PATH;
        //图片路径
        $thumb_datedir = date("Y/m/d");
        $main_img_path = $thumb_path . "/" . $thumb_datedir . "/" . $orgin . "/";
        //note 调用文件操作类库,建立无限级目录
        $mkdirs = MooAutoLoad('MooFiles');
        !is_dir($main_img_path) && $mkdirs->fileMake($main_img_path, 0777);
        $date = date('YmdHis') . rand(111111, 999999);
        $pic_name = $date . '.jpg';
        $imgurl = $main_img_path . $pic_name;
        $result = file_put_contents($imgurl, file_get_contents('php://input'));
        if (!$result) {
            print "ERROR: Failed to write data to {$imgurl}, check permissions\n";
            exit;
        }
        /* $w = (int)$_POST['width'];
        		$h = (int)$_POST['height'];
        		
        
        		$img = imagecreatetruecolor($w, $h);
        		imagefill($img, 0, 0, 0x669966);
        		$rows = 0;
        		$cols = 0;
        		for($rows = 0; $rows < $h; $rows++){
        			$c_row = explode(",", $_POST['px' . $rows]);
        			for($cols = 0; $cols < $w; $cols++){
        				$value = $c_row[$cols];
        				if($value != ""){
        					$hex = $value;
        					while(strlen($hex) < 6){
        						$hex = "0" . $hex;
        					}
        					$r = hexdec(substr($hex, 0, 2));
        					$g = hexdec(substr($hex, 2, 2));
        					$b = hexdec(substr($hex, 4, 2));
        					$test = imagecolorallocate($img, $r, $g, $b);
        					imagesetpixel($img, $cols, $rows, $test);
        				}
        			}
        		} */
        //header("Content-type:image/jpeg");
        //imagejpeg($img,$imgurl, 90);
        $insertarr = array('uid' => $uid, 'pic_url' => $imgurl, 'tmp_order' => $tmp_order, 'staus' => 0, 'pic_date' => $thumb_datedir, 'pic_name' => $pic_name);
        inserttable('tmp', $insertarr);
        $first = new Imagick($imgurl);
        //写入水印
        $second = new Imagick('public/system/images/logo_original.png');
        //$second->setImageOpacity (0.4);//设置透明度
        $dw = new ImagickDraw();
        $dw->setGravity(Imagick::GRAVITY_SOUTHEAST);
        //设置位置
        //$dw->setGravity(Imagick::GRAVITY_SOUTH);//设置位置
        $dw->composite($second->getImageCompose(), 0, 0, 50, 0, $second);
        $first->drawImage($dw);
        $first->writeImage($imgurl);
        //将第一张图片的大小控制成我们需要的大小
        list($width, $height) = getimagesize($imgurl);
        //note 缩略图路径,大小全局调用
        $thumb1_width = $pic_size_arr["1"]["width"];
        $thumb1_height = $pic_size_arr["1"]["height"];
        $thumb2_width = $pic_size_arr["2"]["width"];
        $thumb2_height = $pic_size_arr["2"]["height"];
        $thumb3_width = $pic_size_arr["3"]["width"];
        $thumb3_height = $pic_size_arr["3"]["height"];
        //note 生成日期目录
        $thumb1_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb1_width . "_" . $thumb1_height . "/";
        $thumb2_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb2_width . "_" . $thumb2_height . "/";
        $thumb3_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb3_width . "_" . $thumb3_height . "/";
        !is_dir($thumb1_path) && $mkdirs->fileMake($thumb1_path, 0777);
        !is_dir($thumb2_path) && $mkdirs->fileMake($thumb2_path, 0777);
        !is_dir($thumb3_path) && $mkdirs->fileMake($thumb3_path, 0777);
        $thumb_filename = md5($date) . '.jpg';
        //生成缩略图1
        $image = MooAutoLoad('MooImage');
        $image->config(array('thumbDir' => $thumb1_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '41', 'waterMarkMinHeight' => '57', 'waterMarkStatus' => 9));
        $image->thumb($thumb1_width, $thumb1_height, $imgurl);
        $image->waterMark();
        //生成缩略图2
        $image = MooAutoLoad('MooImage');
        $b = $width / $thumb2_width;
        $thumb2_height = $height / $b;
        $image->config(array('thumbDir' => $thumb2_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '139', 'waterMarkMinHeight' => '189', 'waterMarkStatus' => 9));
        $image->thumb($thumb2_width, $thumb2_height, $imgurl);
        $image->waterMark();
        //生成缩略图3
        $image = MooAutoLoad('MooImage');
        $b = $width / $thumb3_width;
        $thumb3_height = $height / $b;
        $image->config(array('thumbDir' => $thumb3_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '171', 'waterMarkMinHeight' => '244', 'waterMarkStatus' => 9));
        $image->thumb($thumb3_width, $thumb3_height, $imgurl);
        $image->waterMark();
        //判断照片是否生成
        $succes = '';
    }
    header("Location:index.php?n=myaccount&h=picflash&do=js&succes='{$succes}'");
    //include MooTemplate('public/myaccount_flash', 'module');
}