Oksydan / falcon

Prestashop starter theme that provides great development experience.
GNU General Public License v3.0
264 stars 63 forks source link

🐛 [BUG] - WebP images not being generated #278

Open danidinogo opened 1 year ago

danidinogo commented 1 year ago

Description

I am facing a problem for some days trying to generate the WebP images. The message it says when I upload a img is:

[Warning: DOMDocument::loadHTML(): Memory allocation failed in Entity, line: 6 in /home/.../.../modules/is_themecore/src/Core/Webp/WebpPictureGenerator.php on line 19]

You can see it in the logo for example: image

I have tried 2 ways to generate the WebP, but the same problem: image

I tried uploading the logo in jpg, webp and png format, but it keeps not generating the img. I mean, if i check the html source code and get the webp image url, it doesnt exist.

I tried removing cache from admin and from ftp. Not lucky

Node.js version

v14.1.0

php version

8.1

OS and it's version

CentOS

Browsers

Chrome

Required module/theme

is_themecore

Reproduction steps

1. Go to is_themecore
2. Enable WebP & choose any option
3. Upload logo

Logs

[Warning: DOMDocument::loadHTML(): Memory allocation failed in Entity, line: 6 in /home/.../.../modules/is_themecore/src/Core/Webp/WebpPictureGenerator.php on line 19]
Oksydan commented 1 year ago

Hi @danidinogo, What is your is_themecore version and memory limit?

danidinogo commented 1 year ago

Hi @danidinogo, What is your is_themecore version and memory limit?

Hi, first of all, thank you for such a fast response.

is_themecore is version 4.1.0: image

And memory_limit 1024M: image

The html source code where the warning appears in case it helps: image

Oksydan commented 1 year ago

Unfortunately I am not able to reproduce an issue 😞 Can you provide me more information about your server configuration? Can you provide me your .htaccess file? it should contains for example:

RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$1$2$3.webp !-f
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/p/$1/$1$2$3.webp [NC,L]

What is happening when you are visiting that url with webp file? Are you getting error or 404?

danidinogo commented 1 year ago

Omiting the domain url just in case it gets in Google, the htaccess contains that part:

# ~~start-is_themecore~~ Do not remove this comment
# Allow webp files to be sent by Apache 2.2
<IfModule !mod_authz_core.c>
    <Files ~ "\.(webp)$">
        Allow from all
    </Files>
</IfModule>

