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

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);
?>

阅读全文 »

GD 和图像处理 函数 imagefilledpolygon 画一多边形并填充

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

      示例1
<?php 
// 建立多边形各顶点坐标的数组$values = array(            40,  50,  // Point 1 (x, y)            20,  240, // Point 2 (x, y)            60,  60,  // Point 3 (x, y)            240, 20,  // Point 4 (x, y)            50,  40,  // Point 5 (x, y)            10,  10   // Point 6 (x, y)            );
// 创建图像$image = imagecreatetruecolor(250, 250);
// 设定颜色$bg   = imagecolorallocate($image, 200, 200, 200);
$blue = imagecolorallocate($image, 0, 0, 255);
// 画一个多边形imagefilledpolygon($image, $values, 6, $blue);
// 输出图像header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

阅读全文 »

GD 和图像处理 函数 imagefilledellipse 画一椭圆并填充

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

      示例1
<?php 
// create a blank image$image = imagecreatetruecolor(400, 300);
// fill the background color$bg = imagecolorallocate($image, 0, 0, 0);
// choose a color for the ellipse$col_ellipse = imagecolorallocate($image, 255, 255, 255);
// draw the white ellipseimagefilledellipse($image, 200, 150, 300, 200, $col_ellipse);
// output the pictureheader("Content-type: image/png");
imagepng($image);
?>

阅读全文 »

GD 和图像处理 函数 imageellipse 画一个椭圆

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

      示例1
<?php 
// 新建一个空白图像$image = imagecreatetruecolor(400, 300);
// 填充背景色$bg = imagecolorallocate($image, 0, 0, 0);
// 选择椭圆的颜色$col_ellipse = imagecolorallocate($image, 255, 255, 255);
// 画一个椭圆imageellipse($image, 200, 150, 300, 200, $col_ellipse);
// 输出图像header("Content-type: image/png");
imagepng($image);
?>

阅读全文 »

GD 和图像处理 函数 imagefilledrectangle 画一矩形并填充

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

imagefilledrectangle

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

imagefilledrectangle画一矩形并填充

说明

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

imagefilledrectangle()image 图像中画一个用 color 颜色填充了的矩形,其左上角坐标为 x1y1,右下角坐标为 x2y2。0, 0 是图像的最左上角。

阅读全文 »

GD 和图像处理 函数 imageflip Flips an image using a given mode

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

      示例1
<?php 
// File$filename = 'phplogo.png';
// Content typeheader('Content-type: image/png');
// Load$im = imagecreatefrompng($filename);
// Flip it verticallyimageflip($im, IMG_FLIP_VERTICAL);
// Outputimagejpeg($im);
imagedestroy($im);
?>
      示例2
<?php 
// File$filename = 'phplogo.png';
// Content typeheader('Content-type: image/png');
// Load$im = imagecreatefrompng($filename);
// Flip it horizontallyimageflip($im, IMG_FLIP_HORIZONTAL);
// Outputimagejpeg($im);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagefontheight 取得字体高度

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

imagefontheight

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

imagefontheight取得字体高度

说明

imagefontheight(int $font): int

返回指定字体一个字符高度的像素值。

参见 imagefontwidth()imageloadfont()

阅读全文 »

GD 和图像处理 函数 imagefilltoborder 区域填充到指定颜色的边界为止

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

imagefilltoborder

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

imagefilltoborder区域填充到指定颜色的边界为止

说明

imagefilltoborder(
    resource $image,
    int $x,
    int $y,
    int $border,
    int $color
): bool

imagefilltoborder()xy(图像左上角为 0, 0)点开始用 color 颜色执行区域填充,直到碰到颜色为 border 的边界为止。【注:边界内的所有颜色都会被填充。如果指定的边界色和该点颜色相同,则没有填充。如果图像中没有该边界色,则整幅图像都会被填充。】

阅读全文 »

GD 和图像处理 函数 imagefilter 对图像使用过滤器

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

      示例1
