Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing fileExtension propertie in FileUtility.php #475

Closed
kubilaymelnikov opened this issue Aug 6, 2022 · 6 comments
Closed

Missing fileExtension propertie in FileUtility.php #475

kubilaymelnikov opened this issue Aug 6, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@kubilaymelnikov
Copy link

I would like to add this line to the FileUtility so that you can also create webp directly with the processor.

TYPO3 Headless

It is about this method
FileUtility:: processImageFile

TYPO3

From here I have the cutout
ImageViewHelper:: renderStatic

Changed Files

// FriendsOfTYPO3\Headless\Utility\FileUtility::processImageFile
$processingInstructions = [
    'width' => $dimensions['width'] ?? null,
    'height' => $dimensions['height'] ?? null,
    'minWidth' => $dimensions['minWidth'] ?? $properties['minWidth'] ?? 0,
    'minHeight' => $dimensions['minHeight'] ?? $properties['minHeight'] ?? 0,
    'maxWidth' => $dimensions['maxWidth'] ?? $properties['maxWidth'] ?? 0,
    'maxHeight' => $dimensions['maxHeight'] ?? $properties['maxHeight'] ?? 0,
    'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image),
];
// NEW LINES START
if (!empty($dimensions['fileExtension'] ?? '')) {
    $processingInstructions['fileExtension'] = $dimensions['fileExtension'];
}
// NEW LINES END
return $this->imageService->applyProcessingInstructions($image, $processingInstructions);
// FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor::process
$properties = [];

if (isset($processorConfiguration['processingConfiguration.'])) {
    $properties = $processorConfiguration['processingConfiguration.'];
}

$this->contentObjectRenderer = $cObj;
$this->processorConfiguration = $processorConfiguration;

$targetFieldName = (string)$cObj->stdWrapValue(
    'as',
    $this->processorConfiguration,
    $this->defaults['as']
);

$this->fileObjects = $this->fetchData();
$processedData[$targetFieldName] = $this->processFiles($properties);

Example typoscript definition

images = TEXT
images {
  dataProcessing {
    10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor
    10 {
      processingConfiguration {
        fileExtension = webp
      }
      references.fieldName = images
      as = media
    }
  }
}
@jochenrieger
Copy link

Sounds great and a good thing to have in the API response by default.

We also patched the file utility in our current project to also add the file meta data fields to add some of the fields that come with the activation of the TYPO3 core extension typo3/cms-filemetadata, specifically the fields that contain information related to copyright, creator, publisher, source which might be a common use case for those using images from stocks / photographers that need to be named in the caption.

It's just a quick patch adding these fields to the response. It might make sense to add some kind of condition / dependency checking for an active typo3/cms-filemetadata.

@lukaszuznanski
Copy link
Collaborator

Hi,

it's actually not a way to generate .webp image. You don't process image to .webp by changing file extension. Please take a look at https://github.com/plan2net/webp extension, it works perfectly fine with headless, but it has to be done on server side, not in headless at all.
Next time, please create pull request with your changes.

When it comes to cms-filemetadata @jochenrieger, please create another issue. Closing this one as it's not relevant at all. Please reopen if you have any further questions.

@kubilaymelnikov
Copy link
Author

kubilaymelnikov commented Aug 10, 2022

That's not quite true, if you add webp as file format in the configuration you can create webp images normally with the image processing within TYPO3.
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] = 'gif,jpg,jpeg,tif,tiff,bmp,pcx,tga,png,pdf,ai,svg,webp';

However, this issue is not primarily about webp but about taking away the possibility to define a file extension.

@lukaszuznanski
Copy link
Collaborator

@kubilaymelnikov ok, I was not aware that TYPO3 was able to process webp right now. I will dig into this then.

Please provide pull request with your changes.

@kubilaymelnikov
Copy link
Author

@lukaszuznanski yes, as soon as i have time to install it cleanly!

kubilaymelnikov pushed a commit to kubilaymelnikov/headless that referenced this issue Sep 8, 2022
kubilaymelnikov pushed a commit to kubilaymelnikov/headless that referenced this issue Sep 8, 2022
- The same name used in ImageViewHelper
kubilaymelnikov pushed a commit to kubilaymelnikov/headless that referenced this issue Oct 21, 2022
kubilaymelnikov pushed a commit to kubilaymelnikov/headless that referenced this issue Oct 21, 2022
@kubilaymelnikov
Copy link
Author

@lukaszuznanski & @twoldanski
I test this today and then start the pull request.

kubilaymelnikov pushed a commit to kubilaymelnikov/headless that referenced this issue Oct 21, 2022
kubilaymelnikov pushed a commit to kubilaymelnikov/headless that referenced this issue Oct 21, 2022
lukaszuznanski pushed a commit that referenced this issue Oct 27, 2022
Add missing file extension in file processing configuration
@lukaszuznanski lukaszuznanski added the enhancement New feature or request label Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants