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

GD 和图像处理 函数 imagegd 将 GD 图像输出到浏览器或文件

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

imagegd

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

imagegd将 GD 图像输出到浏览器或文件

说明

imagegd(resource $image, string $filename = ?): bool

imagegd() 将一个 GD 图像输出到 filenameimage 参数是由 imagecreatetruecolor() 函数返回的。

filename 参数为可选项,如果为空,则原始图像流会被直接输出。

注意:

GD 格式一般是用来加载图像中的一部分时更快。注意 GD 格式只能用于兼容于 GD 的应用程序。

参见 imagegd2()

阅读全文 »

GD 和图像处理 函数 imagegif 输出图象到浏览器或文件。

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

      示例1
<?php 
// 创建新的图像实例$im = imagecreatetruecolor(100, 100);
// 设置背景为白色imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF);
//在图像上写字imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00);
// 输出图像到浏览器header('Content-Type: image/gif');
imagegif($im);
imagedestroy($im);
?>

      示例2
<?php 
// 载入 PNG$png = imagecreatefrompng('./php.png');
// 以 GIF 保存图像imagegif($png, './php.gif');
// 释放内存imagedestroy($png);
// 完工echo 'Converted PNG image to GIF with success!';
?>

      示例3
<?php 
// 创建新的图像实例$im = imagecreatetruecolor(100, 100);
// 在这里对图像进行一些操作// 处理输出if(function_exists('imagegif')){
    // 针对 GIF    header('Content-Type: image/gif');
    imagegif($im);
}
elseif(function_exists('imagejpeg')){
    // 针对 JPEG    header('Content-Type: image/jpeg');
    imagejpeg($im, NULL, 100);
}
elseif(function_exists('imagepng')){
    // 针对 PNG    header('Content-Type: image/png');
    imagepng($im);
}
elseif(function_exists('imagewbmp')){
    // 针对 WBMP    header('Content-Type: image/vnd.wap.wbmp');
    imagewbmp($im);
}
else{
    imagedestroy($im);
    die('No image support in this PHP server');
}
// 如果发现图像是以上的格式之一,就从内存中释放if($im){
    imagedestroy($im);
}
?>

      示例4
<?php 
if(imagetypes() & IMG_GIF){
    header('Content-Type: image/gif');
    imagegif($im);
}
elseif(imagetypes() & IMG_JPG){
    /* ... etc. */
}
?>

阅读全文 »

GD 和图像处理 函数 imagedashedline 画一虚线

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

imagedashedline

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

imagedashedline画一虚线

说明

imagedashedline(
    resource $image,
    int $x1,
    int $y1,
    int $x2,
    int $y2,
    int $color
): bool

反对使用本函数。应该用 imagesetstyle()imageline() 的组合替代之。

阅读全文 »

GD 和图像处理 函数 imagegetclip Get the clipping rectangle

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

      示例1
<?php 
$im = imagecreate(100, 100);
imagesetclip($im, 10,10, 89,89);
print_r(imagegetclip($im));


阅读全文 »

GD 和图像处理 函数 imagegetinterpolation Get the interpolation method

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

imagegetinterpolation

(PHP 8)

imagegetinterpolationGet the interpolation method

说明

imagegetinterpolation(GdImage $image): int

Gets the currently set interpolation method of the image.

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的图象资源。

返回值

Returns the interpolation method.

更新日志

版本 说明
8.0.0 image expects a GdImage instance now; previously, a resource was expected.

参见

阅读全文 »

GD 和图像处理 函数 imageistruecolor 检查图像是否为真彩色图像

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

      示例1
<?php 
// $im is an image instance// Check if image is a true color image or notif(!imageistruecolor($im)){
    // Create a new true color image instance    $tc = imagecreatetruecolor(imagesx($im), imagesy($im));
    imagecopy($tc, $im, 0, 0, 0, 0, imagesx($im), imagesy($im));
    imagedestroy($im);
    $im = $tc;
    $tc = NULL;
}
// Continue working with image instance?>

阅读全文 »

GD 和图像处理 函数 imagegrabscreen Captures the whole screen

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

      示例1
<?php 
$im = imagegrabscreen();
imagepng($im, "myscreenshot.png");
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagelayereffect 设定 alpha 混色标志以使用绑定的 libgd 分层效果

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

      示例1
<?php 
// Setup an image$im = imagecreatetruecolor(100, 100);
// Set a backgroundimagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 220, 220, 220));
// Apply the overlay alpha blending flagimagelayereffect($im, IMG_EFFECT_OVERLAY);
// Draw two grey ellipsesimagefilledellipse($im, 50, 50, 40, 40, imagecolorallocate($im, 100, 255, 100));
imagefilledellipse($im, 50, 50, 50, 80, imagecolorallocate($im, 100, 100, 255));
imagefilledellipse($im, 50, 50, 80, 50, imagecolorallocate($im, 255, 100, 100));
// Outputheader('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagegrabwindow Captures a window

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

      示例1
<?php 
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$im = imagegrabwindow($handle);
$browser->Quit();
imagepng($im, "iesnap.png");
imagedestroy($im);
?>

      示例2
