fix port to 4.1 extract xmp:PageImage indesign

This commit is contained in:
aynsix
2019-07-17 17:16:29 +04:00
parent 5e2f8da2bb
commit fdb67c74d9
2 changed files with 25 additions and 13 deletions

View File

@@ -61,7 +61,7 @@ class SubdefGenerator
public function generateSubdefs(\record_adapter $record, array $wanted_subdefs = null)
{
if ($record->get_hd_file() !== null) {
if ($record->get_hd_file() !== null && $record->get_hd_file()->getMimeType() == "application/x-indesign") {
$mediaSource = $this->mediavorus->guess($record->get_hd_file()->getPathname());
$metadatas = $mediaSource->getMetadatas();
@@ -69,15 +69,27 @@ class SubdefGenerator
if(!isset($this->tmpFilesystem)){
$this->tmpFilesystem = Manager::create();
}
$tmpDir = $this->tmpFilesystem->createTemporaryDirectory();
$tmpDir = $this->tmpFilesystem->createTemporaryDirectory(0777, 500);
try {
$this->app['filesystem']->dumpFile($tmpDir.'/file.jpg', $metadatas->get('XMP-xmp:PageImage')->getValue()->asString());
$this->tmpFilePath = $tmpDir.'/file.jpg';
} catch (\Exception $e) {
$this->logger->error(sprintf('Unable to write temporary file : %s', $e->getMessage()));
$files = $this->app['exiftool.preview-extractor']->extract($record->get_hd_file()->getPathname(), $tmpDir);
$selected = null;
$size = null;
foreach ($files as $file) {
if ($file->isDir() || $file->isDot()) {
continue;
}
if (is_null($selected) || $file->getSize() > $size) {
$selected = $file->getPathname();
$size = $file->getSize();
}
}
if ($selected) {
$this->tmpFilePath = $selected;
}
}
}