php-GD库的函数(一)
<?php
//getimagesize - 取得图片的大小[即长与宽]
//print_r(getimagesize("./logo_i.gif"));
//Array ( [0] => 240 [1] => 124 [2] => 1 [3] => width="240" height="124" [bits] => 8 [channels] => 3 [mime] => image/gif ) //image_type_to_mime_type - 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的图像类型的 MIME 类型
//$aa = getimagesize("./logo_i.gif");
//print_r(image_type_to_mime_type ($aa)); //imagearc — 画椭圆弧
/*bool imagearc(resource $image ,int $cx ,int $cy ,int $w ,int $h , int $s , int $e , int $color);
//$image:资源
//$cx:左边离圆心的位置
//$cy:上边离圆心的位置
//$w:圆形的直径左右
//$h:圆形的直径上下
//$s:0度顺时针画
//$e:360
//$color:圆形的颜色
// 创建一个 200X200 的图像
$img = imagecreatetruecolor(200, 200);
// 分配颜色
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
// 画一个白色的圆
imagearc($img, 100, 100, 150, 150, 0, 360, $white);
// 将图像输出到浏览器
header("Content-type: image/png");
imagepng($img);
// 释放内存
imagedestroy($img);*/ //imagechar — 水平地画一个字符
/*bool imagechar ( resource $image , int $font , int $x , int $y , string $c , int $color )
$image:资源
$font:字体大小
$x:文字离左边框的距离
$y:文字离上边框的距离
$c:将字符串 c 的第一个字符画在 image 指定的图像中
$color:文字的颜色
$im = imagecreate(100,100);
$string = 'php';
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// prints a black "P" in the top left corner
imagechar($im, 1, 0, 0, $string, $black);
header('Content-type: image/png');
imagepng($im);*/ //imagecharup — 垂直地画一个字符
/*bool imagecharup ( resource $image , int $font , int $x , int $y , string $c , int $color )
$image:资源
$font:字体大小
$x:文字离左边框的距离
$y:文字离上边框的距离
$c:将字符串 c 的第一个字符画在 image 指定的图像中
$color:文字的颜色
$im = imagecreate(100,100);
$string = 'Note that the first letter is a N';
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// prints a black "Z" on a white background
imagecharup($im, 3, 10, 10, $string, $black);
header('Content-type: image/png');
imagepng($im);
*/ //imagecolorallocate — 为一幅图像分配颜色
/*int imagecolorallocate ( resource $image , int $red , int $green , int $blue )
$image:图片资源
$red,$green,$blue分别是所需要的颜色的红,绿,蓝成分。这些参数是 0 到 255 的整数或者十六进制的 0x00 到 0xFF
第一次对 imagecolorallocate() 的调用会给基于调色板的图像填充背景色
$im = imagecreate( 100, 100);
// 背景设为红色
$background = imagecolorallocate($im, 255, 0, 0);
// 设定一些颜色
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// 十六进制方式
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
header('Content-type: image/png');
imagepng($im);
*/ //imagecolorallocatealpha — 为一幅图像分配颜色 + alpha
/*int imagecolorallocatealpha ( resource $image , int $red , int $green , int $blue , int $alpha )
imagecolorallocatealpha() 的行为和 imagecolorallocate() 相同,但多了一个额外的透明度参数 alpha,其值从 0 到 127。0 表示完全不透明,127 表示完全透明。
$size = 300;
$image=imagecreatetruecolor($size, $size);
// 用白色背景加黑色边框画个方框
$back = imagecolorallocate($image, 255, 255, 255);
$border = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back);
imagerectangle($image, 0, 0, $size - 1, $size - 1, $border);
$yellow_x = 100;
$yellow_y = 75;
$red_x = 120;
$red_y = 165;
$blue_x = 187;
$blue_y = 125;
$radius = 150;
// 用 alpha 值分配一些颜色
$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$red = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
// 画三个交迭的圆
imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red);
imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue);
// 不要忘记输出正确的 header!
header('Content-type: image/png');
// 最后输出结果
imagepng($image);
imagedestroy($image);
*/ //imagecolordeallocate — 取消图像颜色的分配
/*bool imagecolordeallocate ( resource $image , int $color )
imagecolordeallocate() 函数取消先前由 imagecolorallocate() 或 imagecolorallocatealpha() 分配的颜色。
$im = imagecreate( 100, 100);
// 背景设为红色
$background = imagecolorallocate($im, 255, 0, 0);
// 设定一些颜色
$white = imagecolorallocate($im, 255, 255, 255);
imagecolordeallocate($im,$white);
header('Content-type: image/png');
imagepng($im);*/ //imagecolorexact — 取得指定颜色的索引值
/*int imagecolorexact ( resource $image , int $red , int $green , int $blue )
返回图像调色板中指定颜色的索引值。
如果颜色不在图像的调色板中,返回 -1。
如果从文件创建了图像,只有图像中使用了的颜色会被辨析。仅出现在调色板中的颜色不会被辨析。
$im = imagecreate( 100, 100);
// 背景设为红色
$background = imagecolorallocate($im, 255, 0, 0);
// 设定一些颜色
$white = imagecolorallocate($im, 255, 255, 255);
$aa = imagecolorexact ($im, 255, 0, 0);
echo $aa; //不存在返回-1*/ //imagecolorset — 给指定调色板索引设定颜色
/*void imagecolorset ( resource $image , int $index , int $red , int $green , int $blue )
本函数将调色板中指定的索引设定为指定的颜色。
$im = imagecreate( 100, 100);
$background = imagecolorallocate($im, 255, 0, 0);
for($c = 0;$c<50;$c++){
imagecolorset($im,$c,255,255,255 );
}
header('Content-type: image/png');
imagepng($im);*/ //imagecolortransparent — 将某个颜色定义为透明色
/*int imagecolortransparent ( resource $image [, int $color ] )
imagecolortransparent() 将 image 图像中的透明色设定为 color。image 是 imagecreatetruecolor() 返回的图像标识符,color 是 imagecolorallocate() 返回的颜色标识符。
$im = imagecreate(100,100);
$background = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent ($im,$background);
header('Content-type: image/png');
imagepng($im);*/ ?>
php-GD库的函数(一)的更多相关文章
- GD库常用函数
创建句柄 imagecreate($width, $height) //新建图像 imagecreat ...
- PHP的GD库
GD库 PHP通过GD库,可以对JPG.PNG.GIF.SWF等图片进行处理.GD库常用在图片加水印,验证码生成等方面. 绘制线条 要对图形进行操作,首先要新建一个画布,通过imagecreatetr ...
- gd库
1.开启GD库扩展 去掉注释: extension=php_gd2.dll extension_dir='ext目录所在位置' 2.检测GD库是否开启 phpinfo(); //检测扩展是够开启 ex ...
- GD库处理图像
在PHP5中,动态图象的处理要比以前容易得多.PHP5在php.ini文件中包含了GD扩展包,只需去掉GD扩展包的相应注释就可以正常使用了.PHP5包含的GD库正是升级的GD2库,其中包含支持真彩图像 ...
- PHP->利用GD库新建图像
1.确认php中GD库是否开启 在PHP配置文件php.ini中查找extension=php_gd2.dll,去掉前边的(分号) ';' 即可,一般php是默认开启的 2.绘画步骤 创建一个画布(画 ...
- php中GD库的简单使用
在php中需要图像处理的地方GD库会发挥重要的作用,php可以创建并处理包括GIF,PNG,JPEG,WBMP以及XPM在内的多种图像格式,简单的举几个例子: 1.用GD库会创建一块空白图片,然后绘制 ...
- 安装GD库解决ThinkPHP 验证码Call to undefined function Think\imagecreate()出错
在php中imagecreate函数是一个图形处理函数,主要用于新建一个基于调色板的图像了,然后在这个基础上我们可以创建一些图形数字字符之类的,但这个函数需要GD库支持,如果没有开启GD库使用时会提示 ...
- PHP图形图像处理之初识GD库
d=====( ̄▽ ̄*)b 引语 php不仅仅局限于html的输出,还可以创建和操作各种各样的图像文件,如GIF.PNG.JPEG.WBMP.XBM等. php还可以将图像流直接显示在浏览器中. 要处 ...
- 解决PHP开启gd库无效的问题
最近需要重新安装PHP,以前一直使用的都是XAMPP,基本上都不需要自己配置,现在准备直接下载官方原版的Apache和PHP,自己来慢慢摸索如何继承配置. 我下载的Apache版本为2.2.25,PH ...
- GD库使用小结---2
接着上一篇.GD库可以折腾很多用法出来,当然得跟画图相关,除了前面的验证码.水印外,还可以进行图片的缩放,裁剪.旋转等操作,这在很多应用中可以见到. 1. 加水印 前面已经知道,我们可以使用image ...
随机推荐
- MFC socket网络通讯核心代码
服务器: AfxSocketInit();//初始化,必须执行这个函数socket才能正常执行 server.Create(10086); server.Listen(10); while(1) { ...
- Android ListView A~Z快速索引(改进版)
上一篇文章虽然实现了ListView 快速索引的效果,但是有一个小小的Bug.这个Bug我在前面也说了,这篇文章就来解决这个Bug. 我研究的时候发现只要showBg值为true,中间的字母就显示,而 ...
- myeclipse 2013 git
1. 2.添加site http://download.eclipse.org/egit/updates-2.3 3.安装 完成后,查看windows->preference的team下面有gi ...
- Hadoop 6、第一个mapreduce程序 WordCount
1.程序代码 Map: import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.h ...
- Walking Ant(一道有意思的蚂蚁游戏,bfs)
Walking Ant Time Limit: 2 Seconds Memory Limit: 65536 KB Ants are quite diligent. They sometime ...
- 开源企业IM-免费企业即时通讯-ENTBOOST V2014.180 Linux版本号正式公布
ENTBOOST,VERSION 2014.180 Linux版本号公布,主要添加企业IM应用集成功能,完好安卓SDK功能及部分BUG修正: 7/1(明天)公布Windows版本号,敬请关注! ENT ...
- 解决Win7&Win8 64位下Source Insight提示未完整安装的问题
网上的破解版的注册表文件都是针对32位系统的,所以在64位系统里运行根本无法破解.下面分别贴出这俩系统里的破解文件. 使用方法: 分别复制对应系统的内容,新建文本文档,将内容粘贴进去,重命名为.reg ...
- 【最大流之EdmondsKarp算法】【HDU1532】模板题
题意:裸的最大流,什么是最大流,参考别的博客 运用复杂度最高的EK算法 O(M*N),模板来自紫书 #include <cstdio> #include <cstdlib> # ...
- java命令行运行main时jar及其配置
run.bat中的内容如: set mypath=%cd%/../set classpath=%mypath%\conf;%mypath%\lib\*start /b java -Xms64m -Xm ...
- 关于Console的Main(String[] args)参数输入
之前接触一个往Console里输入参数的项目,资深QA教我怎么run,灰常脸红. 今日无事,baidu之. Step1 写简单Console Code. class Program { static ...