PHP generated text watermark and image watermark

Source: Internet
Author: User
Tags imagecopy transparent color

Create a text watermark<?php//Text watermark */* Open picture *///1. Configure picture path $SRC = "4.jpg";//2. Get information about a picture (get basic information about a picture) $info = getimagesize ($SRC);//3. By getting the picture type $type = Image_type_to_extension ($info [2],false);//4. Create a picture of the same image type in memory $fun = "imagecreatefrom{$type}";//5. Picture copied into memory $image = $fun ($SRC);/* manipulate picture *///1. Set the path of the font $font = "Stliti. TTF ";//c disk WINDOWS/FONTS//2. Fill in the watermark $content = ' Hello '//3. Set the color of the font RGB and transparency $col = Imagecolorallocatealpha ($image, 255,255,255,50)//4. Write Text Imagettftext ($image, 20,0,20,30, $col, $font, $content);/* Output picture *///browser Output header (" content-type:{$info [' MIME ']} "$func =" image{$type} "; $func ($image);//Save Picture $func ($image, ' newimage. '). $type)/* Destroy picture */imagedestroy ($image);? >Create a picture watermark<?php $dst _path = ' 4.jpg '; $src _path = ' 1.png ';//Create an instance of the picture $dst = Imagecreatefromstring (file_get_contents ($DST _path)); $SRC = imagecreatefromstring (file_get_contents ($src _path)),//Get the width of the watermark image list ($src _w, $src _h) = getimagesize ($src _path )///To copy the watermark picture to the target image, the last parameter 80 is to set the transparency, here to achieve the translucent effect Imagecopymerge ($DST, $SRC, ten, ten, 0, 0, $src _w, $src _h, 80);//If the watermark picture itself with transparent color, Then use the Imagecopy method//imagecopy ($DST, $SRC, ten, 0, 0, $src _w, $src _h);//Output Picture list ($dst _w, $dst _h, $dst _type) = getimagesize ( $DST _path), switch ($dst _type) {case 1://gifheader (' content-type:image/gif '); Imagegif ($DST); Break;case 2:// Jpgheader (' content-type:image/jpeg '); imagejpeg ($DST); Break;case 3://pngheader (' content-type:image/png '); Imagepng ($DST); break;default:break;} Imagedestroy ($DST); Imagedestroy ($SRC);? >

PHP generated text watermark and image watermark

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.