Php Image Watermarking

Source: Internet
Author: User
You can add watermarks to an image by yourself. Currently, only watermark images are supported. The watermark text code is not complete yet. Thank you for your comments! Call method: First include the class file and then instantiate the class: $ imgnewImages; then provide the image: $ img-imgpath (original image path and name, watermark image path and name); then add water

You can add watermarks to an image by yourself. Currently, only watermark images are supported. The watermark text code is not complete yet. Thank you for your comments! Call method: First include the class file and then instantiate the class: $ img = new Images; then provide the image: $ img-imgpath (original image path and name, watermark image path and name ); add water later

A watermark class for a self-written image. Currently, only watermark images are supported, and the watermark text is not complete yet.
The code is not very complete. Thank you for your comments!
Call method:
First include class files
Then instantiate the class:
$ Img = new Images;
Then provide the image:
$ Img-> imgpath (original image path and name, watermark image path and name );
Then start adding the watermark:
$ Img-> send ();
Note:
The send (strimg filename) method has a function that can be omitted. If it is omitted, the path and name of the saved image are the same as those of the original one. If you want to save the image as an exception, the path and name of the image to be saved are provided here.
In addition, the show () method is used to display the watermark image.
This method can be called independently, but the send () method must be called first or consecutively: $ img-> send ()-> show (); PHPizabi PostgreSQL PHPWind BLOG phpBB
 ImgA = $ oldimg; $ this-> imgB = $ newing; $ this-> weizhi = $ WeiZhi; return $ this;} public function send ($ Name = ''){! Empty ($ Name) or $ Name = $ this-> imgA; list ($ this-> imgWA, $ this-> imgWB, $ this-> typea) = $ this-> imgread ($ this-> imgA); list ($ this-> imgHA, $ this-> imgHB, $ this-> typeb) = $ this-> imgread ($ this-> imgB); $ this-> objecta = $ this-> openimg ($ this-> imgA, $ this-> typea ); $ this-> objectb = $ this-> openimg ($ this-> imgB, $ this-> typeb); $ this-> WZ (); $ this-> start (); $ this-> over ($ Name); return $ this;} private function WZ () {switch ($ this-> weizhi) {case 2: $ this-> X = ($ this-> imgWA-$ this-> imgHA)/2; break; case 3: $ this-> X = ($ this-> imgWA-$ this-> imgHA); break; case 4: $ this-> Y = ($ this-> imgWB-$ this-> imgHB)/2; break; case 5: $ this-> X = ($ this-> imgWA-$ this-> imgHA)/2; $ this-> Y = ($ this-> imgWB-$ this-> imgHB)/2; break; case 6: $ this-> X = ($ this-> imgWA-$ this-> imgHA); $ this-> Y = ($ this-> imgWB-$ this-> imgHB) /2; break; case 7: $ this-> Y = ($ this-> imgWB-$ this-> imgHB); break; case 8: $ this-> X = ($ this-> imgWA-$ this-> imgHA)/2; $ this-> Y = ($ this-> imgWB-$ this-> imgHB); break; case 9: $ this-> X = ($ this-> imgWA-$ this-> imgHA); $ this-> Y = ($ this-> imgWB-$ this-> imgHB ); break; default: $ this-> X = 0; $ this-> Y = 0 ;}} private function openimg ($ FileName = '', $ type = 0) {switch ($ type) {case 1: $ obj = imagecreatefromgif ($ FileName); break; case 2: $ obj = imagecreatefromjpeg ($ FileName); break; case 3: $ obj = imagecreatefrompng ($ FileName); break; default: return false;} return $ obj;} private function start () {imagecopy ($ this-> objecta, $ this-> objectb, $ this-> X, $ this-> Y, 0, 0, $ this-> imgHA, $ this-> imgHB );} private function over ($ name = '1.jpg ') {$ this-> okfile = $ name; switch ($ this-> typea) {case 1: imagegif ($ this-> objecta, $ name); break; case 2: imagejpeg ($ this-> objecta, $ name); break; case 3: imagepng ($ this-> objecta, $ name); break; default: return false;} private function imgread ($ FilePath = '') {$ Arr = getimagesize ($ FilePath); return array ($ Arr [0], $ Arr [1], $ Arr [2]);} public function show () {@ header ('content-type: image /*'); echo @ file_get_contents ($ this-> okfile );}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.