本文整理汇总了PHP中ImagickDraw::composite方法的典型用法代码示例。如果您正苦于以下问题:PHP ImagickDraw::composite方法的具体用法?PHP ImagickDraw::composite怎么用?PHP ImagickDraw::composite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImagickDraw
的用法示例。
在下文中一共展示了ImagickDraw::composite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_composite
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: renderImage
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: watermark
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: renderImage
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: water
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:
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");
}
示例7: list
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: waterMark
/**
* 加给图片加水印
*
* @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: add_watermark
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: waterMark
/**
* @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: material_imgactive
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);
//.........这里部分代码省略.........
示例12: resize_and_crop
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;
//.........这里部分代码省略.........
示例13: watermark
/**
* 添加水印
*/
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: addWaterMark
/**
* 加给图片加水印
* @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: transform
//.........这里部分代码省略.........
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":