๋ฐ˜์‘ํ˜•

sizes


sizes๋Š” ๋ฏธ๋””์–ด ์กฐ๊ฑด์— ํ•ด๋‹นํ•˜๋Š” ์ด๋ฏธ์ง€์˜ ์ตœ์  ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ์ด๋‹ค.

 

๐Ÿ’ก ๊ณ ์œ  ํฌ๊ธฐ(๋กœ๋“œ๋œ ์ด๋ฏธ์ง€ ํฌ๊ธฐ)๋Š” next.config.js ํŒŒ์ผ์˜ imageSizes, deviceSizes ์†์„ฑ ๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ๊ฒฐ์ •๋œ๋‹ค(srcset). ์‚ฌ์šฉ์ž ๋””๋ฐ”์ด์Šค ํฌ๊ธฐ์— ๋”ฐ๋ผ ์•„๋ž˜ ์ค‘๋‹จ์  ์ค‘ ํ•˜๋‚˜๊ฐ€ ๊ณ ์œ  ํฌ๊ธฐ๊ฐ€ ๋œ๋‹ค.

  • deviceSizes ๊ธฐ๋ณธ๊ฐ’ : [640, 750, 828, 1080, 1200, 1920, 2048, 3840]
  • imageSizes ๊ธฐ๋ณธ๊ฐ’ : [16, 32, 48, 64, 96, 128, 256, 384]

 

Next/Image์—์„œ layout='responsive' ํ˜น์€ layout='fill' ์ผ ๋•Œ sizes ์†์„ฑ์„ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ํ•ญ์ƒ 100vw ๋„ˆ๋น„์˜ ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋“œํ•œ๋‹ค. ๋งŒ์•ฝ ~500px ์ •๋„์˜ ๋ฐฐ๋„ˆ์— ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ํ•„์š” ์ด์ƒ์œผ๋กœ ํฐ ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋“œํ•˜๋Š” ์…ˆ์ด ๋œ๋‹ค.

 

๋ Œ๋”๋ง์— ํ•„์š”ํ•œ ๋„ˆ๋น„๋Š” 373px ๋ฐ–์— ์•ˆ๋˜์ง€๋งŒ 2048 × 1536 ํฌ๊ธฐ์˜ ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋“œํ–ˆ๋‹ค

๐Ÿ’ก Next.js์—์„œ sizes ์†์„ฑ์€ layout='responsive', layout='fill' ์ผ๋•Œ๋งŒ ์ ์šฉ๋œ๋‹ค.

 

์ด๋•Œ sizes ์†์„ฑ์„ ์ง€์ •ํ•˜๋ฉด ๋ถˆํ•„์š”ํ•˜๊ฒŒ ํฐ ์ด๋ฏธ์ง€ ๋กœ๋“œ๋ฅผ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค. sizes ์†์„ฑ์€ ์ด๋ฏธ์ง€ ์†Œ์Šค ๋ฆฌ์ŠคํŠธ์—์„œ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋‹ค์šด๋กœ๋“œํ•  ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ •ํ•  ๋•Œ ์ฐธ๊ณ ํ•˜๋Š” ์†์„ฑ์ด๋‹ค.

 

๋ธŒ๋ผ์šฐ์ €๋Š” ๋ Œ๋”๋งํ•  ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ์•Œ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ทฐํฌํŠธ๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€ ํฌ๊ธฐ์˜ ์ด๋ฏธ์ง€๋ฅผ ์„ ํƒํ•œ๋‹ค. sizes ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋ฏธ์ง€๊ฐ€ ๋ทฐํฌํŠธ๋ณด๋‹ค ์ž‘๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๋ ค์ค„ ์ˆ˜ ์žˆ๋‹ค.

 

width๋Š” ์ด๋ฏธ์ง€ ์ถœ๋ ฅ ํฌ๊ธฐ๋งŒ ์ง€์ •ํ•˜์ง€๋งŒ sizes๋Š” ์ถœ๋ ฅ ํฌ๊ธฐ + ์ตœ์  ํฌ๊ธฐ๋„ ํ•จ๊ป˜ ์ง€์ •ํ•˜๋Š” ๊ฐœ๋…(sizes ๊ด€๋ จ ๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋งํฌ ์ฐธ๊ณ ).

<div className="grid-element">
  <Image
    src="/example.png"
    fill
    sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
  />
