exif_thumbnail

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

exif_thumbnail检索图像的嵌入式缩略图

说明

exif_thumbnail(
    resource|string $file,
    int &$width = null,
    int &$height = null,
    int &$image_type = null
): string|false

exif_thumbnail() 读取图像的嵌入式缩略图。

如果想通过该函数发送缩略图,应该使用 header() 函数发送 mimetype 信息。

exif_thumbnail() 不能创建图像但能确定它的尺寸。在这种情况下,返回值是 false,但会设置 widthheight

参数

file

图像文件的路径。可以是文件路径也可以是流 resource

width

返回缩略图的宽度。

height

返回缩略图的高度。

image_type

返回缩略图的图像类型。不是 TIFF 就是 JPEG

返回值

返回嵌入式缩略图,如果图像不包含缩略图则返回 false

更新日志

版本 说明
7.2.0 file 参数现在支持本地文件和流资源。

范例

示例 #1 exif_thumbnail() 示例

<?php
$image
= exif_thumbnail('/path/to/image.jpg', $width, $height, $type);

if (
$image!==false) {
header('Content-type: ' .image_type_to_mime_type($type));
echo
$image;
exit;
} else {
// 没有可用的缩略图,这里处理错误
echo 'No thumbnail available';
}
?>

注释

注意:

如果传递流到此函数的 file,然后流必须是可寻找的。请注意,此函数返回后,文件指针位置不会改变。

参见

  • exif_read_data() - 从一个图片文件中读取 EXIF 头信息
  • image_type_to_mime_type() - 取得 getimagesize、exif_read_data、exif_thumbnail、exif_imagetype 所返回的图像类型的 MIME 类型

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top