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

The output conversion file name does not reflect the conversion format #72

Open
silviaho opened this issue Jan 15, 2024 · 1 comment
Open

Comments

@silviaho
Copy link

silviaho commented Jan 15, 2024

Hi, I'm having trouble converting the image format.

I have a conversion that converts images to WebP format. Here is my config file:

    'image_conversions' => [
        '*' => [
            'thumbnail' => [
                'format' => Manipulations::FORMAT_WEBP,
                'width' => 150,
                'height' => 150,
                'fit' => Manipulations::FIT_CROP,
            ],
        ],
    ],

However, when I input an image named sample.png, the resulting conversion file is named sample.thumbnail.png instead of sample.thumbnail.webp in the conversions directory. Despite the file extension being PNG, I have confirmed that the binary content of the converted image is indeed in WebP format.

Then I looked into the source code and found that the extension for the image conversion is always taken from the original media's extension, resulting in the incorrect file extension.
image

Is this the expected behavior? If not, I think the correct way to get conversion file names should be something like the following:

    public function getConversionFileName(Media $media, $conversionName)
    {
        [$fileName, $extension] = FileHelpers::splitNameAndExtension($media->file_name);

        $conversion = (MediaHub::getConversionForMedia($media))[$conversionName];
        $extension = isset($conversion['format']) ? $conversion['format'] : $extension;

        $fileNamer = MediaHub::getFileNamer();
        return $fileNamer->formatConversionFileName($fileName, $extension, $conversionName);
    }

Let me know what you think and looking forward to hearing from you!

Versions:
PHP 8.3
Nova 4.32.9
Nova Media Hub: 1.7.1

@paulbeames
Copy link

Same problem here. Would like to use the conversion to include webp but the file does not get renamed.

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

No branches or pull requests

2 participants