<?PHP//1. Drawing an image resource (creating a canvas)$image= Imagecreatetruecolor (500, 300);//2. First assign a green$green= Imagecolorallocate ($image, 22, 153, 0);//3. Fill the canvas with greenImagefill ($image, 0, 0,$green);//4. Drawing images in the canvas$bai= Imagecolorallocate ($image, 255, 255, 255);//parameter 1: $DST _img destination, Target image resource//Parameter 2: $SRC _img original source, created by imagecreatefromjpeg PNG//Parameter 3, 4: Target image resource X, y coordinate//parameter 5, 6: The beginning of the original collection x, y coordinates//Parameters 7, 8: The original width, height$src _img= Imagecreatefrompng (' bs.png ');//Get the height of the image resource by using PHP's function imagesx () to obtain the width of the image resource, Imagesy ()$src _w= Imagesx ($src _img);$src _h= Imagesy ($src _img); Imagecopy ($image,$src _img, 0, 0, 0, 0,$src _w,$src _h);//5. Output image resources directly in the browserHeader("Content-type:image/jpeg"); Imagejpeg ($image);//6. Destroying image ResourcesImagedestroy ($image);
Draw a picture onto the canvas: Imagecopy ()