| Share an image processing class implemented by php. you can set text watermarks and image watermarks. For more information, see.
This section shares an image processing class, which implements text and image watermarks. it is a small example of learning php image operations.
Code:
Image = new Imagick ($ tplImage);}/*** set the text attribute ** @ 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 instal Led 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, "tex T_angle "=> $ text_angle);}/*** set image attributes ** @ 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-> aImag EData [] = array ("image" => $ sImage, "x" => $ x, "y" => $ y, "angle" => $ angle );} /*** generate final image from text and image attributes ** @ 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 _ Ange'], $ 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", 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);?> |