php大图片切割
<?php
$imagefile ="aa.jpg";
$opFolder = 'map/';
$opFolder .= $str ;
$opFolder .= "/";
$fileinfo=getimagesize($imagefile); //获取图片的信息
$imgwidth =$fileinfo['0']; // 原图片的高度
$imgheight =$fileinfo['1']; // 原图片的宽度
//这里可以改为自动获取图片信息,或者不管用户提供多大的图片都统一缩放为1000*1000的图片再做处理
$opimgwidth = 750; // 切出来每张图片的宽度
$opimgheight = 750; // 切出来每张图片的高度
$split_number=ceil($imgheight / $opimgheight);
$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++){
$now_number=$i+1;
if($split_number==$now_number){
$opimgheight=$imgheight - (($split_number - 1) * $opimgheight);
}
//echo $i."===".$j."====".$opimgheight."====".++$index."<br/>";
$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);
//header('Content-Type: image/jpeg');
//imagegif($opimg, $opFolder."map_".(++$index).".gif", $quality); //根据具体格式选择
//imagejpeg($opimg, $opFolder."map_".(++$index).".jpg", $quality); //根据具体格式选择
$new_imgurl=$opFolder."map_".($i+1).".jpg";
imagejpeg($opimg, $new_imgurl, $quality); //根据具体格式选择
echo "<div style='width:750px;'><img src=".$new_imgurl." border=0 align=absmiddle></div>";
}
}
?>
$imagefile ="aa.jpg";
$opFolder = 'map/';
$opFolder .= $str ;
$opFolder .= "/";
$fileinfo=getimagesize($imagefile); //获取图片的信息
$imgwidth =$fileinfo['0']; // 原图片的高度
$imgheight =$fileinfo['1']; // 原图片的宽度
//这里可以改为自动获取图片信息,或者不管用户提供多大的图片都统一缩放为1000*1000的图片再做处理
$opimgwidth = 750; // 切出来每张图片的宽度
$opimgheight = 750; // 切出来每张图片的高度
$split_number=ceil($imgheight / $opimgheight);
$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++){
$now_number=$i+1;
if($split_number==$now_number){
$opimgheight=$imgheight - (($split_number - 1) * $opimgheight);
}
//echo $i."===".$j."====".$opimgheight."====".++$index."<br/>";
$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);
//header('Content-Type: image/jpeg');
//imagegif($opimg, $opFolder."map_".(++$index).".gif", $quality); //根据具体格式选择
//imagejpeg($opimg, $opFolder."map_".(++$index).".jpg", $quality); //根据具体格式选择
$new_imgurl=$opFolder."map_".($i+1).".jpg";
imagejpeg($opimg, $new_imgurl, $quality); //根据具体格式选择
echo "<div style='width:750px;'><img src=".$new_imgurl." border=0 align=absmiddle></div>";
}
}
?>