php 切割图片

<?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); //根据具体格式选择
            
        }
    }
    
?>

转载于:https://www.cnblogs.com/nishilunhui/archive/2012/11/30/2796071.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值