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

If data-background-image is a data uri, background image will not show up #2978

Closed
edl7878 opened this issue Jun 24, 2021 · 7 comments
Closed

Comments

@edl7878
Copy link

edl7878 commented Jun 24, 2021

If data-background-image is a data uri, background image will not show up

data-background-image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQsAAAC9CAMAAACTb6i8AAABtlBMVEX8/vz///8AAAD8///8Pj8TFRr8//z59vRvAABbAABvCxB+AAAAAAoTGB2BCxKJAAASERZjAADu6+oVHiYbIi3izsuXdXWtW0tXWFxnAAB5CxGFAAAAABCGCxPv4912AACwYVQGDhQeDxDPsKx+aGT8JiZ7XVrft662al5cVlelX1Td0dfKs7Tet7S+pbOylqapfoGiAADKe3WwkKena1urVzmbSCeuiJazhYesKBWFKgC1AACrAADOvbrg4OHU1tq9wMSEhIidmpo5N0FkZ4JvdZJbU2x6cpWrl57j6POAmteDg6aJcYeCa3O2r7BrQUFLAACQUUaKXFWcdGybdoO4k5GzTDjKj4C0QCI0AAAtAABsbG8IFCFse6Spp7V+gLFVKBGKXU98IxiWNyvEbl5cXoJNMTBoTEeNgIautdRkGQ1MJxxhMiGeMB+5cmp/jbFxU0WANDC6gnpFDAa3cW9MGxk6HRl9eo2Eam6SW1zImZSiRzygjYWXNiFmRTecUVhDRkzCYEuGaHj8UVD7zMqVPzC2MA9VJgDFz+b7nJtNW45yPTaVnMP8uLT8i4i5YkhQOC77bGrMjaOvAAAJA0lEQVR4nO2a/VvTWBaAextL+CqFQHL5agk0xFhgsQiLnbUBBEZ2tJSpED4dHctu2ZHGWlRiSzs6I+zMsA7jfzznJi0WcPaZX9y4POcFgSRN2/ty7jnnXvR4EARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBPmcIIW6/hc+Goe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3MhvNLGGwGfBgE+aIZO04mdKGh9YikzyuHsM6lckoS6nj3fusO4939WQDjgsP9yvIGHzvbACBC8OE3AlxoUGzCQmDwmKEGqtObuE8hSLUlEiklA9HssE9d12cbld4O6eqv/VFlixUaaGm71hQpB1J4T/cFF+QLMigUtze6hnKFb8upis7/9y79+9/9lTqyHY0VsyCJagZEBfjIcgNsmyOVC5DTQkVwFE+DHWWBptUt3cDCadPT7ONrdMTHn1I1z21O29O0ai9ie196dWbnMsfWi2n2eKIp3ArFqPUzp2wIotA7QiJYuh0n4zjoQ7ZX0hepsW+V267qAzl/Ik/c9d/36cUtOxRLLa2TWO8h6xCzoQ66uFq74LVWTjEXitUMCI00rLivotPBImurcVisW1qQkqB/gpmybnNUJFGaFE28+OHkQi06Nmhy+vCPGIu3lBIJGzNrtkbOLWACliympA8I7AyKZ6/fIkgI1HmwrC3RD/qolCSwYIGH+ORdCD/B398uAxwfPTo6JbhLMq1E2g2zXMuiJhnEQFxcfhF8XL/1wRoNguiUzQ4MS6KIxf+xgyrEzFcAFgKdeEd/g+pqUcXqrLnzIXLbgJBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBEARBkE/P74UdssLPdnycAAAAAElFTkSuQmCC"
@Yelliiii
Copy link

Evet katkı lazim

@amelo1990
Copy link

@neckish
Copy link

neckish commented Aug 6, 2021

Hi, Same issue here. It was working with version 4.0.2.

@fgracia
Copy link

fgracia commented Sep 23, 2021

Hello,
Same issue, working with 4.1.0 but not above.

@cderv
Copy link

cderv commented Sep 28, 2021

It took me time to found this opened issue but at least it gave me the opportunity to dig into why this was not working.

For the context, I am using reveal.js with Pandoc to produce --self-contained document. All images and other resources are base64 encoded.

I believe this issue is a regression that happens after 4.1.1 release, specifically after support for multiple background images in #2940 by @cmeessen

This is the new code now to create the background-image CSS style on the element:

// Images
if( backgroundImage ) {
backgroundContent.style.backgroundImage = backgroundImage.split( ',' ).map( background => {
return `url(${encodeURI(background.trim())})`;
}).join( ',' );
}

The data-background-image is split on , which is causing the issue because data encoded URI will have a , necessarily:

data:[<mediatype>][;base64],<data>

from the spec https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

That is why currently two url() call are created for the background-image style because the content is wrongly split into two elements

For example, source is

data-background-image="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/

But after reveal.js processes it, it gets wrongly split into two url() call

<div class="slide-background-content" style="background-image: url(&quot;data:image/jpeg;base64&quot;), url(&quot;/9j/4AAQSkZJRgABAQEASABIAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/

It should not be split in that case.

<div class="slide-background-content" style="background-image: url(&quot;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/

One solution would be to not split when data: field is found ?
Or possibly try another algorithm to support multiple images ?

I can try a PR if that helps.

And in any case, hope it helps get a fix for next version. Thanks!

@hakimel
Copy link
Owner

hakimel commented Sep 28, 2021

Thanks for debugging @cderv. This has been fixed now—reveal.js will not try to split background images in base64 format (i.e. beginning with data:).

@hakimel hakimel closed this as completed Sep 28, 2021
@cderv
Copy link

cderv commented Sep 28, 2021

Thanks !

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

8 participants
@hakimel @edl7878 @cderv @fgracia @neckish @amelo1990 @Yelliiii and others