无需言 做自己 业 ,精于勤 荒于嬉.

GD 和图像处理 函数 imagecopymerge 拷贝并合并图像的一部分

发表日期:2021-07-01 08:55:57 | 来源: | 分类:GD 和图像处理 函数

imagecopymerge

(PHP 4 >= 4.0.1, PHP 5, PHP 7, PHP 8)

imagecopymerge拷贝并合并图像的一部分

说明

imagecopymerge(
    resource $dst_im,
    resource $src_im,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $src_w,
    int $src_h,
    int $pct
): bool

src_im 图像中坐标从 src_xsrc_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_xdst_y 的位置上。两图像将根据 pct 来决定合并程度,其值范围从 0 到 100。当 pct = 0 时,实际上什么也没做,当为 100 时对于调色板图像本函数和 imagecopy() 完全一样,它对真彩色图像实现了 alpha 透明。

注意:

本函数是 PHP 4.0.6 新加的。

阅读全文 »

GD 和图像处理 函数 imagecopymergegray 用灰度拷贝并合并图像的一部分

发表日期:2021-07-01 08:55:57 | 来源: | 分类:GD 和图像处理 函数

imagecopymergegray

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

imagecopymergegray用灰度拷贝并合并图像的一部分

说明

imagecopymergegray(
    resource $dst_im,
    resource $src_im,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $src_w,
    int $src_h,
    int $pct
): bool

src_im 图像中坐标从 src_xsrc_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_xdst_y 的位置上。两图像将根据 pct 来决定合并程度,其值范围从 0 到 100。当 pct = 0 时,实际上什么也没做,当为 100 时本函数和 imagecopy() 完全一样。

本函数和 imagecopymerge() 完全一样只除了合并时通过在拷贝操作前将目标像素转换为灰度级来保留了原色度。

注意:

本函数添加于 PHP 4.0.6。

阅读全文 »

GD 和图像处理 函数 imageconvolution 用系数 div 和 offset 申请一个 3x3 的卷积矩阵

发表日期:2021-07-01 08:55:57 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$image = imagecreatefromgif('http://www.php.net/images/php.gif');
$emboss = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
imageconvolution($image, $emboss, 1, 127);
header('Content-Type: image/png');
imagepng($image, null, 9);
?>
      示例2
<?php 
$image = imagecreatetruecolor(180,40);
// Writes the text and apply a gaussian blur on the imageimagestring($image, 5, 10, 8, 'Gaussian Blur Text', 0x00ff00);
$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
imageconvolution($image, $gaussian, 16, 0);
// Rewrites the text for comparisonimagestring($image, 5, 10, 18, 'Gaussian Blur Text', 0x00ff00);
header('Content-Type: image/png');
imagepng($image, null, 9);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorresolvealpha 取得指定颜色 + alpha 的索引值或有可能得到的最接近的替代值

发表日期:2021-07-01 08:55:57 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
// Load an image$im = imagecreatefromgif('phplogo.gif');
// Get closest colors from the image$colors = array();
$colors[] = imagecolorresolvealpha($im, 255, 255, 255, 0);
$colors[] = imagecolorresolvealpha($im, 0, 0, 200, 127);
// Outputprint_r($colors);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorexact 取得指定颜色的索引值

发表日期:2021-07-01 08:55:57 | 来源: | 分类:GD 和图像处理 函数

imagecolorexact

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecolorexact取得指定颜色的索引值

说明

imagecolorexact(
    resource $image,
    int $red,
    int $green,
    int $blue
): int

返回图像调色板中指定颜色的索引值。

如果颜色不在图像的调色板中,返回 -1。

如果从文件创建了图像,只有图像中使用了的颜色会被辨析。仅出现在调色板中的颜色不会被辨析。

参见 imagecolorclosest()

阅读全文 »

GD 和图像处理 函数 getimagesizefromstring 从字符串中获取图像尺寸信息

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$img = '/path/to/test.png';
// 以文件方式打开$size_info1 = getimagesize($img);
// 以字符串格式打开$data       = file_get_contents($img);
$size_info2 = getimagesizefromstring($data);
?>

阅读全文 »

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 和图像处理 函数 image_type_to_mime_type 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的图像类型的 MIME 类型

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG));
?>

阅读全文 »

GD 和图像处理 函数 image2wbmp 以 WBMP 格式将图像输出到浏览器或文件

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$file = 'php.jpg';
$image = imagecreatefrompng($file);
header('Content-type: ' . image_type_to_mime(IMAGETYPE_WBMP));
image2wbmp($file);
 // output the stream directly?>

阅读全文 »

