码迷,mamicode.com
首页 > Web开发 > 详细

PHP图片平均分割

时间:2018-07-16 18:29:22      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:style   idt   14.   from   copy   image   ges   action   jpg   

/**
     * 图片平均分割
     * $h = 23, $w = 8
     * 保存:web/upload_pic/Cut
     */
    public function actionCutPng()
    {
        $filename = dirname(dirname(dirname(dirname(__FILE__)))).‘\web\upload_pic\test114.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图片平均分割

标签:style   idt   14.   from   copy   image   ges   action   jpg   

原文地址:https://www.cnblogs.com/liuliwei/p/9319073.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!