- Your Image Is Probably Not Decorative — Smashing Magazine1
- JPG vs JPEG: Understanding the Most Common Image Format
- Using Modern Image Formats: AVIF And WebP — Smashing Magazine2
- Building an effective Image Component3
- Using Performant Next-Gen Images in CSS with image-set | CSS-Tricks4
- A Guide to the Responsive Images Syntax in HTML | CSS-Tricks5
- Frequently Asked Questions | WebP | Google Developers6
- Picture perfect images with the modern <img> element - Stack Overflow
- Learn Images | web.dev
- GitHub - JonasKruckenberg/imagetools: Load and transform images using a toolbox of custom import directives!
- Cloudflare Image Optimization · Cloudflare Image Optimization docs
Footnotes
커스텀 폰트 사용 시, 배포 중 Provided Edge Function is too large 에러가 발생할 경우 로컬 파일로 사용하지말고 fetch로 해당 폰트를 가져온다.12
Footnotes
import sharp from 'sharp'
import fg from 'fast-glob'
const entries = await fg('./**/*.png')
for (const entry of entries) {
const trimmedBuffer = await sharp(entry).trim().toBuffer()
const trimmedImage = sharp(trimmedBuffer)
const trimmedMetadata = await trimmedImage.metadata()
await trimmedImage
.resize({
width: Math.round(trimmedMetadata.width / 2),
height: Math.round(trimmedMetadata.height / 2),
})
.png()
.toFile(entry.replace(/\.png$/, '.half.png'))
}
offset(top, left)값, 이미지 사이즈 설정으로 crop 구현이 가능하다
sharp('img.png')
.extract({
left: 50,
top: 50,
width: 200,
height: 400
})
이미지 저장1
- 페이지에서 JavaScript를 통해 이미지 추출
- 캔버스에서 이미지 추출
- 서버에서 이미지 가져오기
- DevTools 프로토콜을 사용하여 이미지 추출
const client = await page.createCDPSession()
const { frameTree } = await client.send('Page.getResourceTree')
for (const resource of frameTree.resources) {
const { content, base64Encoded } = await client.send(
'Page.getResourceContent',
{ frameId: frameTree.frame.id, url: resource.url },
)
const contentBuffer = Buffer.from(content, base64Encoded ? 'base64' : 'utf8')
}
page.on('response', async (response) => {
const url = response.url()
const buffer = await response.buffer()
})