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

Inline "background" not replaced with shortpixel #400

Open
nxplace opened this issue May 4, 2023 · 5 comments
Open

Inline "background" not replaced with shortpixel #400

nxplace opened this issue May 4, 2023 · 5 comments

Comments

@nxplace
Copy link

nxplace commented May 4, 2023

Inline CSS with background with URL are not replaced with the shortpixel CDN (even html/css/inline minification activated):

<div class="slide-item" style="background:url('https://myurl.com/wp-content/uploads/sites/3/2023/04/reves.jpg') center center / cover no-repeat;">

Should be
<div class="slide-item" style="background:url('https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img/https://myurl.com/wp-content/uploads/sites/3/2023/04/reves.jpg') center center / cover no-repeat;">

It's working when we use background-image:url('').
Line 766 in autoptimizeImage.php should replaced from:
$out = preg_replace_callback( '/style=(?:"|\')[^<>]*?background*?:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
to :
$out = preg_replace_callback( '/style=(?:"|\')[^<>]*?background[-image]*?:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',

@futtta
Copy link
Owner

futtta commented May 4, 2023

feel free to issue a PR @nxplace :)

@futtta
Copy link
Owner

futtta commented Jun 5, 2023

the regex turned out to be a bit more complex, see https://regex101.com/r/QNjD6B/1 :-)

@futtta
Copy link
Owner

futtta commented Jun 5, 2023

could you test @nxplace ? :-)

@futtta
Copy link
Owner

futtta commented Jun 5, 2023

the regex might work on regex101 but a new unit test fails so it seems more changes might be needed ;-)

@futtta
Copy link
Owner

futtta commented Jun 5, 2023

tested again locally and it seems to work, so looks like an issue with the unit test, looking forward to your feedback after all ...

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