Skip to content

Comments

Use extension if provided in resizer options#74

Closed
mjauvin wants to merge 3 commits intowintercms:wip/1.2from
mjauvin:resizer-use-extension
Closed

Use extension if provided in resizer options#74
mjauvin wants to merge 3 commits intowintercms:wip/1.2from
mjauvin:resizer-use-extension

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented Mar 4, 2022

This is required to allow converting images to other formats (e.g. webp). Otherwise the resulting file will have the correct extension but the wrong image format.

Replaces #9 since the original repo got deleted.

The following code can be used as a workaround in the meantime:

Event::listen('system.resizer.processResize', function ($resizer, $tempPath) {
    // Get the resizing configuration
    $config = $resizer->getConfig();
    $options = array_get($config, 'options', []);

    list($base, $ext) = explode('.', $tempPath);
    $newPath = $base . '.' . array_get($options, 'extension', $ext);

    // Resize the image
    $resizedImageContents = \Winter\Storm\Database\Attach\Resizer::open($tempPath)
        ->resize($config['width'], $config['height'], $options)
        ->save($newPath);

    if ($newPath != $tempPath) {
        File::move($newPath, $tempPath);
    }

    // Prevent any other resizing replacer logic from running
    return true;
});

@mjauvin
Copy link
Member Author

mjauvin commented Mar 24, 2022

@LukeTowers any reason against merging this? Converting a jpg to a webp won't work without this fix.

@mjauvin mjauvin removed this from the v1.2.0 milestone May 12, 2022
@github-actions
Copy link

This pull request will be closed and archived in 3 days, as there has been no activity in the last 60 days.
If this is still being worked on, please respond and we will re-open this pull request.
If this pull request is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

@LukeTowers LukeTowers added this to the 1.2.1 milestone Jul 15, 2022
@LukeTowers LukeTowers deleted the branch wintercms:wip/1.2 July 15, 2022 06:59
@LukeTowers LukeTowers closed this Jul 15, 2022
@mjauvin
Copy link
Member Author

mjauvin commented Jul 15, 2022

@LukeTowers why did you close this?

@bennothommo
Copy link
Member

@mjauvin I think these were automatically closed when Luke deleted the wip/1.2 branch. Would you be able to recreate the PRs targeting develop?

@LukeTowers
Copy link
Member

@bennothommo is correct, it was unintentionally auto closed.

@mjauvin mjauvin removed this from the 1.2.1 milestone Jul 27, 2022
LukeTowers pushed a commit that referenced this pull request Jul 27, 2022
This is required to allow converting images to other formats (e.g. webp). Otherwise the resulting file will have the correct extension but the wrong image format.

Fixes #9 & #74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants