easygithdev/imgmeta

用于访问图像的Exif和IPTC数据的包装器

v1.0.0 2020-06-09 08:47 UTC

This package is auto-updated.

Last update: 2024-09-21 21:04:25 UTC


README

用于访问图像的Exif和IPTC数据的包装器。

安装

安装方式非常典型 - 使用composer

composer require easygithdev/imgmeta

如何使用

如果需要,请包含自动加载。

<?php

require 'vendor/autoload.php';

use ImgMeta\ImgData;

定义一个流。流可以是文件、base64字符串或Url

$stream = 'image.jpg';
$stream = 'data:image/jpeg;base64,iVBOR....';
$stream = 'http://domain/image.jpg';

通过这种方式访问所有元数据

$imgData = new ImgData();
$metas = $imgData->read($stream)->getMetas();

获取EXIF或IPTC标签

$imgData->read($stream)->getExif()->fetch(ExifTags::Copyright);
$imgData->read($stream)->getIptc()->fetch(IptcTags::City);

或者您可以使用快速访问

(new ImgData())->read($stream)->exif('Copyright');
(new ImgData())->read($stream)->iptc('City');

仅使用EXIF

获取所有数据

$imgData = new ImgData();
$exifManager = $imgData->createExifManager();
$exifManager->read(ExifReader::getReader($stream));
$exifManager->getMetas();

获取一个标签

$exifManager->fetch(ExifTags::Copyright);

或者

$exifManager->fetch('Copyright');

例如,获取GPS信息

$latitude = $exifManager->fetch('GPSLatitude');
$longitude = $exifManager->fetch('GPSLongitude');

使用助手获取GPS信息

$exifManager->getPosition();

仅使用IPTC

$imgData = new ImgData();
$iptcManager = $imgData->createIptcManager();
$iptcManager->read(IptcReader::getReader($stream));

获取IPTC默认格式

$iptcManager->getMetas();

通过键获取IPTC

$iptcManager->getMetasByKey();

通过名称获取IPTC

$iptcManager->getMetasByName();

通过名称获取IPTC,包含所有键

$iptcManager->getAssocMetas(IptcManager::META_BY_NAME, true);

获取一个标签,数据被展平

$iptcManager->fetch(IptcTags::Country_PrimaryLocationName);

获取一个标签,数据是原始的

$iptcManager->fetchAll(IptcTags::Country_PrimaryLocationName);

许可证

此项目根据GNU许可证授权 - 请参阅LICENSE文件以获取详细信息