<?php
$maxW=700;
//图片路径
$link= "c:\\aa.jpg";
$img = imagecreatefromjpeg($link);
list($width, $height, $type, $attr) = getimagesize($link);
$maxH=$maxW*($height/$width);
$widthnum=ceil($width/$maxW);
$heightnum=ceil($height/$maxH);
$iOut = imagecreatetruecolor ($maxW,$maxH);
$width2=$width/2;
$height2=$height/2;
$maxW2=$maxW/2;
$maxH2=$maxH/2;
$w=$width2-$maxW2;
$h=$height2-$maxH2;
//将 src_im 图像中坐标从 src_x,src_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_x 和 dst_y 的位置上。
//整图循环切割
for ($i=0;$i < $heightnum;$i++) {
for ($j=0;$j < $widthnum;$j++) {
imagecopy($iOut,$img,0,0,$w,$h,$maxW,$maxH);//复制图片的一部分
echo $w."<br/>".$h."<br/>";
imagejpeg($iOut,"c:\\".$i."_".$j.".jpg"); //输出成0_0.jpg,0_1.jpg这样的格式
}
}
$maxW=700;
//图片路径
$link= "c:\\aa.jpg";
$img = imagecreatefromjpeg($link);
list($width, $height, $type, $attr) = getimagesize($link);
$maxH=$maxW*($height/$width);
$widthnum=ceil($width/$maxW);
$heightnum=ceil($height/$maxH);
$iOut = imagecreatetruecolor ($maxW,$maxH);
$width2=$width/2;
$height2=$height/2;
$maxW2=$maxW/2;
$maxH2=$maxH/2;
$w=$width2-$maxW2;
$h=$height2-$maxH2;
//将 src_im 图像中坐标从 src_x,src_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_x 和 dst_y 的位置上。
//整图循环切割
for ($i=0;$i < $heightnum;$i++) {
for ($j=0;$j < $widthnum;$j++) {
imagecopy($iOut,$img,0,0,$w,$h,$maxW,$maxH);//复制图片的一部分
echo $w."<br/>".$h."<br/>";
imagejpeg($iOut,"c:\\".$i."_".$j.".jpg"); //输出成0_0.jpg,0_1.jpg这样的格式
}
}