| Share a PHP implementation of the image processing class, you can set the text watermark and image watermark, etc., there is a need for friends reference. This section to share a picture processing class, simple implementation of the text watermark and image watermark, is a small example of learning PHP image operations. Code:
Image = new Imagick ($tplImage); }/** * Set text Properties * * @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 Tex T size for printing * @param string $color text color to 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-itali C.TTF) * @Creating An array of text properties */Public Function SetText ($sText, $x = 0, $y = 0, $font = a, $color = ' Black ', $text _angle = 0, $font _style = './liberationsans-italic.ttf ') {$this->atextdata[] = Array ("text" = + $sText , "Font_color" and $color, "Font_size" and "X" and $x, "Y" and $y, "Font_style" and "Text_angle $font _style" = $text _angle); }/** * Set picture Properties * * @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 Setima GE ($sImage, $x = 0, $y = 0, $angle =0) {$this->aimagedata[] = Array ("image" + $sImage, "x" = $x, "y" and "= $y," angle "= $angle);} /** * Generate final image from text and picture properties * * @param string $sImage Output image Name * @return Boolean returns TRUE on success and FA LSE 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, call Example:
SetText ("This is one", "a", "a", "Red"); $oImageMagick->settext ("This is", "Blue", "50"); $oImageMagick->setimage ("Brand.jpg", 160, 90, 0); $oImageMagick->setimage ("Tata.jpg", 160, 20); $newImagename = "Mynewimage.jpg"; $oImageMagick->generateimage ($newImagename);?>
|