GD 和图像处理 函数 业 ,精于勤 荒于嬉.
- GD 和图像处理 函数 gd_info 取得当前安装的 GD 库的信息
-
发表日期:2021-07-01 08:55:55 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
var_dump(gd_info());
3
?>
- GD 和图像处理 函数 getimagesize 取得图像大小
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
list(
$width
,
$height
,
$type
,
$attr
) =
getimagesize
(
"img/flag.jpg"
);
3
echo
"<img src=\"img/flag.jpg\" $attr>"
;
4
?>
示例2
1
<?php
2
$size
=
getimagesize
(
"http://www.example.com/gifs/logo.gif"
);
3
// if the file name has space in it, encode it properly$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
4
?>
示例3
01
<?php
02
$size
=
getimagesize
(
$filename
);
03
$fp
=
fopen
(
$filename
,
"rb"
);
04
if
(
$size
&&
$fp
) {
05
header("Content-type: {
06
$size
[
'mime'
]}
07
");
08
fpassthru
(
$fp
);
09
exit
;
10
}
11
else
{
12
// error}
13
?>
示例4
1
<?php
2
$size
=
getimagesize
(
"testimg.jpg"
, &
$info
);
3
if
(isset(
$info
[
"APP13"
])) {
4
$iptc
= iptcparse(
$info
[
"APP13"
]);
5
var_dump(
$iptc
);
6
}
7
?>
示例5
01
<?php
02
$size
=
getimagesize
(
$filename
);
03
$fp
=
fopen
(
$filename
,
"rb"
);
04
if
(
$size
&&
$fp
) {
05
header("Content-type: {
06
$size
[
'mime'
]}
07
");
08
fpassthru
(
$fp
);
09
exit
;
10
}
11
else
{
12
// error}
13
?>
示例6
1
<?php
2
list(
$width
,
$height
,
$type
,
$attr
) =
getimagesize
(
"img/flag.jpg"
);
3
echo
"<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />"
;
4
?>
示例7
1
<?php
2
$size
=
getimagesize
(
"http://www.example.com/gifs/logo.gif"
);
3
// if the file name has space in it, encode it properly$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
4
?>
示例8
1
<?php
2
$size
=
getimagesize
(
"testimg.jpg"
,
$info
);
3
if
(isset(
$info
[
"APP13"
])) {
4
$iptc
= iptcparse(
$info
[
"APP13"
]);
5
var_dump(
$iptc
);
6
}
7
?>
- GD 和图像处理 函数 getimagesizefromstring 从字符串中获取图像尺寸信息
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
$img
=
'/path/to/test.png'
;
3
// 以文件方式打开$size_info1 = getimagesize($img);
4
// 以字符串格式打开$data = file_get_contents($img);
5
$size_info2
= getimagesizefromstring(
$data
);
6
?>
- GD 和图像处理 函数 image_type_to_extension 取得图像类型的文件后缀
-
发表日期:2021-07-01 08:55:55 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
// 创建图像实例$im = imagecreatetruecolor(100, 100);
3
// 保存图像imagepng($im, './test' . image_type_to_extension(IMAGETYPE_PNG));
4
imagedestroy(
$im
);
5
?>
- GD 和图像处理 函数 image_type_to_mime_type 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的图像类型的 MIME 类型
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
header(
"Content-type: "
. image_type_to_mime_type(IMAGETYPE_PNG));
3
?>
- GD 和图像处理 函数 image2wbmp 以 WBMP 格式将图像输出到浏览器或文件
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
$file
=
'php.jpg'
;
3
$image
= imagecreatefrompng(
$file
);
4
header(
'Content-type: '
. image_type_to_mime(IMAGETYPE_WBMP));
5
image2wbmp(
$file
);
6
// output the stream directly?>
- GD 和图像处理 函数 imageaffine 返回经过仿射变换后的图像,剪切区域可选
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
imageaffine
(PHP 5 >= 5.5.0, PHP 7, PHP 8)
imageaffine — 返回经过仿射变换后的图像,剪切区域可选
说明
imageaffine(resource$image
, array$affine
, array$clip
= ?): resource警告本函数还未编写文档,仅有参数列表。
参数
-
image
-
由图象创建函数(例如imagecreatetruecolor())返回的图象资源。
-
affine
-
数组,其中键为 0 至 5 的数字。
-
clip
-
数组,其中键为 "x","y","width" 和 "height"。
返回值
成功则返回仿射变换后的图像, 或者在失败时返回
false
. -
- GD 和图像处理 函数 imageaffinematrixconcat Concatenate two affine transformation matrices
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
$m1
= imageaffinematrixget(IMG_AFFINE_TRANSLATE,
array
(
'x'
= 2,
'y'
=> 3));
3
$m2
= imageaffinematrixget(IMG_AFFINE_SCALE,
array
(
'x'
= 4,
'y'
=> 5));
4
$matrix
= imageaffinematrixconcat(
$m1
,
$m2
);
5
print_r(
$matrix
);
6
?>
- GD 和图像处理 函数 imageaffinematrixget Get an affine transformation matrix
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
$matrix
= imageaffinematrixget(IMG_AFFINE_TRANSLATE,
array
(
'x'
=> 2,
'y'
=> 3));
3
print_r(
$matrix
);
4
?>
- GD 和图像处理 函数 imagealphablending 设定图像的混色模式
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
// Create image$im = imagecreatetruecolor(100, 100);
3
// Set alphablending to onimagealphablending($im, true);
4
// Draw a squareimagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0));
5
// Outputheader('Content-type: image/png');
6
imagepng(
$im
);
7
imagedestroy(
$im
);
8
?>
- GD 和图像处理 函数 imageantialias 是否使用抗锯齿(antialias)功能
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
01
<?php
02
// Setup an anti-aliased image and a normal image$aa = imagecreatetruecolor(400, 100);
03
$normal
= imagecreatetruecolor(200, 100);
04
// Switch antialiasing on for one imageimageantialias($aa, true);
05
// Allocate colors$red = imagecolorallocate($normal, 255, 0, 0);
06
$red_aa
= imagecolorallocate(
$aa
, 255, 0, 0);
07
// Draw two lines, one with AA enabledimageline($normal, 0, 0, 200, 100, $red);
08
imageline(
$aa
, 0, 0, 200, 100,
$red_aa
);
09
// Merge the two images side by side for output (AA: left, Normal: Right)imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100);
10
// Output imageheader('Content-type: image/png');
11
imagepng(
$aa
);
12
imagedestroy(
$aa
);
13
imagedestroy(
$normal
);
14
?>
- GD 和图像处理 函数 imagearc 画椭圆弧
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
// 创建一个 200X200 的图像$img = imagecreatetruecolor(200, 200);
3
// 分配颜色$white = imagecolorallocate($img, 255, 255, 255);
4
$black
= imagecolorallocate(
$img
, 0, 0, 0);
5
// 画一个黑色的圆imagearc($img, 100, 100, 150, 150, 0, 360, $black);
6
// 将图像输出到浏览器header("Content-type: image/png");
7
imagepng(
$img
);
8
// 释放内存imagedestroy($img);
9
?>
- GD 和图像处理 函数 imagebmp Output a BMP image to browser or file
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
// Create a blank image and add some text$im = imagecreatetruecolor(120, 20);
3
$text_color
= imagecolorallocate(
$im
, 233, 14, 91);
4
imagestring(
$im
, 1, 5, 5,
'BMP with PHP'
,
$text_color
);
5
// Save the imageimagebmp($im, 'php.bmp');
6
// Free up memoryimagedestroy($im);
7
?>
- GD 和图像处理 函数 imagechar 水平地画一个字符
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
$im
= imagecreate(100,100);
3
$string
=
'PHP'
;
4
$bg
= imagecolorallocate(
$im
, 255, 255, 255);
5
$black
= imagecolorallocate(
$im
, 0, 0, 0);
6
// prints a black "P" in the top left cornerimagechar($im, 1, 0, 0, $string, $black);
7
header(
'Content-type: image/png'
);
8
imagepng(
$im
);
9
?>
- GD 和图像处理 函数 imagecharup 垂直地画一个字符
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
$im
= imagecreate(100,100);
3
$string
=
'Note that the first letter is a N'
;
4
$bg
= imagecolorallocate(
$im
, 255, 255, 255);
5
$black
= imagecolorallocate(
$im
, 0, 0, 0);
6
// prints a black "Z" on a white backgroundimagecharup($im, 3, 10, 10, $string, $black);
7
header(
'Content-type: image/png'
);
8
imagepng(
$im
);
9
?>
- GD 和图像处理 函数 imagecolorallocate 为一幅图像分配颜色
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
$im
= imagecreate(
'example.jpg'
, 100, 100);
3
// 背景设为红色$background = imagecolorallocate($im, 255, 0, 0);
4
// 设定一些颜色$white = imagecolorallocate($im, 255, 255, 255);
5
$black
= imagecolorallocate(
$im
, 0, 0, 0);
6
// 十六进制方式$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
7
$black
= imagecolorallocate(
$im
, 0x00, 0x00, 0x00);
8
?>
- GD 和图像处理 函数 imagecolorallocatealpha 为一幅图像分配颜色 + alpha
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
示例1
01
<?php
02
$size
= 300;
03
$image
=imagecreatetruecolor(
$size
,
$size
);
04
// 用白色背景加黑色边框画个方框$back = imagecolorallocate($image, 255, 255, 255);
05
$border
= imagecolorallocate(
$image
, 0, 0, 0);
06
imagefilledrectangle(
$image
, 0, 0,
$size
- 1,
$size
- 1,
$back
);
07
imagerectangle(
$image
, 0, 0,
$size
- 1,
$size
- 1,
$border
);
08
$yellow_x
= 100;
09
$yellow_y
= 75;
10
$red_x
= 120;
11
$red_y
= 165;
12
$blue_x
= 187;
13
$blue_y
= 125;
14
$radius
= 150;
15
// 用 alpha 值分配一些颜色$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
16
$red
= imagecolorallocatealpha(
$image
, 255, 0, 0, 75);
17
$blue
= imagecolorallocatealpha(
$image
, 0, 0, 255, 75);
18
// 画三个交迭的圆imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
19
imagefilledellipse(
$image
,
$red_x
,
$red_y
,
$radius
,
$radius
,
$red
);
20
imagefilledellipse(
$image
,
$blue_x
,
$blue_y
,
$radius
,
$radius
,
$blue
);
21
// 不要忘记输出正确的 header!header('Content-type: image/png');
22
// 最后输出结果imagepng($image);
23
imagedestroy(
$image
);
24
?>
示例2
01
<?php
02
$size
= 300;
03
$image
=imagecreatetruecolor(
$size
,
$size
);
04
// something to get a white background with black border$back = imagecolorallocate($image, 255, 255, 255);
05
$border
= imagecolorallocate(
$image
, 0, 0, 0);
06
imagefilledrectangle(
$image
, 0, 0,
$size
- 1,
$size
- 1,
$back
);
07
imagerectangle(
$image
, 0, 0,
$size
- 1,
$size
- 1,
$border
);
08
$yellow_x
= 100;
09
$yellow_y
= 75;
10
$red_x
= 120;
11
$red_y
= 165;
12
$blue_x
= 187;
13
$blue_y
= 125;
14
$radius
= 150;
15
// allocate colors with alpha values$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
16
$red
= imagecolorallocatealpha(
$image
, 255, 0, 0, 75);
17
$blue
= imagecolorallocatealpha(
$image
, 0, 0, 255, 75);
18
// drawing 3 overlapped circleimagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
19
imagefilledellipse(
$image
,
$red_x
,
$red_y
,
$radius
,
$radius
,
$red
);
20
imagefilledellipse(
$image
,
$blue_x
,
$blue_y
,
$radius
,
$radius
,
$blue
);
21
// don't forget to output a correct header!header('Content-Type: image/png');
22
// and finally, output the resultimagepng($image);
23
imagedestroy(
$image
);
24
?>
- GD 和图像处理 函数 imagecolorat 取得某像素的颜色索引值
-
发表日期:2021-07-01 08:55:57 | 来源: | 分类:GD 和图像处理 函数
-
示例1
1
<?php
2
$im
= ImageCreateFromPng(
"rockym.png"
);
3
$rgb
= ImageColorAt(
$im
, 100, 100);
4
$r
= (
$rgb
>> 16) & 0xFF;
5
$g
= (
$rgb
>> 8) & 0xFF;
6
$b
=
$rgb
& 0xFF;
7
?>
- GD 和图像处理 函数 imagecolorclosest 取得与指定的颜色最接近的颜色的索引值
-
发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数
-
imagecolorclosest
(PHP 4, PHP 5, PHP 7, PHP 8)
imagecolorclosest — 取得与指定的颜色最接近的颜色的索引值
说明
imagecolorclosest(
resource$image
,
int$red
,
int$green
,
int$blue
): int返回图像调色板中与指定的 RGB 值最“接近”的颜色。
指定的颜色与调色板中的每个颜色的“距离”的计算方法是把 RGB 值当成三维空间中点的坐标。
如果从文件创建了图像,只有图像中使用了的颜色会被辨析。仅出现在调色板中的颜色不会被辨析。
- GD 和图像处理 函数 imagecolorclosestalpha 取得与指定的颜色加透明度最接近的颜色
-
发表日期:2021-07-01 08:55:57 | 来源: | 分类:GD 和图像处理 函数
-
示例1
01
<?php
02
// Start with an image and convert it to a palette-based image$im = imagecreatefrompng('figures/imagecolorclosest.png');
03
imagetruecolortopalette(
$im
, false, 255);
04
// Search colors (RGB)$colors = array( array(254, 145, 154, 50), array(153, 145, 188, 127), array(153, 90, 145, 0), array(255, 137, 92, 84));
05
// Loop through each search and find the closest color in the palette.// Return the search number, the search RGB and the converted RGB matchforeach($colors as $id => $rgb){
06
$result
= imagecolorclosestalpha(
$im
,
$rgb
[0],
$rgb
[1],
$rgb
[2],
$rgb
[3]);
07
$result
= imagecolorsforindex(
$im
,
$result
);
08
$result
= "({
09
$result
[
'red'
]}
10
, {
11
$result
[
'green'
]}
12
, {
13
$result
[
'blue'
]}
14
, {
15
$result
[
'alpha'
]}
16
)";
17
echo
"#
$id
: Search (
$rgb
[0],
$rgb
[1],
$rgb
[2],
$rgb
[3]);
18
Closest match:
$result
.\n";
19
}
20
imagedestroy(
$im
);
21
?>
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)