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

Blured thumbnails #134

Open
leomp12 opened this issue Mar 23, 2023 · 1 comment
Open

Blured thumbnails #134

leomp12 opened this issue Mar 23, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@leomp12
Copy link
Member

leomp12 commented Mar 23, 2023

Transformando imagens runtime server-side é até simples:

let thumbWidth: number;
let thumbHeight: number;
if (aspectRatio === 1) {
  thumbWidth = thumbHeight = Math.min(attrs.width || 32, 32);
} else if (aspectRatio > 1) {
  thumbWidth = Math.min(attrs.width || 32, 32);
  thumbHeight = Math.round(thumbWidth / aspectRatio);
} else {
  thumbHeight = Math.min(attrs.height || 32, 32);
  thumbWidth = Math.round(thumbHeight * aspectRatio);
}
const thumbBuffer: Buffer = await sharp(getImageFilepath(src))
  .resize(thumbWidth, thumbHeight, {
    fit: sharp.fit.fill,
  })
  .blur(2)
  .toBuffer();
const thumbBase64 = thumbBuffer.toString('base64');
if (!attrs.style) attrs.style = '';
attrs.style += `background-image: url("data:image/png;base64,${thumbBase64}");`;
attrs.style += 'background-repeat: no-repeat; background-size: 100% 100%;';

Mas não manipulamos imagens no SSR runtime em serverless (#129) e devemos continuar não fazendo.

Talvez a solução seja um script separado executado após o primeiro build (SSG) lendo cada imagem pré-compilada, criando o base64 da thumb de cada uma e adicionando de volta no images.dist.csv na linha da respectiva imagem.

@leomp12 leomp12 added the enhancement New feature or request label Mar 23, 2023
@leomp12
Copy link
Member Author

leomp12 commented Apr 21, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant