rosell-dk / webp-convert

Convert jpeg/png to webp with PHP (if at all possible)
MIT License
578 stars 102 forks source link

command-line-options are being ignored #259

Closed FluffyDiscord closed 3 years ago

FluffyDiscord commented 3 years ago

Hi, I tried serving the image with this setup, but my command line options are being ignored. What the hell, where do I place them ?

lib: 2.3.2

Trying to convert by executing the following command:
cwebp -metadata all -q 85 -alpha_q '85' -m 6 '/media/projects/img.png' -o '/media/projects/img.png.webp' 2>&1 2>&1
        WebPConvert::serveConverted($file, $file.'.webp', [
            'fail' => 'original',
            'fail-when-fail-fails' => '404',
            'reconvert' => true,
            'serve-original' => false,
            'suppress-warnings' => false,

            'serve-image' => [
                'headers' => [
                    'cache-control' => true,
                    'expires' => false,
                ],
                'cache-control-header' => 'public, max-age=31536000', // 1 year
            ],
            'command-line-options' => '-resize 10 10',
            'cwebp-command-line-options' => '-resize 10 10',

            'convert' => [
                'try-cwebp' => false,
                'command-line-options' => '-resize 10 10',
                'cwebp-command-line-options' => '-resize 10 10',
                'converters' => ['cwebp'],
                'quality' => 'auto',
                'encoding' => 'lossy',
                'metadata' => 'all',
                'png' => [

                    'command-line-options' => '-resize 10 10',
                    'cwebp-command-line-options' => '-resize 10 10',
                ],
                'jpeg' => [
                    'command-line-options' => '-resize 10 10',
                    'cwebp-command-line-options' => '-resize 10 10',

                ]
            ]
        ], new \WebPConvert\Loggers\EchoLogger(), new \WebPConvert\Loggers\EchoLogger());
rosell-dk commented 3 years ago

Hi, Sorry for the late reply.

Currently only "common" options pass down from the stack converter to the individual converters. "Common" roughly means most of the options, but not those that only applies to a single converter. I do not recall why I created it this way. It looks like a bug, but on the other hand, I deliberately did the check:

In Stack.php, I have this line:

if ($option->isValueExplicitlySet() && !($option instanceof GhostOption)) {

The latter part is the one that is responsible here. If it is removed, your code works as expected.

Until I get around deciding the purpose of this check and whether to make the change, you can change your code to the following, which works :

WebPConvert::serveConverted($file, $file.'.webp', [
            'fail' => 'original',
            'fail-when-fail-fails' => '404',
            'reconvert' => true,
            'serve-original' => false,
            'suppress-warnings' => false,

            'serve-image' => [
                'headers' => [
                    'cache-control' => true,
                    'expires' => false,
                ],
                'cache-control-header' => 'public, max-age=31536000', // 1 year
            ],

            'convert' => [
                'converters' => ['cwebp'],
                'quality' => 80,
                'encoding' => 'auto',
                'converter-options' => [
                    'cwebp' => [
                        'try-cwebp' => false,
                        'command-line-options' => '-resize 10 12'
                    ]
                ],

            ]
        ], new \WebPConvert\Loggers\EchoLogger(), new \WebPConvert\Loggers\EchoLogger());
rosell-dk commented 3 years ago

By the way: You can use the "log-call-arguments" option to get more info about which options were recognized in the log

FluffyDiscord commented 3 years ago

Okay, will try. I think that a big step in improving the configuration options would be to pass and object, instead of an array. That way we devs could somewhat orient around the incomplete docs (?, unless I overlooked it, then I am sorry, please point me where I could find this information) by browsing through the "settings" objects.

rosell-dk commented 3 years ago

Fixed the bug