php創(chuàng)建sprite
<?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); //創(chuàng)建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); //銷毀image
}
$css=$css."[class*=".$prefix."]{background-image:url('image.png');}}";
$css=$css.".".$prefix."{background-image:url('image.png');}"; //兼容ie 系列
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>
相關(guān)文章
php中單個(gè)數(shù)據(jù)庫(kù)字段多列顯示(單字段分頁(yè)、橫向輸出)
這篇文章主要介紹了php中單個(gè)數(shù)據(jù)庫(kù)字段多列顯示、分行分列顯示技巧,也可稱為單字段分頁(yè)、橫向輸出,需要的朋友可以參考下2014-07-07
thinkphp3.2同時(shí)連接兩個(gè)數(shù)據(jù)庫(kù)的簡(jiǎn)單方法
這篇文章主要給大家介紹了關(guān)于thinkphp3.2同時(shí)連接兩個(gè)數(shù)據(jù)庫(kù)的簡(jiǎn)單方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用thinkphp3.2具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
php解析非標(biāo)準(zhǔn)json、非規(guī)范json的方式實(shí)例
php 將bmp圖片轉(zhuǎn)為jpg等其他任意格式的圖片
通過(guò)修改配置真正解決php文件上傳大小限制問(wèn)題(nginx+php)
php版微信公眾平臺(tái)開(kāi)發(fā)之驗(yàn)證步驟實(shí)例詳解

