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

Thumbnail creation doesn't work as expected when using webp #4145

Closed
andreasotto opened this issue Feb 10, 2022 · 12 comments
Closed

Thumbnail creation doesn't work as expected when using webp #4145

andreasotto opened this issue Feb 10, 2022 · 12 comments
Labels
needs: discussion 🗣 Requires further discussion to proceed type: stale 💤 Will be closed soon because there was no recent activity

Comments

@andreasotto
Copy link

andreasotto commented Feb 10, 2022

Description

Thumbnail creation doesn't work as expected when using 'format' => 'webp'.
As soon as one switches the format to webp, the creation of thumbs doesn't work any more. Although images are converted to webp, as expected, the image has not the right size. Instead of that, the original, full size is given out.

Expected behavior
Even if webp format is used, the thumb settings should be taken into account and the thumbs should be generated in the required size.

To reproduce

Setup config.phpwith these settings:

    'thumbs' => [
        'format' => 'webp',
        'presets' => [
            '1950w' => ['width' => 1950, 'quality' => 30],
        ]
    ],

Then use in a template like this:

<img src="<?= $image->thumb('1950w')->url() ?>">

Result:

  • Image is converted to webp (as expected)
  • But the preset setting was not taken into account. The image is output in full size (not expected).
  • (As soon as you remove format webp, the thumb will be output in the correct size again.)

Kirby Version
3.6.1.1

@distantnative
Copy link
Member

Which thumb driver are you using? https://getkirby.com/docs/reference/system/options/thumbs#thumbs-driver
Default gd?

@andreasotto
Copy link
Author

andreasotto commented Feb 10, 2022

Yes, default (changed no setting for that).

Update: Just switched to im for a test, but makes no difference.

@afbora afbora added the needs: replication 🔬 Requires a sample to reproduce the issue label Feb 16, 2022
@afbora
Copy link
Member

afbora commented Feb 16, 2022

I've tested your settings on Starterkit 3.6.2 and works great for me.

Don't forget:

Smaller image width

If the image width (for ex: 800x600px) is less than the desired (1950px) width, the full size (800px) is displayed.

Crop option

If you do not want the above situation, you can use the crop option. So the size you want is always shown.

'thumbs' => [
    'format' => 'webp',
    'presets' => [
        '1950w' => ['width' => 1950, 'quality' => 30, 'crop' => true],
    ]
],

@afbora
Copy link
Member

afbora commented Feb 18, 2022

@andreasotto Have you tried my last post?

@bastianallgeier
Copy link
Member

Maybe your GD and IM installations don't support webp yet. It has been introduced in more recent versions.

@andreasotto
Copy link
Author

andreasotto commented Mar 25, 2022

Debian 11.2
PHP 8.1.4
Kirby 3.6.2

Everything is up-to-date

Converting to webp seems to work, but the file is not resized.

config.php (as suggested by @afbora ):

    'thumbs' => [
        'format' => 'webp',
        'presets' => [
            'background' => ['width' => 1950, 'quality' => 30, 'crop' => true],
        ]
    ]

Template:

            <?php if($image = $block->image()->toFile()) : ?>
                <img class="w-full h-full object-cover" src="<?= $image->thumb('background')->url() ?>" alt="">
            <?php endif ?>

Result:

image

As you can see, the image is 4.4 mb and has not been resized.

What can i do to deliver better information to find the problem?

@texnixe
Copy link
Member

texnixe commented Mar 25, 2022

I can't reproduce the issue, at least not with images that are larger than the target size. An image that was smaller than the target size was blown up though, tested with PHP 8.1 on Mac with Laravel Valet.

@andreasotto
Copy link
Author

andreasotto commented Mar 25, 2022

It does not work on Linux (latest Debian, latest PHP8). Maybe there are some system libraries missing. But that means we need some more documentation of dependencies. But these are all just guesses. The fact is that images from other formats are not converted to WebP in this configuration:

  • Debian 11
  • PHP 8.1

Installed package: libwebp-dev

gd is configured with gd --with-freetype=/usr/include/ --with-webp --with-jpeg=/usr/include/ && docker-php-ext-install -j$(nproc) gd

phpinfo() says: WebP Support: enabled

I have loaded jpg and other formats into Kirby. The output format chosen was webp. The images look like they would habe been converted to webp, but the size is not changed. So the images are way too big to use in the website. But in reality, no image has been created in the media folder.

image

There is only a job file, but no image has been saved:

image

content of jobs file:

{"width":1950,"quality":30,"crop":true,"format":"webp","filename":"stocksnap_btg0uzk1nx-1.jpg"}

This looks like the webp conversion is not working, but unfortunately no error message is displayed either.

@andreasotto
Copy link
Author

andreasotto commented Mar 25, 2022

It worked. The key point was the configuration of gd. This is how it works:

gd --with-freetype=/usr/include/ --with-webp=/usr/include/ --with-jpeg=/usr/include/

@afbora
Copy link
Member

afbora commented Mar 25, 2022

@andreasotto Closing the issue then, right?

@andreasotto
Copy link
Author

Maybe a short discussion about the requirements or dependencies would be useful, because I think there are two aspects:

  1. missing documentation
  2. check (e.g. show in the panel if requirements are not met - there is no error message and no hint).

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the type: stale 💤 Will be closed soon because there was no recent activity label Sep 22, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: discussion 🗣 Requires further discussion to proceed type: stale 💤 Will be closed soon because there was no recent activity
Projects
None yet
Development

No branches or pull requests

5 participants