• 8.PHP图像处理


    PHP图像处理

    GD2


    Jpgraph


    创建一个画布:

    <?php
        header('content-type:image/gif');
        //echo "你好";
        $im = imagecreate(200,60);
        $white = imagecolorallocate($im ,225 ,66 ,159);
        imagegif($im);
    ?>


    显示一张图片

    <?php
            function LoadPNG($imgname)
            {
                /* Attempt to open */
                $im = @imagecreatefromjpeg($imgname);
                /* See if it failed */
                if(!$im){
                    echo "aaa";
                    /* Create a blank image */
                    $im  = imagecreatetruecolor(150,40);
                    $bgc = imagecolorallocate($im255255255);
                    $tc  = imagecolorallocate($im000);
                    imagefilledrectangle($im0015040$bgc);
                    /* Output an error message */
                    imagestring($im155'bb ' $imgname$tc);
                }
                return $im;
            }

            header('Content-Type: image/jpeg');
            $img = LoadPNG('p.jpg');
            imagepng($img);
            imagedestroy($img);
    ?>


    随机生成验证码:

    <?php
        session_start();
        header('Content-Type: image/png');
        $image_width 70;
        $image_height 18;
        srand(microtime()*100000);
        $new_number '';
        for($i ;$i ;$i ++){
            $new_number.=dechex(rand(,15));
        }
        $_SESSION['check_checks'] = $new_number;
        $num_image = imagecreate($image_width ,$image_height);
        imagecolorallocate($num_image ,255 ,255 ,255);
        for($i ;$i < strlen($_SESSION['check_checks']) ;$i ++){
            $font = mt_rand(,5);
            $x = mt_rand(,8) + $image_width $i 4;
            $y = mt_rand(,$image_height 4);
            $color imagecolorallocate($num_image ,mt_rand(0,100,mt_rand(,150,mt_rand(,200));
            imagestring($num_image ,$font ,$x ,$y,$_SESSION['check_checks'][$i,$color);
        }
        imagepng($num_image);
        imagedestroy($num_image);
    ?>


    创建一个柱形图

    <?php
        include ("src/jpgraph.php");
        include ("src/jpgraph_bar.php");
        $datay array(160 ,180 ,203 ,289 ,405 ,488 ,489 ,408 ,299 ,166 ,187 ,205);
        $graph new Graph(600 ,300 ,"auto");
        $graph -> SetScale("textlin");
        $graph -> yaxis -> scale -> SetGrace(20);
        $graph -> SetShadow();
        $graph -> img -> SetMargin(40 ,30 ,30 ,40);
        $bplot new BarPlot($datay);
        $bplot -> SetFillColor('orange');
        $bplot -> value -> Show();
        $bplot -> value -> SetFormat('%d');
        $graph -> Add($bplot);
        $graph -> SetMarginColor("lightblue");
        $graph -> title -> Set("tit");
        $a array(,,,,,,,,,10 ,11 ,12);
        $graph -> xaxis -> SetTickLabels($a);
        $graph -> title -> SetFont(FF_SIMSUN);
        $graph -> xaxis -> SetFont(FF_SIMSUN);
        $graph -> Stroke();
    ?>


    绘制折线图

    <?php
        include ("src/jpgraph.php");
        include ("src/jpgraph_line.php");
        $datay array(160 ,180 ,203 ,289 ,405 ,488 ,489 ,408 ,299 ,166 ,187 ,500);
        $graph new Graph(600 ,300 ,"auto");
        $graph -> img -> SetMargin(50 ,40 ,30 ,40);
        $graph -> img -> SetAntiAliasing();
        $graph -> SetScale("textlin");
        $graph -> SetShadow();
        $graph -> title -> Set("tit");
        $graph -> title -> SetFont(FF_SIMSUN ,FS_BOLD);
        $graph -> SetMarginColor("lightblue");
        $graph -> yaxis ->title -> SetFont(FF_SIMSUN);
        $graph -> xaxis -> SetPos("min");
        $graph -> yaxis -> HideZeroLabel();
        $graph -> ygrid -> SetFill(true ,'#EFEFEF@0.5' ,'#BBCCFF@0.5');


        $a array(,,,,,,,,,10 ,11 ,12);
        $graph -> xaxis -> SetTickLabels($a);
        $graph -> xaxis -> SetFont(FF_SIMSUN);
        $graph -> yscale -> SetGrace(20);

        $p1 new LinePlot($datay);
        $p1 -> mark -> SetType(MARK_FILLEDCIRCLE);
        $p1  -> mark ->SetFillColor('red');
        $p1 -> mark ->SetWidth(4);
        $p1 -> SetColor('blue');
        $p1 -> SetCenter();
        $graph -> Add($p1);
        $graph -> Stroke();
    ?>


    3D饼状图

    <?php
        include ("src/jpgraph.php");
        include ("src/jpgraph_pie.php");
        include ("src/jpgraph_pie3d.php");

        $data array(160 ,180 ,203 ,289 ,405 ,500 );
        $graph new PieGraph(540 ,260 ,"auto");
        $graph -> SetShadow();

        $graph -> title -> Set("tit");
        $graph -> title -> SetFont(FF_SIMSUN ,FS_BOLD);
        $graph -> legend -> SetFont(FF_SIMSUN ,FS_NORMAL);

        $p1 new PiePlot3D($data);
        $p1 -> SetLegends(array('11','22','33','44','55','66'));

        $targ array("pie3d_csimex1.php?v=1","pie3d_csimex1.php?v=2","pie3d_csimex1.php?v=3","pie3d_csimex1.php?v=4","pie3d_csimex1.php?v=5","pie3d_csimex1.php?v=6");
        $alts array("val=%d" ,"val=%d" ,"val=%d" ,"val=%d" ,"val=%d" ,"val=%d");
        $p1 -> SetCSIMTargets($targ ,$alts);
        $p1 -> SetCenter(0.4 ,0.5);
        $graph -> Add($p1);
        $graph -> StrokeCSIM();
    ?>


  • 相关阅读:
    sprintf使用
    Android ListView保持选中项高亮
    Creational Patterns创建型模式
    C和指针终于看到指针这一章
    C++随笔001
    TCP reset
    开始看设计模式英文版了
    Excel条件求和
    linux中安装软件,查看、卸载已安装软件方法
    linux vi文本编辑器三种模式切换及常用操作
  • 原文地址:https://www.cnblogs.com/csnd/p/12062048.html
Copyright © 2020-2023  润新知