</div>

 

  • ๋ทฐํฌํŠธ ํฌ๊ธฐ๊ฐ€ 768px ์ดํ•˜๋ฉด 100vw ํฌ๊ธฐ์™€ ๊ฐ€์žฅ ๊ทผ์ ‘ํ•œ ์ด๋ฏธ์ง€ ์‚ฌ์šฉ
  • ๋ทฐํฌํŠธ ํฌ๊ธฐ๊ฐ€ 769px ~ 1200px ์‚ฌ์ด๋ฉด 50vw ํฌ๊ธฐ์™€ ๊ฐ€์žฅ ๊ทผ์ ‘ํ•œ ์ด๋ฏธ์ง€ ์‚ฌ์šฉ
  • ๋ทฐํฌํŠธ ํฌ๊ธฐ๊ฐ€ 1201px ์ด์ƒ์ด๋ฉด 33vw ํฌ๊ธฐ์™€ ๊ฐ€์žฅ ๊ทผ์ ‘ํ•œ ์ด๋ฏธ์ง€ ์‚ฌ์šฉ

 

๋ฐฐ๋„ˆ์ฒ˜๋Ÿผ ๊ณ ์ •์ ์ธ ํฌ๊ธฐ๋ผ๋ฉด sizes="373px" ์ด๋ ‡๊ฒŒ ํŠน์ • ์‚ฌ์ด์ฆˆ๋ฅผ ์ง์ ‘ ์ง€์ •ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

 

sizes ์†์„ฑ์„ 373px๋กœ ์ง€์ •ํ•œ ํ›„ ๊ณ ์œ  ํฌ๊ธฐ๊ฐ€ 750px๋กœ ์ค„์—ˆ๋‹ค(๋ ˆํ‹ฐ๋‚˜ ๋””์Šคํ”Œ๋ ˆ์ด์—์„  2๋ฐฐ ํฐ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค)

ํ•œํŽธ Next.js์—์„  sizes ์†์„ฑ์— ์–ด๋–ค ๊ฐ’์„ ๋ช…์‹œํ–ˆ๋Š”์ง€์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์ด๋ฏธ์ง€ ์†Œ์Šค ๋ฆฌ์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

  • sizes ์†์„ฑ์„ ๋ช…์‹œํ•˜์ง€ ์•Š์œผ๋ฉด ๊ณ ์ • ํฌ๊ธฐ ์ด๋ฏธ์ง€์— ์ ํ•ฉํ•œ small source set์„ ์ƒ์„ฑํ•œ๋‹ค.
    'responsive', 'fill' ๋ ˆ์ด์•„์›ƒ์ผ ๋•Œ sizes ์†์„ฑ์„ ๋ช…์‹œํ•˜์ง€ ์•Š์œผ๋ฉด ํ•ญ์ƒ 100vw๊ฐ€ ๋˜๋ฏ€๋กœ ์ฃผ์˜
  • sizes ์†์„ฑ์„ ๋ช…์‹œํ•˜๋ฉด ๋ฐ˜์‘ํ˜• ์ด๋ฏธ์ง€์— ์ ํ•ฉํ•œ large source set์„ ์ƒ์„ฑํ•œ๋‹ค.
  • 50vw ๊ฐ™์€ ๋ทฐํฌํŠธ ๋„ˆ๋น„์˜ ๋น„์œจ์„ ๋ช…์‹œํ•˜๋ฉด ์ด๋ณด๋‹ค ์ด๋ฏธ์ง€์˜ ์ž‘์€ source set์€ ์ œ์™ธ๋œ๋‹ค.

 

width / height


๐Ÿ’ก width, height ์†์„ฑ์€ ์ •์ ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜จ ์ด๋ฏธ์ง€ ํ˜น์€ layout="fill" ์„ ์ œ์™ธํ•˜๊ณค ํ•„์ˆ˜ ํ•ญ๋ชฉ์ด๋‹ค.

 

layout์ด 'responsive', 'fill' ์ผ ๋•Œ width, height ์†์„ฑ์— ์ž…๋ ฅํ•œ ๊ฐ’๋ณด๋‹ค ๋” ํฐ ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋“œํ•˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•œ๋‹ค. Next/Image์—์„  layout ์†์„ฑ์— ๋”ฐ๋ผ width, height๊ฐ€ ๋‹ค๋ฅด๊ฒŒ ์ž‘๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

  • 'instrinsic', 'fixed' : ๋ Œ๋”๋ง ์‚ฌ์ด์ฆˆ
  • 'responsive', 'fill' : ์›๋ณธ ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ → ์ด๋ฏธ์ง€ ๋น„์œจ์„ ์ถ”์ •ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ

 

The width property can represent either the rendered width or original width in pixels, depending on the layout and sizes properties.

When using layout="intrinsic" or layout="fixed" the width property represents the rendered width in pixels, so it will affect how large the image appears.

