• PHP GD库---之微信朋友圈9张图


    $item_pic = "img/item.jpg";
    
    list($width, $height) = getimagesize($item_pic);
    
    $item_pic = imagecreatefromjpeg($item_pic);
    
    
    $avg_width = ceil($width / 3);
    $avg_height = ceil($height / 3);
    
    // 创建画布
    for ($i = 1; $i < 10; $i++) {
    
        $image = imagecreatetruecolor($avg_width, $avg_height);
    
        list($source_width, $source_height) = get_source_width_height($avg_width, $avg_height, $i);
    
        imagecopyresampled($image, $item_pic, 0, 0, $source_width, $source_height, $avg_height, $avg_height, $avg_height, $avg_height);
    
        imagejpeg($image, 'img/'.$i.'.jpg');
    
        imagedestroy($image);
    
    }
    
    function get_source_width_height ($avg_width, $avg_height, $i) {
    
        switch ($i) {
            case 1:
                $return_width = 0;
                $return_height = 0;
                break;
            case 2:
                $return_width = $avg_width;
                $return_height = 0;
                break;
            case 3:
                $return_width = $avg_width * 2;
                $return_height = 0;
                break;
            case 4:
                $return_width = 0;
                $return_height = $avg_height;
                break;
            case 5:
                $return_width = $avg_width ;
                $return_height = $avg_height;
                break;
            case 6:
                $return_width = $avg_width * 2;
                $return_height = $avg_height;
                break;
            case 7:
                $return_width = 0;
                $return_height = $avg_height * 2;
                break;
            case 8:
                $return_width = $avg_width;
                $return_height = $avg_height * 2;
                break;
            case 9:
                $return_width = $avg_width * 2;
                $return_height = $avg_height * 2;
                break;
            default;
        }
        return [$return_width, $return_height];
    }
    

      效果

  • 相关阅读:
    python学习笔记(2)
    数据分析工具pandas
    python学习笔记(1)
    python学习笔记(3)
    python学习笔记(2):科学计算及数据可视化入门
    python学习笔记(1):python基础
    js setTimeout 和 setInterval 区别
    C#根据URL生成签名
    jquery.validate.js客户端验证
    redis学习(一)
  • 原文地址:https://www.cnblogs.com/zouzhe0/p/10138446.html
Copyright © 2020-2023  润新知