php创建sprite


Posted in PHP onFebruary 11, 2014
<?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);       //创建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>
PHP 相关文章推荐
用Socket发送电子邮件(利用需要验证的SMTP服务器)
Oct 09 PHP
一个域名查询的程序
Oct 09 PHP
深入探讨PHP中的内存管理问题
Aug 31 PHP
PHP中strpos、strstr和stripos、stristr函数分析
Jun 11 PHP
PHP命令行执行整合pathinfo模拟定时任务实例
Aug 12 PHP
PHP执行shell脚本运行程序不产生core文件的方法
Dec 28 PHP
PHP实现绘制二叉树图形显示功能详解【包括二叉搜索树、平衡树及红黑树】
Nov 16 PHP
PHP合并两个或多个数组的方法
Jan 20 PHP
php写app用的框架整理
Sep 29 PHP
Laravel5.1 框架响应基本用法实例分析
Jan 04 PHP
phpmyadmin在宝塔面板里进不去的解决方案
Jul 06 PHP
PHP引擎php.ini参数优化深入讲解
Mar 24 PHP
PHP循环结构实例讲解
Feb 10 #PHP
更改localhost为其他名字的方法
Feb 10 #PHP
php 获取SWF动画截图示例代码
Feb 10 #PHP
php导入csv文件碰到乱码问题的解决方法
Feb 10 #PHP
php判断正常访问和外部访问的示例
Feb 10 #PHP
php利用单例模式实现日志处理类库
Feb 10 #PHP
PHP遍历并打印指定目录下所有文件实例
Feb 10 #PHP
You might like
phpmyadmin导入(import)文件限制的解决办法
2009/12/11 PHP
PHP 数据结构 算法描述 冒泡排序 bubble sort
2011/07/10 PHP
ThinkPHP3.1新特性之对Ajax的支持更加完善
2014/06/19 PHP
PHP curl使用实例
2015/07/02 PHP
让焦点自动跳转
2006/07/01 Javascript
JavaScript中变量提升 Hoisting
2012/07/03 Javascript
使用js实现一个可编辑的select下拉列表
2014/02/20 Javascript
js换图片效果可进行定时操作
2014/06/09 Javascript
js实现图片点击左右轮播
2015/07/08 Javascript
jQuery实现输入框下拉列表树插件特效代码分享
2015/08/27 Javascript
jQuery 插件封装的方法
2016/11/16 Javascript
利用Vue.js框架实现火车票查询系统(附源码)
2017/02/27 Javascript
在vue项目中引入高德地图及其UI组件的方法
2018/09/04 Javascript
Vue源码分析之Vue实例初始化详解
2019/08/25 Javascript
微信小程序点击view动态添加样式过程解析
2020/01/21 Javascript
vue 使用v-for进行循环的实例代码详解
2020/02/19 Javascript
vue 使用微信jssdk,调用微信相册上传图片功能
2020/11/13 Javascript
在Python中用get()方法获取字典键值的教程
2015/05/21 Python
Python 列表理解及使用方法
2017/10/27 Python
Python爬虫包BeautifulSoup简介与安装(一)
2018/06/17 Python
对python 自定义协议的方法详解
2019/02/13 Python
python输出电脑上所有的串口名的方法
2019/07/02 Python
django自定义模板标签过程解析
2019/12/14 Python
pytorch 图像中的数据预处理和批标准化实例
2020/01/15 Python
Python中logging日志库实例详解
2020/02/19 Python
基于Python绘制个人足迹地图
2020/06/01 Python
Python 远程开关机的方法
2020/11/18 Python
Boda Skins皮衣官网:奢侈皮夹克,全球配送
2016/12/15 全球购物
中科软测试工程师面试题
2012/06/16 面试题
护理学毕业生自荐信
2013/10/02 职场文书
仓库管理员岗位职责
2014/03/19 职场文书
三八节标语
2014/06/27 职场文书
民主生活会对照检查材料
2014/09/22 职场文书
重阳节演讲稿:尊敬帮助老人 弘扬传统美德
2014/09/25 职场文书
创先争优个人总结
2015/03/04 职场文书
Vue实现下拉加载更多
2021/05/09 Vue.js