When using layout="responsive", layout="fill", the width property represents the original width in pixels, so it will only affect the aspect ratio.

The width property is required, except for statically imported images, or those with layout="fill".

 

srcset


srcset์€ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋ทฐํฌํŠธ ํฌ๊ธฐ์— ๋”ฐ๋ผ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ์ด๋ฏธ์ง€ ์†Œ์Šค ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ช…์‹œํ•˜๋Š” ์†์„ฑ์ด๋‹ค.
(๋ธŒ๋ผ์šฐ์ €์—๊ฒŒ ์ด๋ฏธ์ง€ ์„ ํƒ๊ถŒ ์œ„์ž„)

 

๐Ÿ’ก srcset์€ ๋‹ค์–‘ํ•œ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง€๋Š” ๋™์ผ ๋น„์œจ์˜ ์ด๋ฏธ์ง€๋“ค์„ ์ตœ์†Œ 2๊ฐœ ์ด์ƒ ๋ช…์‹œํ•˜๋Š” ์†์„ฑ์œผ๋กœ ์ด๋ฏธ์ง€ ์„ ํƒ๊ถŒ์„ ๋ธŒ๋ผ์šฐ์ €์—๊ฒŒ ์œ„์ž„ํ•œ๋‹ค. ๋•Œ๋ฌธ์— ์–ด๋–ค ํฌ๊ธฐ์˜ ์ด๋ฏธ์ง€๊ฐ€ ์„ ํƒ๋ ์ง€ ์ •ํ™•ํžˆ ์•Œ๊ธฐ ์–ด๋ ต๋‹ค. w(์ด๋ฏธ์ง€ ๋„ˆ๋น„) x(์ด๋ฏธ์ง€ ๋น„์œจ) ๋””์Šคํฌ๋ฆฝํ„ฐ๋Š” ๋ธŒ๋ผ์šฐ์ €์—๊ฒŒ ์ด๋ฏธ์ง€์˜ ํฌ๊ธฐ๋ฅผ ์•Œ๋ ค์ฃผ๋Š” ์šฉ๋„๋กœ, ์ด๋ฏธ์ง€์˜ ์ •ํ™•ํ•œ ํฌ๊ธฐ๋ฅผ ์ž…๋ ฅํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ w ๋””์Šคํฌ๋ฆฝํ„ฐ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋ธŒ๋ผ์šฐ์ €๋Š” ๋””์Šคํฌ๋ฆฝํ„ฐ๋ฅผ ํ†ตํ•ด ๊ฐ ์ด๋ฏธ์ง€์˜ ์ตœ์ ํ™”๋œ ํ”ฝ์…€ ๋ฐ€๋„๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ์ ์ ˆํ•œ ์ด๋ฏธ์ง€๋ฅผ ์„ ํƒํ•œ๋‹ค.

 

Next/Image๋Š” ๊ฐ ๋””๋ฐ”์ด์Šค ํฌ๊ธฐ์˜ srcset์„ ๋ฏธ๋ฆฌ ์ง€์ •ํ•ด ๋†“๊ณ  ์‚ฌ์šฉ์ž ๋””๋ฐ”์ด์Šค์— ๋งž๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•œ๋‹ค(srcset ์†์„ฑ์— ๊ด€ํ•œ ๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋งํฌ ์ฐธ๊ณ ). ์ด๋ฏธ์ง€์— ๋Œ€ํ•œ ์ฒซ ์š”์ฒญ์„ ๋ฐ›์œผ๋ฉด Next.js ์„œ๋ฒ„์—์„œ ์‚ฌ์ด์ฆˆ/ํฌ๋งท ๋“ฑ์„ ์ตœ์ ํ™”ํ•œ ์ด๋ฏธ์ง€ ํŒŒ์ผ๋“ค์„ ์ƒ์„ฑํ•ด์„œ ์•„๋ž˜ ๊ฐ™์€ srcset์ด ์ง€์ •๋œ๋‹ค.

 

Next.js์— ์˜ํ•ด ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋œ srcset

