php创建sprite的方法

发布时间:2021-07-26 13:41:45 作者:chen
来源:亿速云 阅读:88

本篇内容主要讲解“php创建sprite的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“php创建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);       //创建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 >
 <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创建sprite的方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. 使用Visual Studio创建图片精灵(Image Sprite)——Web Essential
  2. php创建新对象的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php sprite

上一篇:datepickerrh 定义自己的angular时间组件

下一篇:bootstrap响应式布局中怎么设置图片居中

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》