如何确定具有php的vector文件版本?

问题描述 投票:0回答:1
文件的版本(或使用其他语言进行示例)。我知道这是文本格式,但是我找不到文件中的版本值。 Adobe Illustartion有许多版本支持。

,但我需要至少检测到最广泛使用的8和10个标志的版本。

enter image description here要使用PHP确定EPS(封装的Postscript)文件的版本,您可以读取文件的标题并从%%Creator:

注释行中提取版本信息。该行通常指定用于创建EPS文件的软件和版本。

在这里是实现这一目标的PHP功能:
php file vector eps
1个回答
0
投票

<?php function getEpsVersion($filePath) { // Open the EPS file for reading $file = fopen($filePath, 'r'); if (!$file) { throw new Exception("Unable to open file: $filePath"); } // Initialize version as 'Unknown' $version = 'Unknown'; // Read the file line by line while (($line = fgets($file)) !== false) { // Check for the '%%Creator:' line if (strpos($line, '%%Creator:') === 0) { // Extract the version number using a regular expression if (preg_match('/Adobe Illustrator\(R\) ([\d.]+)/', $line, $matches)) { $version = $matches[1]; } break; } } // Close the file fclose($file); return $version; } // Example usage $filePath = 'path/to/your/file.eps'; try { $version = getEpsVersion($filePath); echo "EPS file version: $version"; } catch (Exception $e) { echo 'Error: ' . $e->getMessage(); } ?>

示例输出:

如果EPS文件包含该行%%Creator: Adobe Illustrator(R) 8.0,则输出将为:

EPS file version: 8.0

这种方法依赖于EPS文件中的

%%Creator:

注释行的存在。如果该行丢失或遵循不同的格式,则该功能可能无法确定版本。此外,Adobe Illustrator以外的其他软件创建的EPS文件可能具有不同的行,因此您可能需要调整正则表达式以匹配其他格式。

	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.