Пример #1
0
 public function watermark($file, $mark_image, $set)
 {
     $obj = new ecae_image();
     $obj->set_file($file);
     $obj->watermark(file_get_contents($mark_image), $set['dest_x'], $set['dest_y'], 0, 0, $set['wm_opacity'] ? $set['wm_opacity'] : 50);
     $content = $obj->exec();
     if ($content) {
         file_put_contents($file, $content);
     }
 }
Пример #2
0
 /**
  * 设置图片水印
  * @param object image 实体对象
  * @param string 文件路径
  * @param array 设置的集合
  * @return null
  */
 function image_watermark(&$imgmdl, $file, $set)
 {
     switch ($set['wm_type']) {
         case 'text':
             $mark_image = $set['wm_text_image'];
             break;
         case 'image':
             $mark_image = $set['wm_image'];
             break;
         default:
             return;
     }
     if ($set['wm_text_preview']) {
         $mark_image = $set['wm_text_image'];
     } else {
         $mark_image = $imgmdl->fetch($mark_image);
     }
     list($watermark_width, $watermark_height, $type) = getimagesize($mark_image);
     list($src_width, $src_height) = getimagesize($file);
     list($dest_x, $dest_y) = self::get_watermark_dest($src_width, $src_height, $watermark_width, $watermark_height, $set['wm_loc']);
     if (ECAE_MODE) {
         include_lib('image.php');
         $obj = new ecae_image();
         $obj->set_file($file);
         $obj->watermark(file_get_contents($mark_image), $dest_x, $dest_y, 0, 0, $set['wm_opacity'] ? $set['wm_opacity'] : 50);
         $content = $obj->exec();
         if ($content) {
             file_put_contents($file, $content);
         }
     } elseif (function_exists('NewMagickWand')) {
         $sourceWand = NewMagickWand();
         $compositeWand = NewMagickWand();
         MagickReadImage($compositeWand, $mark_image);
         MagickReadImage($sourceWand, $file);
         MagickSetImageIndex($compositeWand, 0);
         MagickSetImageType($compositeWand, MW_TrueColorMatteType);
         MagickEvaluateImage($compositeWand, MW_SubtractEvaluateOperator, ($set['wm_opacity'] ? $set['wm_opacity'] : 50) / 100, MW_OpacityChannel);
         MagickCompositeImage($sourceWand, $compositeWand, MW_ScreenCompositeOp, $dest_x, $dest_y);
         MagickWriteImage($sourceWand, $file);
     } elseif (method_exists(image_clip, 'imagecreatefrom')) {
         $sourceimage = self::imagecreatefrom($file);
         $watermark = self::imagecreatefrom($mark_image);
         imagecolortransparent($watermark, imagecolorat($watermark, 0, 0));
         imagealphablending($watermark, 1);
         $set['wm_opacity'] = intval($set['wm_opacity']);
         imagecopymerge($sourceimage, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $set['wm_opacity']);
         imagejpeg($sourceimage, $file);
         imagedestroy($sourceimage);
         imagedestroy($watermark);
     }
     @unlink($mark_image);
 }