This article describes the use of PHP based on the picture in the folder to generate Sprite Composite diagram example, the need for friends can refer to the following
Code as follows: <?php $srcdir = './image/'; $prefix = "pic11_"; $DST = "image"; $imagedir =scandir ($srcdir); Array_shift ($imagedir); Array_shift ($imagedir); $width = 0; $height = 0; foreach ($imagedir as $key => $value) { $picinfo =getimagesize ($srcdir. $value); $width = $picinfo [0]+$ Width if ($height < $picinfo [1]) { $height = $picinfo [1];  }} $image =imagecreatetruecolor ($width, $height) ; Imagesavealpha ($image, true); $color =imagecolorallocatealpha ($image, 0,0,0,127); Imagefill ($image, 0, 0, $color); $width = 0; $height = 0; $css = ""; foreach ($imagedir as $key => $value) { $picinfo =getimagesize ($srcdir. $value); $im =imagecreatefrompng ($ Srcdir. $value); //Create Image imagecopymerge ($image, $im, $width, 0, 0, 0, $picinfo [0], $picinfo [1],100); $picname =pathinfo ($srcdir. $value); $CSS = ".". $prefix. $picname [' filename ']. " {height: ". $picinfo [0]." Px;width: ". $picinfo [1]." Px;background-position:-". $width." px 0px;} ". $css; $width =$width+ $picinfo [0]; imagedestroy ($im); //Destroy image} $css = $css. " [class*= ". $prefix."] {background-image:url (' image.png ');}}; $CSS = $css. ". $prefix. " {background-image:url (' image.png ');} "; //compatible IE series file_put_contents ("./". $dst. ') CSS ', $css); Imagepng ($image, "./". $dst. " PNG '); Imagedestroy ($image);?> <link rel= "stylesheet" type= "Text/css" "href="/image.css "> <!--<img src = "./image.png" >--> <body style= "Background-color: #eee" > <div class= "PIC11_CSS3" > </div > <div class= "Pic11_firefox" > </div> <div class= "Pic11_chrome" > </div> <span class= "CSS3 "> </span> <span class=" Sprite Firefox > </span> </body>