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

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

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

      示例1
<?php 
function LoadPNG($imgname){
    /* Attempt to open */
    $im = @imagecreatefrompng($imgname);
    /* See if it failed */
    if(!$im)    {
        /* Create a blank image */
        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
    return $im;
}
header('Content-Type: image/png');
$img = LoadPNG('bogus.image');
imagepng($img);
imagedestroy($img);
?>

阅读全文 »

GD 和图像处理 函数 imagecreatefromstring 从字符串中的图像流新建一图像

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

      示例1
<?php 
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'       . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'       . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'       . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);
$im = imagecreatefromstring($data);
if ($im !== false) {
    header('Content-Type: image/png');
    imagepng($im);
    imagedestroy($im);
}
else {
    echo 'An error occurred.';
}
?>

阅读全文 »

GD 和图像处理 函数 imagecopyresampled 重采样拷贝部分图像并调整大小

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

      示例1
<?php 
// 这个文件$filename = 'test.jpg';
$percent = 0.5;
// 内容类型header('Content-Type: image/jpeg');
// 获取新的尺寸list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
// 重新取样$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// 输出imagejpeg($image_p, null, 100);
?>
      示例2
<?php 
// 源文件$filename = 'test.jpg';
// 设置最大宽高$width = 200;
$height = 200;
// Content typeheader('Content-Type: image/jpeg');
// 获取新尺寸list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
}
 else {
   $height = $width/$ratio_orig;
}
// 重新取样$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// 输出imagejpeg($image_p, null, 100);
?>

阅读全文 »

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

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

      示例1
<?php 
// 加载 WebP 文件$im = imagecreatefromwebp('./example.webp');
// 以 100% 的质量转换成 jpeg 格式imagejpeg($im, './example.jpeg', 100);
imagedestroy($im);
?>

阅读全文 »

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

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

      示例1
<?php 
// Load the xbm file$xbm = imagecreatefromxbm('./example.xbm');
// Convert it to a png fileimagepng($xbm, './example.png');
imagedestroy($xbm);
?>

阅读全文 »

GD 和图像处理 函数 imagecrop Crop an image to the given rectangle

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

      示例1
<?php 
$im = imagecreatefrompng('example.png');
$size = min(imagesx($im), imagesy($im));
$im2 = imagecrop($im, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]);
if ($im2 !== FALSE) {
    imagepng($im2, 'example-cropped.png');
    imagedestroy($im2);
}
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecropauto Crop an image automatically using one of the available modes

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

      示例1
<?php 
$cropped = imagecropauto($im, IMG_CROP_DEFAULT);
if ($cropped !== false) {
 // in case a new image object was returned    imagedestroy($im);
    // we destroy the original image    $im = $cropped;
       // and assign the cropped image to $im}
?>

阅读全文 »

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

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

      示例1
<?php 
function LoadWBMP($imgname){
    /* Attempt to open */
    $im = @imagecreatefromwbmp($imgname);
    /* See if it failed */
    if(!$im)    {
        /* Create a blank image */
        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
    return $im;
}
header('Content-Type: image/vnd.wap.wbmp');
$img = LoadWBMP('bogus.image');
imagewbmp($img);
imagedestroy($img);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorclosestalpha 取得与指定的颜色加透明度最接近的颜色

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

      示例1
<?php 
// Start with an image and convert it to a palette-based image$im = imagecreatefrompng('figures/imagecolorclosest.png');
imagetruecolortopalette($im, false, 255);
// 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));
// 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){
    $result = imagecolorclosestalpha($im, $rgb[0], $rgb[1], $rgb[2], $rgb[3]);
    $result = imagecolorsforindex($im, $result);
    $result = "({
$result['red']}
, {
$result['green']}
, {
$result['blue']}
, {
$result['alpha']}
)";
    echo "#$id: Search ($rgb[0], $rgb[1], $rgb[2], $rgb[3]);
 Closest match: $result.\n";
}
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorclosesthwb 取得与给定颜色最接近的色度的黑白色的索引

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

      示例1
<?php 
$im = imagecreatefromgif('php.gif');
echo 'HWB: ' . imagecolorclosesthwb($im, 116, 115, 152);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorat 取得某像素的颜色索引值

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

      示例1
<?php 
$im = ImageCreateFromPng("rockym.png");
$rgb = ImageColorAt($im, 100, 100);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
?>

