PHP GD库画彩票走势图,表格类型图像创建,也可以直接输出为html table表格

网站有演示,可以去看看

调用方法


        for ($i = 0; $i < 22; $i++) {
            $data[] = [
                $i,$i,$i,$i,$i%10?0:false,$i,$i,$i,$i%10?0:null,$i,$i,$i
            ];
        }

        createTableImgHelper::createImage($data, [], '', 12, '#444', '#999', '#f9f9f9');
        createTableImgHelper::echoImage();exit;

帖两张效果图

 

<?php
/* 
 * Copyright (c) 2018-2020 http://www.levme.com All rights reserved.
 * 
 * 创建时间:2020-09-11 12:53
 *
 * 项目:basic-2.0.26  -  $  - createTable.php
 *
 * 作者:liwei  Levme.com <675049572@qq.com>
 */


namespace app\modules\lotterys\widgets\lottimgWidget;

use app\gii\generators\crud\Generator;
use app\modules\lotterys\tjLotteryHelper;
use levmecom\aalevme\levHelpers;
use yii\helpers\ArrayHelper;

class createTableImgHelper extends createChartImg {}

class createChartImg
{
    public static $font = __DIR__ . '/static/ttf/simsun.ttf';

    public static $im = null;
    public static $imgWidth = null;//图像宽高自动计算,你只能通过调节$leftPadding $upPadding开改变它
    public static $imgHeight = null;

    /**
     * false=空行=rowspan 表示占行(与下一行对应格合并)
     * null=空列=colspan 表示占列(与下一列对应格合并)
     * null与false不能相阾,因为不科学
     * @param array $data
     * @param array $dataColor [2=>[2=>['bg'=>[2,levHelpers::hexToRgb('F4606C'),['r'=>255,'g'=>255,'b'=>255]]]]]
     * @param string $title
     * @param int $txtSize
     * @param string $bgColor
     * @param string $brColor
     * @param string $txtColor
     * @param int $calibHeight
     * @param int $outLine
     * @param int $margin
     * @param int $border
     * @param int $leftPadding
     * @param int $upPadding
     * @param int $titleSize
     * @param bool $align
     * @param string $font
     */
    public static function createImage($data, $dataColor = [], $title = '', $txtSize = 20, $bgColor = '', $brColor = '', $txtColor = '', $pointLine = ['ff9600', 2], $calibHeight = 0, $outLine = 2, $margin = 5, $border = 1, $leftPadding = 0, $upPadding = 0, $titleSize = 0, $align = true, $font = '') {
//        $data = [
//            [false, '好列', null, null, '占两列',  null, '占两列',   false],//false 表示占行(与下一行对应格合并)
//            ['2', null, '占两列', null, '占两列', '占两列',  '占两行',  false],//null 表示占列(与下一列对应格合并)
//            [false, '好列', '1',  '好列',null, '占两列', false,   false],   //null与false不能相阾,因为不科学
//            ['好列', '好列', '好列',null, '占两列', '占两列',   '12345',  false],
//            [null, '占两列', null, '占两列', '好列', '占两列',  '好列',  '好列'],
//            [null, '占两列', null, '占两列', '好列', '占两列',  '好列',  '好列'],
//            [null, '占两列', null, '占两列', '好列', '占两列',  '好列',  '好列'],
//            [null, '占两列', null, '占两列', '好列', '占两列',  '好列',  '好列'],
//            [null, '占两列', null, '占两列', '好列', '占两列',  '好列',  '好列'],
//        ];
//        $dataColor = [
//            1=>[
//                2=>[
//                    'bg'=>[
//                        2,//1:整个td格背景;2:椭圆形背景
//                        levHelpers::hexToRgb('fff'),//td背景色
//                        ['r'=>255,'g'=>0,'b'=>0],//td字体色
//                        'point' => [2,2],//连线点(行号,列号)
//                    ],
//                ]
//            ],
//            2=>[
//                2=>[
//                    'bg'=>[
//                        2,
//                        levHelpers::hexToRgb('F4606C'),
//                        ['r'=>255,'g'=>255,'b'=>255],
//                        'point' => [],
//                    ],
//                ]
//            ],
//        ];

        ini_set('memory_limit', '10240M');
        $font = $font ?: static::$font;
        $data && $data = array_values($data);
        $dataRow = count($data);

        $upPadding   = $upPadding   ?: round($txtSize / 1.6);//上下内边距
        $leftPadding = $leftPadding ?: round($txtSize / 1.6);//左内边距
        $titleSize   = $titleSize   ?: round($txtSize * 1.2);//标题字体大小

        $pointBorder = $pointLine[1] ?: $border;

        $rowHeight = $txtSize + 2 + $upPadding*2 + $border;//行高

        //计算标题写入起始位置
        if ($title) {
            $ttfBox = imagettfbbox($titleSize, 0, $font, $title);
            $titleWidth = $ttfBox[2] - $ttfBox[0];//右下角 X 位置 - 左下角 X 位置 为文字宽度
            $titleHeight = $titleSize + 2 + $upPadding*2;
        }else {
            $titleWidth = $titleHeight = 0;
        }

        foreach ($data as $dk => $v) {
            $k = -1;
            foreach ($v as $r) {
                $k++;
                if ($r !== null && $r !== false) {
                    $ttfBox = imagettfbbox($txtSize, 0, $font, $r);
                    $colWidth[$k][] = $ttfBox[2] - $ttfBox[0] + $leftPadding*2 + $border;
                }else {
                    $colWidth[$k][] = 0;
                }
            }
        }
        //取最大文字宽度
        foreach ($colWidth as $k => $v) {
            $colMaxWidth[$k] = max($v);
        }//print_r($colMaxWidth);

        $imgWidth = array_sum($colMaxWidth) + $margin*2 + $outLine*2 - $border;//图片宽度
        $imgHeight = $rowHeight * $dataRow + $margin*2 + $titleHeight + $outLine*2 - $border;//图片高度
        static::$imgWidth = $imgWidth;
        static::$imgHeight = $imgHeight;

        $xCol = $margin + $outLine;
        $yRow = $margin + $outLine + $titleHeight;

        $columnLines = [];
        forea
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值