# Allow webp files to be sent by Apache 2.4
<IfModule mod_authz_core.c>
    <Files ~ "\.(webp)$">
        Require all granted
        allow from all
    </Files>
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^XXXXX.es$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$1$2$3.webp -f
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$1$2$3.webp !-f
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/p/$1/$1$2$3.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$1$2$3$4.webp -f
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$1$2$3$4.webp !-f
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/p/$1/$2/$1$2$3$4.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$1$2$3$4$5.webp -f
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$1$2$3$4$5.webp !-f
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/p/$1/$2/$3/$1$2$3$4$5.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$1$2$3$4$5$6.webp -f
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$1$2$3$4$5$6.webp !-f
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$1$2$3$4$5$6.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.webp -f
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.webp !-f
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.webp -f
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.webp !-f
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.webp -f
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.webp !-f
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/c/$1$2.webp -f
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/c/$1$2.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/c/$1$2$3.webp -f
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/c/$1$2$3.webp [L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/c/$1$2.webp !-f
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/c/$1$2.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{DOCUMENT_ROOT}/img/c/$1$2$3.webp !-f
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/img/c/$1$2$3.webp [NC,L]

RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.webp$ %{ENV:REWRITEBASE}modules/is_themecore/webp.php?source=%{DOCUMENT_ROOT}/$1.webp [NC,L]

</IfModule>
# ~~end-is_themecore~~ Do not remove this comment

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# https://www.prestashop.com - https://www.prestashop.com/forums

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

RewriteEngine on

#Domain: XXXXXXXXXX
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api(?:/(.*))?$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
RewriteRule ^upload/.+$ %{ENV:REWRITEBASE}index.php [QSA,L]

# Images
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^(([\d])(?:\-[\w-]*)?)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$1$3 [L]
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^(([\d])([\d])(?:\-[\w-]*)?)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$1$4 [L]
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^(([\d])([\d])([\d])(?:\-[\w-]*)?)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$1$5 [L]
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^(([\d])([\d])([\d])([\d])(?:\-[\w-]*)?)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$5/$1$6 [L]
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^(([\d])([\d])([\d])([\d])([\d])(?:\-[\w-]*)?)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$5/$6/$1$7 [L]
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^(([\d])([\d])([\d])([\d])([\d])([\d])(?:\-[\w-]*)?)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$5/$6/$7/$1$8 [L]
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^(([\d])([\d])([\d])([\d])([\d])([\d])([\d])(?:\-[\w-]*)?)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$5/$6/$7/$8/$1$9 [L]
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^c/([\d]+)(\-[\.*\w-]*)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/c/$1$2$3 [L]
RewriteCond %{HTTP_HOST} ^XXXXXXXXXX$
RewriteRule ^c/([a-zA-Z_-]+)(-[\d]+)?/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/c/$1$2$3 [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ %{ENV:REWRITEBASE}js/jquery/plugins/fancybox/images/$1.$2 [L]

# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/font-woff .woff
AddType font/woff2 .woff2
<IfModule mod_headers.c>
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg)$">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>

    <FilesMatch "\.pdf$">
      Header set Content-Disposition "Attachment"
      Header set X-Content-Type-Options "nosniff"
    </FilesMatch>
</IfModule>

<Files composer.lock>
    # Apache 2.2
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>

    # Apache 2.4
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
</Files>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404

# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

I have also enabled some options prestashop gives me to handle webp but unlucky. The server configuration is CentOS with Apache (I can give u phpinfo if u want).

When I visit the webp image i get a 403 (forbidden) but just because it doesnt exist. If I manually upload the file it works:

image
Oksydan commented 1 year ago

Is your store inside directory? Like domain.com/shop/

danidinogo commented 1 year ago

Is your store inside directory? Like domain.com/shop/

It is in the root folder of a subdomain. It also has language selection and it adds /en/, /es/ /pt/ to the url

danidinogo commented 1 year ago

Ok now it does generate the WebP. I had to enable the feature and the format in experimental options in Prestashop. The warning keeps being there:

image

Is it normal or it just happens to me? I will check that part of the code tomorrow anyway. Thanks!

Oksydan commented 1 year ago

Hi @danidinogo,

can you go to your ROOT_PROJECT/img and find .htaccess file there. Please paste content of this file.

BTW I am not recommending using prestashop webp generation. It's currently working only for product images and you are not able to use different driver than GD.

EDIT: About that error warning you can suppress it but I didn't face it yet. We will rewrite image generation in is_themecore v5. I will try to reproduce this warning or just suppress it by default.

danidinogo commented 1 year ago

Hi @danidinogo,

can you go to your ROOT_PROJECT/img and find .htaccess file there. Please paste content of this file.

BTW I am not recommending using prestashop webp generation. It's currently working only for product images and you are not able to use different driver than GD.

EDIT: About that error warning you can suppress it but I didn't face it yet. We will rewrite image generation in is_themecore v5. I will try to reproduce this warning or just suppress it by default.

HI again. So the /img/.htaccess is:

# Apache 2.2
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    <Files ~ "(?i)^.*\.(jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico|webp|avif)$">
        Allow from all
    </Files>
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
    Require all denied
    <Files ~ "(?i)^.*\.(jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico|webp|avif)$">
        Require all granted
    </Files>
</IfModule>
Oksydan commented 1 year ago

Hi @danidinogo,

your htaccess files are ok 🤔 Did you solve the warning problem?

danidinogo commented 1 year ago

Hi @danidinogo,

your htaccess files are ok 🤔 Did you solve the warning problem?

Hi there! Sorry for such a late reply. So I couldnt fix it, i just hidded the warning and for now i keep working on the modifications in the template, but honestly I would like to use the way this template produces the webp images and also solve the warnings.

As soon as I finish with the design of the shop I will start working on it. If i find out what is happening I will comment it here. Also if u want to personally check the error we are getting I could give u access to our development enviorenment which is where I am working on. Thanks very much for your time and patience!

Blaaszkovsky commented 4 months ago

Hi @danidinogo are you using apache or litespeed on the server?