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