Skip to content

Comments

Use extension if provided in resizer options#99

Merged
LukeTowers merged 5 commits intodevelopfrom
resizer-use-extension
Jul 27, 2022
Merged

Use extension if provided in resizer options#99
LukeTowers merged 5 commits intodevelopfrom
resizer-use-extension

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented Jul 22, 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.
Replaces #74

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 mjauvin added this to the 1.2.1 milestone Jul 22, 2022
@mjauvin mjauvin requested a review from LukeTowers July 22, 2022 12:33
@mjauvin mjauvin self-assigned this Jul 22, 2022
@LukeTowers LukeTowers merged commit 71d6e70 into develop Jul 27, 2022
@LukeTowers LukeTowers deleted the resizer-use-extension branch July 27, 2022 16:58
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.

2 participants