<?php
$imagefile = $upload_dir.$_FILES['userfile']['name'];
$opFolder = 'map/';
$opFolder .= $str ;
$opFolder .= "/";
$imgwidth = 1000; // 原图片的高度
$imgheight = 1000; // 原图片的宽度
// 这里可以改为自动获取图片信息,或者不管用户提供多大的图片都统一缩放为1000*1000的图片再做处理
$opimgwidth = 100; // 切出来每张图片的宽度
$opimgheight = 100; // 切出来每张图片的高度
$quality = 100; // 0 ---100 代表图片质量
$img = imagecreatefromjpeg($imagefile);
$widthCount = $imgwidth/$opimgwidth;
$heightCount = $imgheight/$opimgheight;
$index = 0;
//创建目录
createDir("map/");
createDir($opFolder);
for( $i=0; $i < $heightCount; $i++){
for( $j=0; $j < $widthCount; $j++){
$opimg = imagecreatetruecolor ($opimgwidth, $opimgheight); //magecreatetruecolor() 返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的黑色图像。相当于java里的"画布"
$lefttop_x = $opimgwidth * $j;
$lefttop_y = $opimgheight * $i;
$rightbottom_x = $opimgwidth * ($j + 1);
$rightbottom_y = $opimgwidth * ($i + 1);
imagecopy($opimg, $img, 0, 0, $lefttop_x, $lefttop_y, $rightbottom_x, $rightbottom_y);
imagegif($opimg, $opFolder."map_".(++$index).".gif", $quality); //根据具体格式选择
}
}
?>