,但我需要至少检测到最广泛使用的8和10个标志的版本。 注释行中提取版本信息。该行通常指定用于创建EPS文件的软件和版本。 在这里是实现这一目标的PHP功能:
<?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文件可能具有不同的行,因此您可能需要调整正则表达式以匹配其他格式。