Copy CodeThe code is as follows:
$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 with IE series
File_put_contents ("./". $dst. CSS ', $css);
Imagepng ($image, "./". $dst. PNG ');
Imagedestroy ($image);
?>
http://www.bkjia.com/PHPjc/733058.html www.bkjia.com true http://www.bkjia.com/PHPjc/733058.html techarticle Copy the code as follows: Php $srcdir = './image/'; $prefix = "pic11_"; $dst = "image"; $imagedir =scandir ($srcdir); Array_shift ($ IMAGEDIR); Array_shift ($imagedir); $width = 0; $height =0;