layout ์†์„ฑ์ด 'fixed', 'intrinsic' ์ผ ๋• 1x, 2x 2๊ฐœ์˜ srcset๋งŒ ์ƒ์„ฑํ•œ๋‹ค. 'responsive', 'fill' ์ผ ๋• next.config.js ํŒŒ์ผ์— ์žˆ๋Š” deviceSizes, imageSizes ์†์„ฑ์„ ์ฐธ์กฐํ•ด์„œ srcset์„ ์ƒ์„ฑํ•œ๋‹ค. ๋‘ ์†์„ฑ์„ ๋”ฐ๋กœ ์ง€์ •ํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์•„๋ž˜ ๊ธฐ๋ณธ๊ฐ’์ด ์ ์šฉ๋œ๋‹ค. ์ปจํ…Œ์ด๋„ˆ์˜ ์ตœ๋Œ€ ๋„ˆ๋น„๊ฐ€ ์ •ํ•ด์ ธ ์žˆ๊ฑฐ๋‚˜ ์‚ฌ์šฉ์ž์˜ ๋””๋ฐ”์ด์Šค ํฌ๊ธฐ๋ฅผ ์˜ˆ์ธกํ•  ์ˆ˜ ์žˆ์–ด์„œ ์ด๋ฏธ์ง€ ์†Œ์Šค ๋ฆฌ์ŠคํŠธ๋ฅผ ์„ธ๋ถ„ํ™”ํ•  ํ•„์š” ์—†๋‹ค๋ฉด ์ง์ ‘ ์ˆ˜์ •ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

module.exports = {
  images: {
    // imageSizes, deviceSizes๋ฅผ ๋”ฐ๋กœ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ์•„๋ž˜ ๊ธฐ๋ณธ๊ฐ’์ด ์ ์šฉ๋œ๋‹ค
    deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
    imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
  },
};

 

๐Ÿ’ก Advanced ์‚ฌ๋ก€๋ฅผ ์ œ์™ธํ•˜๊ณค deviceSizes, imageSizes ์ˆ˜์ •ํ•  ์ผ์€ ๋ณ„๋กœ ์—†๋‹ค

 

  • deviceSizes : ๋””๋ฐ”์ด์Šค ์ค‘๋‹จ์  ๋ชฉ๋ก ์ง€์ •
    Next/Image ์ปดํฌ๋„ŒํŠธ๊ฐ€ sizes ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ srcset ์ƒ์„ฑ์„ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค.
  • imageSizes : ์ด๋ฏธ์ง€ ๋„ˆ๋น„ ๋ชฉ๋ก ์ง€์ •
    deviceSizes์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ srcset ์ƒ์„ฑ์„ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค. imageSizes๋Š” deviceSizes์™€ ์—ฐ๊ฒฐ๋ผ์„œ ์ „์ฒด ์ด๋ฏธ์ง€ ์†Œ์Šค ๋ฆฌ์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. imageSizes๋Š” sizes ์†์„ฑ์„ ์ œ๊ณตํ–ˆ์„ ๋•Œ๋งŒ ์‚ฌ์šฉ๋˜๋Š”๋ฐ ์ด ๊ฒฝ์šฐ ์ด๋ฏธ์ง€๊ฐ€ ๋ทฐํฌํŠธ ๋„ˆ๋น„๋ณด๋‹ค ์ž‘๋‹ค๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๋”ฐ๋ผ์„œ imageSizes ๋„ˆ๋น„๋Š” deviceSizes ๋ฐฐ์—ด์— ์žˆ๋Š” ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’๋ณด๋‹ค ์ž‘์•„์•ผ ํ•œ๋‹ค.

 

sizes/srcset์„ ๋ช…์‹œํ–ˆ์„ ๋•Œ ๋ธŒ๋ผ์šฐ์ € ๋™์ž‘

  1. ๊ธฐ๊ธฐ ๋„ˆ๋น„ ํ™•์ธ
  2. sizes ์†์„ฑ์—์„œ ๊ฐ€์žฅ ๋จผ์ € ์ฐธ์ด ๋˜๋Š” ์กฐ๊ฑด๋ฌธ ํ™•์ธ
  3. ํ•ด๋‹น ์กฐ๊ฑด๋ฌธ์—์„œ ์ œ๊ณตํ•˜๋Š” ์Šฌ๋กฏ ํฌ๊ธฐ ํ™•์ธ
  4. ํ•ด๋‹น ์Šฌ๋กฏ ํฌ๊ธฐ์— ๊ฐ€์žฅ ๊ทผ์ ‘ํ•œ ์ด๋ฏธ์ง€๋ฅผ srcset์—์„œ ๊ฒ€์ƒ‰ ํ›„ ์ ์šฉ

 

๋ ˆํผ๋Ÿฐ์Šค


 


๊ธ€ ์ˆ˜์ •์‚ฌํ•ญ์€ ๋…ธ์…˜ ํŽ˜์ด์ง€์— ๊ฐ€์žฅ ๋น ๋ฅด๊ฒŒ ๋ฐ˜์˜๋ฉ๋‹ˆ๋‹ค. ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”
๋ฐ˜์‘ํ˜•