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

GD 和图像处理 函数 imagettfbbox 取得使用 TrueType 字体的文本的范围

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

imagettfbbox

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

imagettfbbox取得使用 TrueType 字体的文本的范围

说明

imagettfbbox(
    float $size,
    float $angle,
    string $fontfile,
    string $text
): array

本函数计算并返回一个包围着 TrueType 文本范围的虚拟方框的像素大小。

size
像素单位的字体大小。
angle
text 将被度量的角度大小。
fontfile
TrueType 字体文件的文件名(可以是 URL)。根据 PHP 所使用的 GD 库版本,可能尝试搜索那些不是以 '/' 开头的文件名并加上 '.ttf' 的后缀并搜索库定义的字体路径。
text
要度量的字符串。
imagettfbbox() 返回一个含有 8 个单元的数组表示了文本外框的四个角:
0 左下角 X 位置
1 左下角 Y 位置
2 右下角 X 位置
3 右下角 Y 位置
4 右上角 X 位置
5 右上角 Y 位置
6 左上角 X 位置
7 左上角 Y 位置
这些点是相对于文本的而和角度无关,因此“左上角”指的是以水平方向看文字时其左上角。

本函数同时需要 GD 库和 FreeType 库。

参见 imagettftext()

阅读全文 »

GD 和图像处理 函数 imagesy 取得图像高度

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

      示例1
<?php 
// create a 300*200 image$img = imagecreatetruecolor(300, 200);
echo imagesy($img);
 // 200?>

阅读全文 »

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

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

imagewbmp

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

imagewbmp以 WBMP 格式将图像输出到浏览器或文件

说明

imagewbmp(resource $image, string $filename = ?, int $foreground = ?): bool

imagewbmp()image 图像创建一个名为 filenameWBMP 文件。image 参数是 imagecreatetruecolor() 的返回值。

filename 参数是可选项,如果省略,则直接将原图像流输出。通过用 header() 发送 image/vnd.wap.wbmp 的 Content-type,可以创建直接输出 WBMP 图像的 PHP 脚本。

注意:

WBMP 支持仅能用于 PHP 编译时加入了 GD-1.8 或更高版本时。

用可选的 foreground 参数可以设定前景色,用 imagecolorallocate() 函数返回的颜色标识符。默认前景色是黑色。

参见 image2wbmp()imagepng()imagegif()imagejpeg()imagetypes()

阅读全文 »

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

发表日期:2021-07-01 08:56:02 | 来源: | 分类: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);
// 保存图像imagexbm($im, 'simpletext.xbm');
// 释放内存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);
// 设置替换的前景色$foreground_color = imagecolorallocate($im, 255, 0, 0);
// 保存图像imagexbm($im, NULL, $foreground_color);
// 释放内存imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 iptcparse 将二进制 IPTC 块解析为单个标记

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

      示例1
<?php 
$size = getimagesize('./test.jpg', $info);
if(isset($info['APP13'])){
    $iptc = iptcparse($info['APP13']);
    var_dump($iptc);
}
?>

阅读全文 »

GD 和图像处理 函数 imagettftext 用 TrueType 字体向图像写入文本

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

      示例1
<?php 
// Set the enviroment variable for GDputenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)$font = 'SomeFont';
?>
      示例2
<?php 
// Set the content-typeheader('Content-Type: image/png');
// Create the image$im = imagecreatetruecolor(400, 30);
// Create some colors$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw$text = 'Testing...';
// Replace path by your own font path$font = 'arial.ttf';
// Add some shadow to the textimagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the textimagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()imagepng($im);
imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 imagewebp 将 WebP 格式的图像输出到浏览器或文件

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

      示例1
<?php 
// 创建一个空图像并在其上加入一些文字$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'WebP with PHP', $text_color);
// 保存图像imagewebp($im, 'php.webp');
// 释放内存imagedestroy($im);
?>

阅读全文 »

GD 和图像处理 函数 iptcembed 将二进制 IPTC 数据嵌入到一幅 JPEG 图像中

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

      示例1
<?php 
// iptc_make_tag() function by Thies C. Arntzenfunction iptc_make_tag($rec, $data, $value){
    $length = strlen($value);
    $retval = chr(0x1C) . chr($rec) . chr($data);
    if($length < 0x8000)    {
        $retval .= chr($length >> 8) .  chr($length & 0xFF);
    }
    else    {
        $retval .= chr(0x80) .                    chr(0x04) .                    chr(($length >> 24) & 0xFF) .                    chr(($length >> 16) & 0xFF) .                    chr(($length >> 8) & 0xFF) .                    chr($length & 0xFF);
    }
    return $retval . $value;
}
// Path to jpeg file$path = './phplogo.jpg';
// We need to check if theres any IPTC data in the jpeg image. If there is then // bail out because we cannot embed any image that already has some IPTC data!$image = getimagesize($path, $info);
if(isset($info['APP13'])){
    die('Error: IPTC data found in source image, cannot continue');
}
// Set the IPTC tags$iptc = array(    '2#120' => 'Test image',    '2#116' => 'Copyright 2008-2009, The PHP Group');
// Convert the IPTC tags into binary code$data = '';
foreach($iptc as $tag => $string){
    $tag = substr($tag, 2);
    $data .= iptc_make_tag(2, $tag, $string);
}
// Embed the IPTC data$content = iptcembed($data, $path);
// Write the new image data out to the file.$fp = fopen($path, "wb");
fwrite($fp, $content);
fclose($fp);
?>

阅读全文 »

GD 和图像处理 函数 png2wbmp 将 PNG 图像文件转换为 WBMP 图像文件

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

      示例1
<?php 
// Path to the target png$path = './test.png';
// Get the image sizes$image = getimagesize($path);
// Convert imagepng2wbmp($path, './test.wbmp', $image[1], $image[0], 7);
?>

