建议使用 php 代码来读取 Adobe Bridge CS3 设置的文件评级
-
27-09-2019 - |
题
背景: 我一直在尝试使用 php 的知识共享元数据工具包来读取 Adobe Bridge CS3 中分配的评级,但没有成功。我正在使用共享主机,因此我没有机会使用不同的模块重新编译 php。
是否有可用于读取 .jpg 文件中嵌入的评级的 PHP 代码?我读到这是文件中的 xmp (xml) 格式部分。
解决方案
我在这里发布我的解决方案,以防其他人遇到类似问题并阅读此帖子。这是我发现的:
视窗Vista 将评级添加到文件中嵌入的 exif 部分
土坯桥 向 jpg 文件添加另一个部分,其中包含 xml 格式的数据。xml+数据结构称为xmp文件。我还没有使用 Adobe Bridge 处理该文件,这就是为什么我无法使用元数据工具包读取 xmp 数据。
使用知识共享 - 元数据工具包,我可以使用以下代码读取评级。此代码是 Drupal 模块的一部分,一些引用的变量是 Drupal 设置:Variable_get() 是一个 Drupal 函数,用于从持久数据存储中读取变量。
include_once("PHP_JPEG_Metadata_Toolkit_1.11/JPEG.php"); include_once("PHP_JPEG_Metadata_Toolkit_1.11/Photoshop_File_Info.php"); include_once("PHP_JPEG_Metadata_Toolkit_1.11/EXIF.php"); include_once("PHP_JPEG_Metadata_Toolkit_1.11/XMP.php"); $photodir = variable_get('rotate_images_sourcefiles_dir',"sites/default/files/imageNodes"); $rating_threshold = variable_get('rotate_images_rating_threshold',3); $allImages=dir($photodir); $filenames = scandir($photodir); foreach($filenames as $filename){ $rating = null; $info = pathinfo($filename); if (strtolower($info['extension'])=="jpg"){ // First try to get the rating from the EXIF data, this is where it is stored by Windows Vista $exif = get_EXIF_JPEG( $photodir . "/" . $filename ); $rating = $exif[0][18246]['Data'][0]; $jpeg_header = get_jpeg_header_data($photodir . "/" . $filename ); // If no rating was found in the EXIF data, it may be in the Adobe format xmp section if ($rating == null){ if($jpeg_header != false){ $xmp = get_XMP_text($jpeg_header); $xmpArray = read_XMP_array_from_text($xmp); $rating = $xmpArray[0]['children'][0]['children'][0][attributes]['xap:Rating']; } } } }
我确实需要修改 EXIF_Tags.php 通过向 EXIF 标签数组添加附加条目,将文件添加到元数据工具包中。我向作者报告了这一点,但我认为他不再维护该模块了。源代码在sourceforge上,但我不知道如何发布补丁。因此,您可能需要自己更改 EXIF.php 才能使代码正常工作。
'EXIF' => array ( // Exif IFD 18246 => array ( 'Name' => "Rating", 'Type' => "Numeric" ),
其他提示
理论上如果你使用 fgets
你应该能够读懂它。如果您知道本节从文件中的字节数开始的位置,将会很有帮助。
不隶属于 StackOverflow