zoukankan      html  css  js  c++  java
  • 图像函数 imagecreatetruecolor()和imagecreate()的异同点

    共同点:这两个函数都是用于创建画布

    区别:

    1.不同的是创建画布和为画布填充颜色的流程不一样;

    用imagecreatetruecolor(int x,int y)创建的是一幅大小为 x和 y的图像(默认为黑色),如想改变背景颜色则需要为画布分配颜色imagecolorallcollate(resource:image,red:int,green:int,blue:int),然后为画布填充颜色函数imagefill(resource:image,int x, int y,$color); 

    具体代码:

    <?php

    //设置文件类型为图像
    header('Content-Type:image/png');

    //创建画布
    $image = imagecreatetruecolor(200,200);

    //为画布分配颜色
    $color = imagecolorallocate($image,174,48,96);

    //填充颜色
    imagefill($image,0,0,$color);

    //生成图像
    imagepng($image);

    //保存图像,生成图像和保存图像需要分为两步,要么只能生成,要么只能保存
    imagepng($image,'./1.png');
    ?>

    用imagecreate(int x,int y)创建的也是一幅大小为 x和 y的图像(默认没有颜色,需要指定颜色),如想改变背景颜色则需要为画布分配颜色imagecolorallcollate(resource:image,red: int,green:int ,blue:int),和上面不同的是不需要填充,因为imagecolorallcollate()在imagecreate()函数创建画布的情况下自动填充.

    具体代码:

    <?php
    //设置文件类型为图像
    header('Content-Type:image/png');

    //创建画布
    $image = imagecreate(200,200);

    //为画布分配颜色并填充画布
    $color = imagecolorallocate($image,174,48,96);

    //生成图像
    imagepng($image);

    //保存图像,生成图像和保存图像需要分为两步,要么只能生成,要么只能保存
    imgaepng($image,'./1.png');
    ?>

    2.支持的颜色数不同,imagecreatetruecolor()支持的颜色更多一些.

  • 相关阅读:
    【转】IOS缓存机制详解
    Soul网关插件之Sofa
    Soul网关代理Dubbo插件的使用
    Soul网关默认Divide插件的使用
    高性能网关Soul源码调试环境搭建
    大厂面试系列一些问题的解答
    大厂面试系列一些问题的答案
    大厂面试系列(十三):Java基础
    大厂面试助手(十二):场景和设计
    Action Filters for ASP.NET MVC
  • 原文地址:https://www.cnblogs.com/fantianlong/p/9898579.html
Copyright © 2011-2022 走看看