PHP图片平均分割
Posted LiuLiwei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP图片平均分割相关的知识,希望对你有一定的参考价值。
/** * 图片平均分割 * $h = 23, $w = 8 * 保存:web/upload_pic/Cut */ public function actionCutPng() { $filename = dirname(dirname(dirname(dirname(__FILE__)))).‘webupload_pic est114.png‘; list($width, $height) = getimagesize($filename); $h = 23; $w = 8; $newwidth = floor($width / $w); $newheight = floor($height / $h); $lastH = $height % $h; $lastW = $width % $w; $source = imagecreatefrompng($filename); for( $i=0 ; $i< $h; $i++ ){ for ($j = 0 ; $j < $w ; $j++){ $h_p = $newheight*$i; $w_p = $newwidth*$j; if(($j + 1) == $w ){ $newwidth += $lastW; } if(( $i + 1 ) == $h ){ $newheight += $lastH; } $thumb = ImageCreateTrueColor($newwidth, $newheight); imagecopyresized( $thumb, $source, 0, 0, $w_p, $h_p, $newwidth, $newheight, floor($width / $w),floor($height / $h)); imagejpeg( $thumb , "./upload_pic/Cut/{$i}-{$j}.jpg" ,100); } } }
以上是关于PHP图片平均分割的主要内容,如果未能解决你的问题,请参考以下文章