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

GD 和图像处理 函数 imageftbbox 给出一个使用 FreeType 2 字体的文本框

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

      示例1
<?php 
// Create a 300x150 image$im = imagecreatetruecolor(300, 150);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Set the background to be whiteimagefilledrectangle($im, 0, 0, 299, 299, $white);
// Path to our font file$font = './arial.ttf';
// First we create our bounding box$bbox = imageftbbox(10, 0, $font, 'The PHP Documentation Group');
// This is our cordinates for X and Y$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
imagefttext($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group');
// Output to browserheader('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagegammacorrect 对 GD 图像应用 gamma 修正

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

imagegammacorrect

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

imagegammacorrect对 GD 图像应用 gamma 修正

说明

imagegammacorrect(resource $image, float $inputgamma, float $outputgamma): bool

imagegammacorrect() 函数用给定的输入 gamma 值 inputgamma 和输出 gamma 值 outputgamma 对一幅 GD 图像流(image)应用 gamma 修正。

阅读全文 »

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

发表日期:2021-07-01 08:55:59 | 来源: | 分类: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,  "A Simple Text String", $text_color);
// Output the imageimagegd2($im);
// Free up memoryimagedestroy($im);
?>

      示例2
<?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,  "A Simple Text String", $text_color);
// Save the gd2 image// The file format for GD2 images is .gd2, see http://www.libgd.org/GdFileFormatsimagegd2($im, 'simple.gd2');
// Free up memoryimagedestroy($im);
?>

阅读全文 »

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

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

      示例1
<?php 
// Load the BMP file$im = imagecreatefrombmp('./example.bmp');
// Convert it to a PNG file with default settingsimagepng($im, './example.png');
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecopyresized 拷贝部分图像并调整大小

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

      示例1
<?php 
// File and new size$filename = 'test.jpg';
$percent = 0.5;
// Content typeheader('Content-Type: image/jpeg');
// Get new sizeslist($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resizeimagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Outputimagejpeg($thumb);
?>

阅读全文 »

GD 和图像处理 函数 imagecreate 新建一个基于调色板的图像

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

      示例1
<?php 
header("Content-type: image/png");
$im = @imagecreate(100, 50)    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecreatefromgd2 从 GD2 文件或 URL 新建一图像

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

      示例1
<?php 
// 加载 gd2 图像$im = imagecreatefromgd2('./test.gd2');
// 在图像上应用效果。// 在这个例子中,如果版本为 PHP5+ 则反转图像颜色if(function_exists('imagefilter')){
    imagefilter($im, IMG_FILTER_NEGATE);
}
// 保存图像imagegd2($im, './test_updated.gd2');
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecreatefromgd2part 从给定的 GD2 文件或 URL 中的部分新建一图像

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

      示例1
<?php 
// For this example we need the image size before$image = getimagesize('./test.gd2');
// Create the image instance now we got the image // sizes$im = imagecreatefromgd2part('./test.gd2', 4, 4, ($image[0] / 2) - 6, ($image[1] / 2) - 6);
// Do an image operation, in this case we emboss the // image if PHP 5+if(function_exists('imagefilter')){
    imagefilter($im, IMG_FILTER_EMBOSS);
}
// Save optimized imageimagegd2($im, './test_emboss.gd2');
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagecreatefromgd 从 GD 文件或 URL 新建一图像

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

      示例1
<?php 
// Load the gd image$im = @imagecreatefromgd('./test.gd');
// Test if the image was loadedif(!is_resource($im)){
     die('Unable to load gd image!');
}
// Do image operations here// Save the imageimagegd($im, './test_updated.gd');
imagedestroy($im);
?>

阅读全文 »

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

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

      示例1
<?php 
function LoadGif($imgname){
    /* Attempt to open */
    $im = @imagecreatefromgif($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/gif');
$img = LoadGif('bogus.image');
imagegif($img);
imagedestroy($img);
?>

阅读全文 »

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

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

      示例1
<?php 
function LoadJpeg($imgname){
    /* 尝试打开 */
    $im = @imagecreatefromjpeg($imgname);
    /* See if it failed */
    if(!$im)    {
        /* Create a black 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/jpeg');
$img = LoadJpeg('bogus.image');
imagejpeg($img);
imagedestroy($img);
?>

阅读全文 »

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

阅读全文 »

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