Skip to content

Commit

Permalink
[FEATURE] Add MIME type and file extension Helper methods; simplify i…
Browse files Browse the repository at this point in the history
…mage mimetypeLabel logic
  • Loading branch information
fschoelzel committed Jan 2, 2025
1 parent 4b3a130 commit e0565dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
24 changes: 24 additions & 0 deletions Classes/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,4 +988,28 @@ function ($mimeType) use ($categories) {
}
return false;
}

/**
* Get file extensions for a given MIME type
*
* @param string $mimeType
* @return array
*/
public static function getFileExtensionsForMimeType(string $mimeType): array
{
$mimeTypeDetector = GeneralUtility::makeInstance(MimeTypeDetector::class);

Check failure on line 1000 in Classes/Common/Helper.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Class Kitodo\Dlf\Common\MimeTypeDetector not found.
return $mimeTypeDetector->getFileExtensionsForMimeType($mimeType);
}

/**
* Get MIME types for a given file extension
*
* @param string $fileExtension
* @return array
*/
public static function getMimeTypesForFileExtension(string $fileExtension): array
{
$mimeTypeDetector = GeneralUtility::makeInstance(MimeTypeDetector::class);

Check failure on line 1012 in Classes/Common/Helper.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Class Kitodo\Dlf\Common\MimeTypeDetector not found.
return $mimeTypeDetector->getMimeTypesForFileExtension($fileExtension);
}
}
14 changes: 4 additions & 10 deletions Classes/Controller/ToolboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,13 @@ private function renderToolByName(string $tool): void
*
* @return array Array of image information's.
*/
public function getImage(int $page): array
private function getImage(int $page): array
{
// Get @USE value of METS fileGroup.
$image = $this->getFile($page, GeneralUtility::trimExplode(',', $this->settings['fileGrpsImageDownload']));
switch ($image['mimetype']) {
case 'image/jpeg':
$image['mimetypeLabel'] = ' (JPG)';
break;
case 'image/tiff':
$image['mimetypeLabel'] = ' (TIFF)';
break;
default:
$image['mimetypeLabel'] = '';
if (isset($image['mimetype'])) {
$fileExtension = Helper::getFileExtensionsForMimeType($image['mimetype']);
$image['mimetypeLabel'] = !empty($fileExtension) ? ' (' . strtoupper($fileExtension[0]) . ')' : '';
}
return $image;
}
Expand Down

0 comments on commit e0565dc

Please sign in to comment.