阅读全文 »

GD 和图像处理 函数 jpeg2wbmp 将 JPEG 图像文件转换为 WBMP 图像文件

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

      示例1
<?php 
// 目标 jpeg 的路径$path = './test.jpg';
// 获取图像尺寸$image = getimagesize($path);
// 转换图像jpeg2wbmp($path, './test.wbmp', $image[1], $image[0], 5);
?>

阅读全文 »

可交换图像信息 exif_read_data 从一个图片文件中读取 EXIF 头信息

发表日期:2021-07-01 08:56:02 | 来源: | 分类:可交换图像信息

      示例1
<?php 
echo "test1.jpg:<br />\n";
$exif = exif_read_data('tests/test1.jpg', 'IFD0');
echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />\n";
$exif = exif_read_data('tests/test2.jpg', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />\n";
    }
}
?>

      示例2
<?php 
// Open a the file, this should be in binary mode$fp = fopen('/path/to/image.jpg', 'rb');
if (!$fp) {
    echo 'Error: Unable to open image for reading';
    exit;
}
// Attempt to read the exif headers$headers = exif_read_data($fp);
if (!$headers) {
    echo 'Error: Unable to read exif headers';
    exit;
}
// Print the 'COMPUTED' headersecho 'EXIF Headers:' . PHP_EOL;
foreach ($headers['COMPUTED'] as $header => $value) {
    printf(' %s => %s%s', $header, $value, PHP_EOL);
}
?>

阅读全文 »

可交换图像信息 exif_imagetype 判断一个图像的类型

发表日期:2021-07-01 08:56:02 | 来源: | 分类:可交换图像信息

      示例1
<?php 
if (exif_imagetype("image.gif") != IMAGETYPE_GIF) {
    echo "The picture is not a gif";
}
?>

阅读全文 »

可交换图像信息 exif_tagname 获取指定索引的头名称

发表日期:2021-07-01 08:56:02 | 来源: | 分类:可交换图像信息

      示例1
<?php 
echo "256: ".exif_tagname(256).PHP_EOL;
echo "257: ".exif_tagname(257).PHP_EOL;
?>

阅读全文 »

GD 和图像处理 函数 imagepalettetotruecolor Converts a palette based image to true color

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

      示例1
<?php 
// Backwards compatiblityif(!function_exists('imagepalettetotruecolor')){
    function imagepalettetotruecolor(&$src)    {
        if(imageistruecolor($src))        {
            return(true);
        }
        $dst = imagecreatetruecolor(imagesx($src), imagesy($src));
        imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src));
        imagedestroy($src);
        $src = $dst;
        return(true);
    }
}
// Helper closure$typeof = function() use($im){
    echo 'typeof($im) = ' . (imageistruecolor($im) ? 'true color' : 'palette'), PHP_EOL;
}
;
// Create a palette based image$im = imagecreate(100, 100);
$typeof();
// Convert it to true colorimagepalettetotruecolor($im);
$typeof();
// Free the memoryimagedestroy($im);
?>

阅读全文 »

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

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

      示例1
<?php 
$im = imagecreatefrompng("test.png");
imagepng($im);
?>

阅读全文 »

GD 和图像处理 函数 imagerectangle 画一个矩形

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

imagerectangle

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

imagerectangle画一个矩形

说明

imagerectangle(
    resource $image,
    int $x1,
    int $y1,
    int $x2,
    int $y2,
    int $col
): bool

imagerectangle()col 颜色在 image 图像中画一个矩形,其左上角坐标为 x1, y1,右下角坐标为 x2, y2。图像的左上角坐标为 0, 0。

阅读全文 »

GD 和图像处理 函数 imageresolution Get or set the resolution of the image

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

      示例1
<?php 
$im = imagecreatetruecolor(100, 100);
imageresolution($im, 200);
print_r(imageresolution($im));
imageresolution($im, 300, 72);
print_r(imageresolution($im));
?>

阅读全文 »

GD 和图像处理 函数 imagerotate 用给定角度旋转图像

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

      示例1
<?php 
// File and rotation$filename = 'test.jpg';
$degrees = 180;
// Content typeheader('Content-type: image/jpeg');
// Load$source = imagecreatefromjpeg($filename);
// Rotate$rotate = imagerotate($source, $degrees, 0);
// Outputimagejpeg($rotate);
?>

阅读全文 »

GD 和图像处理 函数 imagepolygon 画一个多边形

发表日期:2021-07-01 08:56:01 | 来源: | 分类: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 polygon$col_poly = imagecolorallocate($image, 255, 255, 255);
// draw the polygonimagepolygon($image,             array (                    0, 0,                    100, 200,                    300, 200             ),             3,             $col_poly);
// output the pictureheader("Content-type: image/png");
imagepng($image);
?>

阅读全文 »

GD 和图像处理 函数 imagesetbrush 设定画线用的画笔图像

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

imagesetbrush

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

imagesetbrush设定画线用的画笔图像

说明

imagesetbrush(resource $image, resource $brush): bool

当用特殊的颜色 IMG_COLOR_BRUSHEDIMG_COLOR_STYLEDBRUSHED 绘画时,imagesetbrush() 设定了所有画线的函数(例如 imageline()imagepolygon())所使用的画笔图像。【注:使用画笔图像,所画的线是由 brush 所代表的图像构成的。请参考并尝试运行 imagesetstyle() 中的例子以帮助理解。】

注意:

使用完画笔图像后不需要采取什么特殊动作。但如果销毁了画笔图像,在设定一个新的画笔图像之前不能使用 IMG_COLOR_BRUSHEDIMG_COLOR_STYLEDBRUSHED

注意:

本函数是 PHP 4.0.6 添加的。

阅读全文 »

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