糊涂虫 php,PHP

将根据xml配置,将合并后的大图切割成一系列小图

/**

* 将大图片按照配置切割成一定比例的小图片

* 并按照一定规则给小图片命名

*

* 使用方法:

*根据guardians/g1目录下的Attack_1.xml配置切割Attack_1.png

*也可批量切割(我写的是批量切割)

*

* 注:需要GD2支持

*/

// echo “{${phpinfo()}}”;

header(“Cache-Control:no-cache,must-revalidate”); //不使用缓存

for ($i = 1; $i 

$filename = “guardians/g” . $i . “/Attack_1.png”; //大图文件

$tempdir  = “temp”; //小图存放目录

//判断文件是否存在 不存在就切割完毕

if (file_exists($filename)) {

if (!file_exists($tempdir))

mkdir($tempdir);

}

$xml = simplexml_load_file(“guardians/g” . $i . “/Attack_1.xml”);

echo “guardians/g” . $i . “/Attack_1.xml
”;

$j = 1;

foreach ($xml->SubTexture as $SubTexture) {

$attri = $SubTexture->attributes();

$picW  = $attri->frameWidth; //切割小图的宽

$picH  = $attri->frameHeight;

//为支持大图片增加内存限制

ini_set(‘memory_limit’, ‘220M’); //切割小图的高

echo $picW . “,” . $picH . “
”;

list($width, $height, $type, $attr) = getimagesize($filename);

$image = imagecreatefrompng($filename);

//透明背景

$im = imagecreatetruecolor((int) $picW, (int) $picH) or die(“Cannot Initialize new GD image stream”); //创建小图像

imagealphablending($im, false);

imagesavealpha($im, true);

$white = imagecolorallocatealpha($im, 255, 255, 255, 127);

imagefill($im, 0, 0, $white);

$picX = $attri->width; //获取截取图片的宽度

$picY = $attri->height; //获取截取图片的高度

echo $picX . “,” . $picY . “
”;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值