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); //根据具体格式选择
                
            }
        }
        
    ?>
  • 相关阅读:
    转贴"三个月内通过Adsense赚一百万美金"
    今天申请了Google Adsense
    Asp.Net Core 多样性的配置来源
    Identity第二章
    Identity第一章
    Identity第三章 Authorize原理解析
    async和await
    ASP.Net Core简介
    【学习笔记】后缀数组 SA
    题解 [NOI2009] 植物大战僵尸
  • 原文地址:https://www.cnblogs.com/nishilunhui/p/2796071.html
Copyright © 2011-2022 走看看