rosell-dk / webp-convert

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

webp-on-demand does not redirecting me to image #215

Closed sashabeep closed 3 years ago

sashabeep commented 5 years ago

in my htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Redirect images to webp-on-demand.php (if browser supports webp)
    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME} [NC,L]
</IfModule>

AddType image/webp .webp

When i try to open any .jpg file hothing happens with on-the-fly conversion, just jpg displays. But when i call /webp-on-demand.php?source=my/jpg/file.jpg script is reporting that

...
gd succeeded :)

Converted image in 36 ms, reducing file size with 22% (went from 16 kb to 13 kb)

and creates my/jpg/file.jpg.webp alongside with original one

Why are redirect to conversion and created image doesn't work? I'm using lite speed web server The other rewrite rules in .htaccess works as expected. What am i missing?

sashabeep commented 5 years ago

UPD: Moved redirect rule to the top of .htaccess file and conversation seems to be ok but i'm getting reports instead of images despite the 'show-report' option is set true or false or commented

Снимок экрана 2019-09-09 в 23 20 26

rosell-dk commented 5 years ago

Weird.

I have many changes with regards to the .htaccess rules in the upcoming release. And some handy buttons for running self-tests / diagnosis. Lets see how this all acts in the next release.

rosell-dk commented 5 years ago

0.15.0 is out. Can you tell me if it works in 0.15.0?

sashabeep commented 5 years ago

Still getting broken images with html content-type. Direct link shows the images, .webp copy is not creating, redirect doesnt work.

Снимок экрана 2019-09-17 в 12 35 20

rosell-dk commented 5 years ago

Can you paste in the output after pressing the "Live test" buttons ? Perhaps you simply need to change some file permissions.

sashabeep commented 5 years ago

Hmmm...

Fatal error: Uncaught Error: Call to undefined method WebPConvert\WebPConvert::convertAndServe() in /****/webp-on-demand.php:16 Stack trace: #0 {main} thrown in /****/webp-on-demand.php on line 16
sashabeep commented 5 years ago

Installed using composer

sashabeep commented 5 years ago

webp-on-demand.php

<?php
require 'vendor/autoload.php';        // Make sure to point this correctly

use WebPConvert\WebPConvert;

$source = $_GET['source'];            // Absolute file path to source file. Comes from the .htaccess
$destination = $source . '.webp';     // Store the converted images besides the original images (other options are available!)

$options = [

    // UNCOMMENT NEXT LINE, WHEN YOU ARE UP AND RUNNING!    
    'show-report' => false             // Show a conversion report instead of serving the converted image.

    // More options available!
];
WebPConvert::convertAndServe($source, $destination, $options);
rosell-dk commented 5 years ago

Sorry, ignore my last comment. I thought you were using the Wordpress plugin. There is of course no "test" buttons in this library...

rosell-dk commented 3 years ago

The problem was perhaps simply that you were using the tutorial for 1.3 but using WebPConvert 2.0. The "convertAndServe" method was renamed to "serveConverted" in 2.0.