GD 和图像处理 函数 imagealphablending 设定图像的混色模式

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
// Create image$im = imagecreatetruecolor(100, 100);
// Set alphablending to onimagealphablending($im, true);
// Draw a squareimagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0));
// Outputheader('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imageaffinematrixconcat Concatenate two affine transformation matrices

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$m1 = imageaffinematrixget(IMG_AFFINE_TRANSLATE, array('x' = 2, 'y' => 3));
$m2 = imageaffinematrixget(IMG_AFFINE_SCALE, array('x' = 4, 'y' => 5));
$matrix = imageaffinematrixconcat($m1, $m2);
print_r($matrix);
?>

阅读全文 »

GD 和图像处理 函数 getimagesize 取得图像大小

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr>";
?>

      示例2
<?php 
$size = getimagesize("http://www.example.com/gifs/logo.gif");
// if the file name has space in it, encode it properly$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
?>

      示例3
<?php 
$size = getimagesize($filename);
$fp=fopen($filename, "rb");
if ($size && $fp) {
  header("Content-type: {
$size['mime']}
");
  fpassthru($fp);
  exit;
}
 else {
  // error}
?>

      示例4
<?php 
$size = getimagesize("testimg.jpg", &$info);
if (isset($info["APP13"])) {
    $iptc = iptcparse($info["APP13"]);
    var_dump($iptc);
}
?>

      示例5
<?php 
$size = getimagesize($filename);
$fp = fopen($filename, "rb");
if ($size && $fp) {
    header("Content-type: {
$size['mime']}
");
    fpassthru($fp);
    exit;
}
 else {
    // error}
?>

      示例6
<?php 
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>

      示例7
<?php 
$size = getimagesize("http://www.example.com/gifs/logo.gif");
// if the file name has space in it, encode it properly$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
?>

      示例8
<?php 
$size = getimagesize("testimg.jpg", $info);
if (isset($info["APP13"])) {
    $iptc = iptcparse($info["APP13"]);
    var_dump($iptc);
}
?>

阅读全文 »

GD 和图像处理 函数 imageantialias 是否使用抗锯齿(antialias)功能

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
// Setup an anti-aliased image and a normal image$aa = imagecreatetruecolor(400, 100);
$normal = imagecreatetruecolor(200, 100);
// Switch antialiasing on for one imageimageantialias($aa, true);
// Allocate colors$red = imagecolorallocate($normal, 255, 0, 0);
$red_aa = imagecolorallocate($aa, 255, 0, 0);
// Draw two lines, one with AA enabledimageline($normal, 0, 0, 200, 100, $red);
imageline($aa, 0, 0, 200, 100, $red_aa);
// Merge the two images side by side for output (AA: left, Normal: Right)imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100);
// Output imageheader('Content-type: image/png');
imagepng($aa);
imagedestroy($aa);
imagedestroy($normal);
?>

阅读全文 »

GD 和图像处理 函数 imagebmp Output a BMP image to browser or file

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
// Create a blank image and add some text$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'BMP with PHP', $text_color);
// Save the imageimagebmp($im, 'php.bmp');
// Free up memoryimagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagearc 画椭圆弧

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
// 创建一个 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, $black);
// 将图像输出到浏览器header("Content-type: image/png");
imagepng($img);
// 释放内存imagedestroy($img);
?>

阅读全文 »

GD 和图像处理 函数 imagechar 水平地画一个字符

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$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 cornerimagechar($im, 1, 0, 0, $string, $black);
header('Content-type: image/png');
imagepng($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorallocate 为一幅图像分配颜色

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$im = imagecreate('example.jpg', 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);
?>

阅读全文 »

GD 和图像处理 函数 imageaffinematrixget Get an affine transformation matrix

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$matrix = imageaffinematrixget(IMG_AFFINE_TRANSLATE, array('x' => 2, 'y' => 3));
print_r($matrix);
?>

阅读全文 »

GD 和图像处理 函数 imagecharup 垂直地画一个字符

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$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 backgroundimagecharup($im, 3, 10, 10, $string, $black);
header('Content-type: image/png');
imagepng($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorallocatealpha 为一幅图像分配颜色 + alpha

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
$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);
?>
      示例2
<?php 
$size = 300;
$image=imagecreatetruecolor($size, $size);
// something to get a white background with black border$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;
// allocate colors with alpha values$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$red    = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue   = imagecolorallocatealpha($image, 0, 0, 255, 75);
// drawing 3 overlapped circleimagefilledellipse($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);
// don't forget to output a correct header!header('Content-Type: image/png');
// and finally, output the resultimagepng($image);
imagedestroy($image);
?>

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2025 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。