function segmentation($w, $h, $dir,$filename)
{
//获取原图wdith和height
list($width, $height) = getimagesize($dir.$filename);
//分割后大小
$newwidth = floor($width / $w);
$newheight = floor($height / $h);
//复制
$source = imagecreatefrompng($dir.$filename);
for ($i = 0; $i < $h; $i++) {
for ($j = 0; $j < $w; $j++) {
$startY = $i * $newheight;
$startX = $j * $newwidth;
$thumb = ImageCreateTrueColor($newwidth, $newheight);
//结果对象,来源对象,结果对象x起点,结果对象y起点,来源对象x起点,来源对象y起点,需要的width,需要的height
imagecopy($thumb, $source, 0, 0, $startX, $startY, $newwidth, $newheight);
$n++;
imagepng($thumb, "$dir$n.png", 9);
}
}
}
segmentation(横格数, 纵格数, 图片目录,图片名称)
本文链接:
https://www.dnwfb.com/5887.html,转载请注明出处。
评论0