<?php 
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.libgd.org");
/* Still working? */
while ($browser->Busy) {
    com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imageinterlace 启用或禁用隔行扫描

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

      示例1
<?php 
// 创建一个图像实例$im = imagecreatefromgif('php.gif');
// 打开隔行扫描imageinterlace($im, true);
// 保存图像imagegif($im, './php_interlaced.gif');
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imageloadfont 载入一新字体

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

      示例1
<?php 
header("Content-type: image/png");
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 49, 19, $white);
$font = imageloadfont("04b.gdf");
imagestring($im, $font, 0, 0, "Hello", $black);
imagepng($im);
?>

阅读全文 »

GD 和图像处理 函数 imageopenpolygon Draws an open polygon

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

      示例1
<?php 
// Create a blank image$image = imagecreatetruecolor(400, 300);
// Allocate a color for the polygon$col_poly = imagecolorallocate($image, 255, 255, 255);
// Draw the polygonimageopenpolygon($image, array(        0,   0,        100, 200,        300, 200    ),    3,    $col_poly);
// Output the picture to the browserheader('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

阅读全文 »

GD 和图像处理 函数 imageline 画一条线段

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

      示例1
<?php 
function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1){
    /* 下面两行只在线段直角相交时好使    imagesetthickness($image, $thick);
    return imageline($image, $x1, $y1, $x2, $y2, $color);
    */
    if ($thick == 1) {
        return imageline($image, $x1, $y1, $x2, $y2, $color);
    }
    $t = $thick / 2 - 0.5;
    if ($x1 == $x2 || $y1 == $y2) {
        return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
    }
    $k = ($y2 - $y1) / ($x2 - $x1);
 //y = kx + q    $a = $t / sqrt(1 + pow($k, 2));
    $points = array(        round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a),        round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a),        round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a),        round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a),    );
    imagefilledpolygon($image, $points, 4, $color);
    return imagepolygon($image, $points, 4, $color);
}
?>

阅读全文 »

GD 和图像处理 函数 imagejpeg 输出图象到浏览器或文件。

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

      示例1
<?php 
// 创键空白图像并添加一些文本$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
// 设置内容类型标头 —— 这个例子里是 image/jpegheader('Content-Type: image/jpeg');
// 输出图像imagejpeg($im);
// 释放内存imagedestroy($im);
?>
      示例2
<?php 
// 创键空白图像并添加一些文本$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
// 保存图像为 'simpletext.jpg'imagejpeg($im, 'simpletext.jpg');
// 释放内存imagedestroy($im);
?>
      示例3
<?php 
// 创键空白图像并添加一些文本$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
// 设置内容类型标头 —— 这个例子里是 image/jpegheader('Content-Type: image/jpeg');
// 使用 NULL 跳过 filename 参数,并设置图像质量为 75%imagejpeg($im, NULL, 75);
// 释放内存imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagepalettecopy 将调色板从一幅图像拷贝到另一幅

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

imagepalettecopy

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

imagepalettecopy将调色板从一幅图像拷贝到另一幅

说明

imagepalettecopy(resource $destination, resource $source): void

imagepalettecopy()source 图像把调色板拷贝到 destination 图像。

阅读全文 »

GD 和图像处理 函数 imagecreatefromxpm 由文件或 URL 创建一个新图象。

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

      示例1
<?php 
// Check for XPM supportif(!(imagetypes() & IMG_XPM)){
    die('Support for xpm was not found!');
}
// Create the image instance$xpm = imagecreatefromxpm('./example.xpm');
// Do image operations here// PHP has no support for writing xpm images// so in this case we save the image as a // jpeg file with 100% qualityimagejpeg($xpm, './example.jpg', 100);
imagedestroy($xpm);
?>

阅读全文 »

GD 和图像处理 函数 imagecreatetruecolor 新建一个真彩色图像

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

      示例1
<?php 
header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)      or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagedestroy 销毁一图像

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

imagedestroy

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

imagedestroy销毁一图像

说明

imagedestroy(resource $image): bool

imagedestroy() 释放与 image 关联的内存。image 是由图像创建函数返回的图像标识符,例如 imagecreatetruecolor()

阅读全文 »

GD 和图像处理 函数 imagefill 区域填充

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

      示例1
<?php 
$im = imagecreatetruecolor(100, 100);
// 将背景设为红色$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagefilledarc 画一椭圆弧且填充

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

      示例1
<?php 
// 创建图像$image = imagecreatetruecolor(100, 100);
// 分配一些颜色$white    = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray     = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy     = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red      = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred  = imagecolorallocate($image, 0x90, 0x00, 0x00);
// 创建 3D 效果for ($i = 60;
 $i > 50;
 $i--) {
   imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darknavy, IMG_ARC_PIE);
   imagefilledarc($image, 50, $i, 100, 50, 45, 75 , $darkgray, IMG_ARC_PIE);
   imagefilledarc($image, 50, $i, 100, 50, 75, 360 , $darkred, IMG_ARC_PIE);
}
imagefilledarc($image, 50, 50, 100, 50, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 45, 75 , $gray, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 75, 360 , $red, IMG_ARC_PIE);
// 输出图像header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

阅读全文 »

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