How PHP implements image compositing and generates watermarks (full code)

Source: Internet
Author: User
Tags imagecopy
This article brings the content is about how PHP to achieve image synthesis and generate watermark (complete code), there is a certain reference value, the need for friends can refer to, I hope to help you.

<?php$dst_path = './upload/goods/2018/06-04/2bd2518a2e4e6d8bdab9f01434b9f754.png '; $src _path = './public/upload/ Weixin/20180620/a643cf1ee7dd5bda12270647ca543f60.png '; $hz = substr (STRRCHR ($dst _path, '. '), 1); $image = Date ("Ymdhis "). Rand (100000,999999).". ". $hz;//Create an instance of the picture $dst = Imagecreatefromstring (file_get_contents ($DST _path)); $src = Imagecreatefromstring (file_get_ Contents ($src _path));//obtain a watermark image of the wide-height $src_w =139; $src _h=58;list ($src _w, $src _h) = getimagesize ($src _path);// If the watermark picture itself is transparent, use the Imagecopy method Imagecopy ($DST, $SRC, 85,85, 0, 0, $src _w, $src _h);//Output Picture list ($src _w, $src _h, $dst _type) =        GetImageSize ($dst _path), switch ($dst _type) {case 1://gif header (' content-type:image/gif '); Imagegif ($DST, ".".                $image);        Break         Case 2://jpg Header (' content-type:image/jpeg '); Imagejpeg ($DST, ".".         $image);     Break         Case 3://png Header (' content-type:image/png '); Imagepng ($DST, ".".         $image);     Break Default:break;} ImAgedestroy ($DST); Imagedestroy ($SRC); return $image;
Related Article

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.