分割png图片

/***
* 分割图片
*/
public function cut_img(){
$filename = 'site_upload/form_file_forinput/20180313/20180313191121824939294.png';
$p = 3;
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width;
$newheight = floor($height / $p);
$last = $height % $p;
// Load
$source = imagecreatefrompng($filename);
for( $i=0 ; $i< $p; $i++ ){

$_p = $newheight*$i;
if(( $i + 1 ) == $p)
$newheight += $last;
$thumb = ImageCreateTrueColor($newwidth, $newheight);
imagecopyresized( $thumb, $source, 0, 0, 0, $_p, $newwidth, $height, $width, $height);
header('Content-type: image/png');
imagepng( $thumb , "site_upload/form_file_forinput/20180313/t{$i}.png" );
imagedestroy($thumb);
}

echo 'end';exit;
}
原文地址:https://www.cnblogs.com/pansidong/p/8625166.html