PHP compositing pictures, generating text, centering, drawing lines, rectangles, triangles, polygons, images anti-aliasing, non-distortion high-performance source code example

Source: Internet
Author: User

functionGenerateimg ($source,$text 1,$text 2,$text 3,$font= './msyhbd.ttf ') {    $date= '.Date(' YMD '). ‘/‘; $img=$date.MD5($source.$text 1.$text 2.$text 3) . '. jpg '; if(file_exists( ‘./‘ .$img )) {        return $img; }     $main= Imagecreatefromjpeg ($source ); $width= Imagesx ($main ); $height= Imagesy ($main ); $target= Imagecreatetruecolor ($width,$height ); $white= Imagecolorallocate ($target, 255, 255, 255 ); Imagefill ($target, 0, 0,$white ); Imagecopyresampled ($target,$main, 0, 0, 0, 0,$width,$height,$width,$height ); $fontSize= 18;//Pixel Font    $fontColor= Imagecolorallocate ($target, 255, 0, 0);//the RGB color of the word    $fontBox= Imagettfbbox ($fontSize, 0,$font,$text 1);//Text horizontal centered essenceImagettftext ($target,$fontSize, 0,Ceil(($width-$fontBox[2])/2), 190,$fontColor,$font,$text 1 ); $fontBox= Imagettfbbox ($fontSize, 0,$font,$text 2); Imagettftext ($target,$fontSize, 0,Ceil(($width-$fontBox[2])/2), 370,$fontColor,$font,$text 2 ); $fontBox= Imagettfbbox ($fontSize, 0,$font,$text 3); Imagettftext ($target,$fontSize, 0,Ceil(($width-$fontBox[2])/2), 560,$fontColor,$font,$text 3 ); //Imageantialias ($target, true);//antialiasing, some PHP versions are problematic, use sparinglyImagefilledpolygon ($target,Array(10 + 0, 0 + 142, 0, 12 + 142, 20 + 0, 12 + 142), 3,$fontColor);//Draw a triangleImageline ($target, 100, 200, 20, 142,$fontColor);//Draw LineImagefilledrectangle ($target, 50, 100, 250, 150,$fontColor);//Draw Rectangle//bof of composition pictures    $child 1= Imagecreatefromjpeg (' http://gtms01.alicdn.com/tps/i1/T1N0pxFEhaXXXxK1nM-357-88.jpg ' ); Imagecopymerge ($target,$child 1, 0, 0, 0, Imagesx ($child 1), Imagesy ($child 1), 100 ); //EOF of composite pictures     @mkdir( ‘./‘ .$date ); Imagejpeg ($target, ‘./‘ .$img, 95 ); Imagedestroy ($main ); Imagedestroy ($target ); Imagedestroy ($child 1 ); return $img;}//http://my.oschina.net/cart/Generateimg (' http://1.popular.sinaapp.com/munv/pic.jpg ', ' my.oschina.net/cart ', ' PHP text horizontally centered ', ' 3 words ' );Exit();

PHP compositing pictures, generating text, centering, drawing lines, rectangles, triangles, polygons, picture antialiasing, undistorted high-performance source code examples

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.