阅读全文 »

GD 和图像处理 函数 imagecolormatch 使一个图像中调色板版本的颜色与真彩色版本更能匹配

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

      示例1
<?php 
// Setup the true color and palette images$im1 = imagecreatefrompng('./gdlogo.png');
$im2 = imagecreate(imagesx($im1), imagesy($im1));
// Add some colors to $im2$colors   = Array();
$colors[] = imagecolorallocate($im2, 255, 36, 74);
$colors[] = imagecolorallocate($im2, 40, 0, 240);
$colors[] = imagecolorallocate($im2, 82, 100, 255);
$colors[] = imagecolorallocate($im2, 84, 63, 44);
// Match these colors with the true color imageimagecolormatch($im1, $im2);
// Free from memoryimagedestroy($im1);
imagedestroy($im2);
?>

阅读全文 »

GD 和图像处理 函数 imagecolordeallocate 取消图像颜色的分配

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

      示例1
<?php 
$white = imagecolorallocate($im, 255, 255, 255);
imagecolordeallocate($im, $white);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorexactalpha 取得指定的颜色加透明度的索引值

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

      示例1
<?php 
// Setup an image$im = imagecreatefrompng('./gdlogo.png');
$colors   = Array();
$colors[] = imagecolorexactalpha($im, 255, 0, 0, 0);
$colors[] = imagecolorexactalpha($im, 0, 0, 0, 127);
$colors[] = imagecolorexactalpha($im, 255, 255, 255, 55);
$colors[] = imagecolorexactalpha($im, 100, 255, 52, 20);
print_r($colors);
// Free from memoryimagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecolorset 给指定调色板索引设定颜色

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

imagecolorset

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

imagecolorset给指定调色板索引设定颜色

说明

imagecolorset(
    resource $image,
    int $index,
    int $red,
    int $green,
    int $blue
): void

本函数将调色板中指定的索引设定为指定的颜色。对于在调色板图像中创建类似区域填充(flood-fill)的效果很有用,免去了真的去填充的开销。

参见 imagecolorat()

阅读全文 »

GD 和图像处理 函数 imagecolorsforindex 取得某索引的颜色

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

      示例1
<?php 
// 打开一幅图像$im = imagecreatefrompng('nexen.png');
// 取得一点的颜色$start_x = 40;
$start_y = 50;
$color_index = imagecolorat($im, $start_x, $start_y);
// 使其可读$color_tran = imagecolorsforindex($im, $color_index);
// 显示该颜色的值echo '<pre>';
print_r($color_tran);
echo '</pre>';
?>

阅读全文 »

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

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

imagecolorresolve

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

imagecolorresolve取得指定颜色的索引值或有可能得到的最接近的替代值

说明

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

本函数可以保证对所请求的颜色返回一个颜色索引,要么是确切值要么是所能得到最接近的替代值。

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

参见 imagecolorclosest()

阅读全文 »

GD 和图像处理 函数 imagecolorstotal 取得一幅图像的调色板中颜色的数目

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

imagecolorstotal

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

imagecolorstotal取得一幅图像的调色板中颜色的数目

说明

imagecolorstotal(resource $image): int

本函数返回指定图像的调色板中的颜色数目。

参见 imagecolorat()imagecolorsforindex()

阅读全文 »

GD 和图像处理 函数 imagecolortransparent 将某个颜色定义为透明色

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

imagecolortransparent

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

imagecolortransparent将某个颜色定义为透明色

说明

imagecolortransparent(resource $image, int $color = ?): int

imagecolortransparent()image 图像中的透明色设定为 colorimageimagecreatetruecolor() 返回的图像标识符,colorimagecolorallocate() 返回的颜色标识符。

注意:

透明色是图像的一种属性,透明度不是颜色的属性。一旦设定了某个颜色为透明色,图像中之前画为该色的任何区域都成为透明的。

返回新透明色的标识符,如果省略 color 则返回当前透明色的标识符。

注意:

透明度仅能通过 imagecopymerge() 和真彩色图像拷贝,不能用 imagecopy() 或调色板图像。

阅读全文 »

GD 和图像处理 函数 imagecopy 拷贝图像的一部分

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

imagecopy

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

imagecopy拷贝图像的一部分

说明

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

src_im 图像中坐标从 src_xsrc_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_xdst_y 的位置上。

阅读全文 »

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