zoukankan      html  css  js  c++  java
  • 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); //根据具体格式选择
                
            }
        }
        
    ?>
  • 相关阅读:
    255以内全一的二进制数
    XP下ubuntu双系统安装方法
    数据库的增删改查
    网安团队建设
    链表相关操作
    操作系统及其他----面试
    排序算法之----快速排序
    排序算法之----希尔排序
    排序算法之----选择排序&插入排序
    排序算法之----冒泡排序
  • 原文地址:https://www.cnblogs.com/nishilunhui/p/2796071.html
Copyright © 2011-2022 走看看