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); //銷(xiāo)毀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從數(shù)據(jù)庫(kù)讀取數(shù)據(jù),并以json格式返回?cái)?shù)據(jù)的方法
今天小編就為大家分享一篇php從數(shù)據(jù)庫(kù)讀取數(shù)據(jù),并以json格式返回?cái)?shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08ThinkPHP3.1新特性之動(dòng)態(tài)設(shè)置自動(dòng)完成及自動(dòng)驗(yàn)證示例代碼
這篇文章主要介紹了ThinkPHP3.1的動(dòng)態(tài)設(shè)置自動(dòng)完成及自動(dòng)驗(yàn)證功能,需要的朋友可以參考下2014-06-06基于CI框架的微信網(wǎng)頁(yè)授權(quán)庫(kù)示例
這篇文章主要介紹了基于CI框架的微信網(wǎng)頁(yè)授權(quán)庫(kù),結(jié)合實(shí)例形式分析了CI框架整合微信授權(quán)功能及控制器調(diào)用的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-11-11PHP curl模擬登錄帶驗(yàn)證碼的網(wǎng)站
最近接了個(gè)項(xiàng)目,其中有需求是要登錄帶驗(yàn)證碼的網(wǎng)站,獲取數(shù)據(jù),但是我們不可能人為的一直去記錄數(shù)據(jù),想通過(guò)自動(dòng)采集的方式進(jìn)行,下面小編給大家?guī)?lái)的相關(guān)代碼,對(duì)php curl 模擬登錄帶驗(yàn)證碼的網(wǎng)站感興趣的朋友一起學(xué)習(xí)吧2015-11-11基于php+MySql實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)實(shí)例
這篇文章主要介紹了基于php+MySql實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)實(shí)例,文中通過(guò)圖片功能介紹的非常詳細(xì),文章末尾附帶項(xiàng)目源碼,需要的朋友可以參考下2020-08-08php分頁(yè)思路以及在Zend?Framework框架中的使用
php分頁(yè)思路以及在Zend?Framework框架中的使用,需要的朋友可以參考下2012-05-05淺析Yii2 GridView實(shí)現(xiàn)下拉搜索教程
這篇文章主要介紹了淺析Yii2 GridView實(shí)現(xiàn)下拉搜索教程的相關(guān)資料,需要的朋友可以參考下2016-04-04