<?php 
$im = imagecreatefrompng('dave.png');
if ($im && imagefilter($im, IMG_FILTER_GRAYSCALE)) {
    echo 'Image converted to grayscale.';
    imagepng($im, 'dave.png');
}
 else {
    echo 'Conversion to grayscale failed.';
}
imagedestroy($im);
?>
      示例2
<?php 
$im = imagecreatefrompng('sean.png');
if ($im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20)) {
    echo 'Image brightness changed.';
    imagepng($im, 'sean.png');
}
 else {
    echo 'Image brightness change failed.';
}
imagedestroy($im);
?>
      示例3
<?php 
$im = imagecreatefrompng('philip.png');
/* R, G, B, so 0, 255, 0 is green */
if ($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0)) {
    echo 'Image successfully shaded green.';
    imagepng($im, 'philip.png');
}
 else {
    echo 'Green shading failed.';
}
imagedestroy($im);
?>
      示例4
<?php 
$im = imagecreatefrompng('dave.png');
if($im && imagefilter($im, IMG_FILTER_GRAYSCALE)){
    echo 'Image converted to grayscale.';
    imagepng($im, 'dave.png');
}
else{
    echo 'Conversion to grayscale failed.';
}
imagedestroy($im);
?>
      示例5
<?php 
$im = imagecreatefrompng('sean.png');
if($im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20)){
    echo 'Image brightness changed.';
    imagepng($im, 'sean.png');
    imagedestroy($im);
}
else{
    echo 'Image brightness change failed.';
}
?>
      示例6
<?php 
$im = imagecreatefrompng('philip.png');
/* R, G, B, so 0, 255, 0 is green */
if($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0)){
    echo 'Image successfully shaded green.';
    imagepng($im, 'philip.png');
    imagedestroy($im);
}
else{
    echo 'Green shading failed.';
}
?>
      示例7
<?php 
// Define our negate function so its portable for // php versions without imagefilter()function negate($im){
    if(function_exists('imagefilter'))    {
        return imagefilter($im, IMG_FILTER_NEGATE);
    }
    for($x = 0;
 $x < imagesx($im);
 ++$x)    {
        for($y = 0;
 $y < imagesy($im);
 ++$y)        {
            $index = imagecolorat($im, $x, $y);
            $rgb = imagecolorsforindex($index);
            $color = imagecolorallocate($im, 255 - $rgb['red'], 255 - $rgb['green'], 255 - $rgb['blue']);
            imagesetpixel($im, $x, $y, $color);
        }
    }
    return(true);
}
$im = imagecreatefromjpeg('kalle.jpg');
if($im && negate($im)){
    echo 'Image successfully converted to negative colors.';
    imagejpeg($im, 'kalle.jpg', 100);
    imagedestroy($im);
}
else{
    echo 'Converting to negative colors failed.';
}
?>
      示例8
<?php 
// Load the PHP logo, we need to create two instances // to show the differences$logo1 = imagecreatefrompng('./php.png');
$logo2 = imagecreatefrompng('./php.png');
// Create the image instance we want to show the // differences on$output = imagecreatetruecolor(imagesx($logo1) * 2, imagesy($logo1));
// Apply pixelation to each instance, with a block // size of 3imagefilter($logo1, IMG_FILTER_PIXELATE, 3);
imagefilter($logo2, IMG_FILTER_PIXELATE, 3, true);
// Merge the differences onto the output imageimagecopy($output, $logo1, 0, 0, 0, 0, imagesx($logo1) - 1, imagesy($logo1) - 1);
imagecopy($output, $logo2, imagesx($logo2), 0, 0, 0, imagesx($logo2) - 1, imagesy($logo2) - 1);
imagedestroy($logo1);
imagedestroy($logo2);
// Output the differencesheader('Content-Type: image/png');
imagepng($output);
imagedestroy($output);
?>

阅读全文 »

GD 和图像处理 函数 imagefontwidth 取得字体宽度

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

imagefontwidth

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

imagefontwidth取得字体宽度

说明

imagefontwidth(int $font): int

返回指定字体一个字符宽度的像素值。

参见 imagefontheight()imageloadfont()

阅读全文 »

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