日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php图片是啥,php图片处理类(附实例)

發(fā)布時(shí)間:2024/9/19 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php图片是啥,php图片处理类(附实例) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

分享一個(gè)php實(shí)現(xiàn)的圖片處理類,可以設(shè)置文字水印與圖片水印等,有需要的朋友參考下。

本節(jié)分享一個(gè)圖片處理類,簡單實(shí)現(xiàn)了文字水印與圖片水印,是學(xué)習(xí)php圖片操作的小例子。

代碼:

image = new Imagick($tplImage);

}

/**

* 設(shè)置文本屬性

*

* @param string $sText text to print on the image (i.e. Buy 1 Get 1 Free )

* @param integer $x text to print from x codinates

* @param integer $y text to print from y codinates

* @param integer $font text size for printing

* @param string $color text color for print

* @param integer $text_anglerotate text from 0-360

* @param string $font_style installed font name and path (i.e /usr/share/fonts/liberation/LiberationSans-Italic.ttf)

* @Creating an array of text properties

*/

public function setText($sText, $x = 0, $y = 0, $font = 12, $color = 'black', $text_angle = 0, $font_style = './LiberationSans-Italic.ttf') {

$this->aTextData[] = array("text"=>$sText, "font_color"=>$color, "font_size"=>$font,"x"=>$x,"y"=>$y, "font_style"=>$font_style,

"text_angle"=>$text_angle);

}

/**

* 設(shè)置圖片屬性

*

* @param string $sImage text to print on the image (i.e. /home/httpd/images/brand.jpg )

* @param integer $x text to print from x codinates

* @param integer $y text to print from y codinates

* @param integer $text_anglerotate text from 0-180

* @Creating an array of image properties

*/

public function setImage($sImage, $x = 0, $y = 0, $angle=0) {

$this->aImageData[] = array("image"=>$sImage, "x"=>$x, "y"=>$y, "angle"=>$angle);

}

/**

* 從文字和圖片屬性生成最終圖像

*

* @param string $sImage Output image Name

* @return boolean returns TRUE on success and FALSE upon failure

*/

public function generateImage($sImage) {

foreach ($this->aImageData as $aImageValue) {

if (!trim($aImageValue["image"])) {

$sError = 1;

break;

}

$oImg = new Imagick($aImageValue["image"]);

$oImg->rotateImage("transparent", $aImageValue["angle"]);

$this->image->compositeImage($oImg, $oImg->getImageCompose(), $aImageValue["x"], $aImageValue["y"]);

unset($oImg);

}

foreach ($this->aTextData as $aTextValue){

if (!trim($aTextValue['text'])) {

$sError = 2;

break;

}

$oDraw = new ImagickDraw();

$oDraw->setFont($aTextValue['font_style']);

$oDraw->setFontSize($aTextValue['font_size']);

$oDraw->setFillColor($aTextValue['font_color']);

$this->image->annotateImage($oDraw, $aTextValue['x'], $aTextValue['y'], $aTextValue['text_angle'], $aTextValue['text']);

unset($oDraw);

}

if ($sError == 1) {

exit("Unable to generate Image. Check \"setImage\" Properties");

}elseif ($sError == 2) {

exit("Unable to generate Image. Check \"setText\" Properties");

}

$this->image->setImageFormat("jpg");

return $this->image->writeImage($sImage);

}

}

?>

2,調(diào)用示例:

setText("This is one", 350, 20, 22, "red");

$oImageMagick->setText("This is Two", 50, 50, 25, "blue","50");

$oImageMagick->setImage("brand.jpg", 160, 90, 0);

$oImageMagick->setImage("tata.jpg", 160, 20);

$newImagename = "mynewImage.jpg";

$oImageMagick->generateImage($newImagename);

?>

總結(jié)

以上是生活随笔為你收集整理的php图片是啥,php图片处理类(附实例)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。