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從數(shù)據(jù)庫讀取數(shù)據(jù),并以json格式返回?cái)?shù)據(jù)的方法
今天小編就為大家分享一篇php從數(shù)據(jù)庫讀取數(shù)據(jù),并以json格式返回?cái)?shù)據(jù)的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
ThinkPHP3.1新特性之動態(tài)設(shè)置自動完成及自動驗(yàn)證示例代碼
這篇文章主要介紹了ThinkPHP3.1的動態(tài)設(shè)置自動完成及自動驗(yàn)證功能,需要的朋友可以參考下2014-06-06
PHP curl模擬登錄帶驗(yàn)證碼的網(wǎng)站
最近接了個(gè)項(xiàng)目,其中有需求是要登錄帶驗(yàn)證碼的網(wǎng)站,獲取數(shù)據(jù),但是我們不可能人為的一直去記錄數(shù)據(jù),想通過自動采集的方式進(jìn)行,下面小編給大家?guī)淼南嚓P(guān)代碼,對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í)例,文中通過圖片功能介紹的非常詳細(xì),文章末尾附帶項(xiàng)目源碼,需要的朋友可以參考下2020-08-08
php分頁思路以及在Zend?Framework框架中的使用
php分頁思路以及在Zend?Framework框架中的使用,需要的朋友可以參考下2012-05-05
淺析Yii2 GridView實(shí)現(xiàn)下拉搜索教程
這篇文章主要介紹了淺析Yii2 GridView實(shí)現(xiàn)下拉搜索教程的相關(guān)資料,需要的朋友可以參考下2016-04-04

