Hatkat

img app

Nov 7th, 2025
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.26 KB | None | 0 0
  1. # 🎨 OPTIMIZACIÓN DE IMÁGENES PIXEL ART PARA WEB
  2.  
  3. ## 🔑 LA SOLUCIÓN PERFECTA: Pixel Art + Escalado CSS
  4.  
  5. ### **¡Buenas noticias!**
  6. El pixel art es **PERFECTO** para tu caso porque:
  7. - Las imágenes base son **TINY** (16x16, 32x32, 64x64 píxeles)
  8. - Pesan menos de 5KB cada una
  9. - Se escalan sin perder calidad usando CSS
  10. - Se ven nítidas en cualquier pantalla
  11.  
  12. ---
  13.  
  14. ## 📐 TAMAÑOS RECOMENDADOS PARA TUS ASSETS
  15.  
  16. ### **Personajes (Sprites)**
  17. ```
  18. Tamaño original: 32x32 píxeles
  19. Peso: 1-3 KB
  20. Escalado en pantalla: 128x128 o 160x160 píxeles
  21. Formato: PNG-8 (con transparencia)
  22. ```
  23.  
  24. ### **Retratos para Diálogos**
  25. ```
  26. Tamaño original: 64x64 píxeles
  27. Peso: 3-8 KB
  28. Escalado en pantalla: 192x192 o 256x256 píxeles
  29. Formato: PNG-8
  30. ```
  31.  
  32. ### **Edificaciones**
  33. ```
  34. Tamaño original: 128x128 píxeles
  35. Peso: 10-20 KB
  36. Escalado en pantalla: 256x256 o 384x384 píxeles
  37. Formato: PNG-8
  38. ```
  39.  
  40. ### **Fondos/Tilesets**
  41. ```
  42. Tamaño original: 256x256 píxeles (seamless)
  43. Peso: 15-30 KB
  44. Se repite con CSS (background-repeat)
  45. Formato: PNG-8
  46. ```
  47.  
  48. ### **Pantalla completa (cinemáticas)**
  49. ```
  50. Tamaño original: 320x568 píxeles (o 360x640)
  51. Peso: 30-60 KB
  52. Escalado: 100vw
  53. Formato: PNG-8 o WebP
  54. ```
  55.  
  56. ---
  57.  
  58. ## 💻 CÓDIGO CSS PARA ESCALADO PERFECTO
  59.  
  60. ### **Método 1: image-rendering (EL MÁS IMPORTANTE)**
  61.  
  62. ```css
  63. /* CRÍTICO: Esto mantiene los píxeles nítidos al escalar */
  64. .pixel-art {
  65. image-rendering: -moz-crisp-edges; /* Firefox */
  66. image-rendering: -webkit-crisp-edges; /* Webkit (Safari) */
  67. image-rendering: pixelated; /* Chrome/Opera */
  68. image-rendering: crisp-edges; /* Standard */
  69. -ms-interpolation-mode: nearest-neighbor; /* IE */
  70. }
  71.  
  72. /* Para sprites de personajes */
  73. .character-sprite {
  74. width: 128px; /* 4x el tamaño original de 32px */
  75. height: 128px;
  76. image-rendering: pixelated;
  77. }
  78.  
  79. /* Para retratos */
  80. .character-portrait {
  81. width: 256px; /* 4x el tamaño original de 64px */
  82. height: 256px;
  83. image-rendering: pixelated;
  84. }
  85.  
  86. /* Para edificaciones */
  87. .building {
  88. width: 384px; /* 3x el tamaño original de 128px */
  89. height: 384px;
  90. image-rendering: pixelated;
  91. }
  92. ```
  93.  
  94. ### **Método 2: Escalado Responsivo**
  95.  
  96. ```css
  97. /* Se adapta a cualquier pantalla */
  98. .responsive-pixel-art {
  99. width: 100%;
  100. max-width: 256px;
  101. height: auto;
  102. image-rendering: pixelated;
  103. }
  104.  
  105. /* Para móviles pequeños */
  106. @media (max-width: 375px) {
  107. .character-portrait {
  108. width: 192px;
  109. height: 192px;
  110. }
  111. }
  112.  
  113. /* Para móviles grandes */
  114. @media (min-width: 376px) {
  115. .character-portrait {
  116. width: 256px;
  117. height: 256px;
  118. }
  119. }
  120.  
  121. /* Para tablets */
  122. @media (min-width: 768px) {
  123. .character-portrait {
  124. width: 320px;
  125. height: 320px;
  126. }
  127. }
  128. ```
  129.  
  130. ---
  131.  
  132. ## 🗜️ HERRAMIENTAS DE OPTIMIZACIÓN
  133.  
  134. ### **1. TinyPNG / TinyJPG** (Recomendado #1)
  135. - Web: https://tinypng.com/
  136. - Reduce PNG hasta 70% sin pérdida visible
  137. - **Ejemplo:**
  138. - Antes: 15 KB → Después: 4 KB
  139. - Soporta batch (múltiples archivos)
  140.  
  141. ### **2. ImageOptim** (Mac) / FileOptimizer (Windows)
  142. - Optimización local sin subir a internet
  143. - Múltiples formatos
  144. - Gratuito
  145.  
  146. ### **3. Squoosh** (Google)
  147. - Web: https://squoosh.app/
  148. - Comparación visual antes/después
  149. - Múltiples formatos de salida
  150. - Control manual de calidad
  151.  
  152. ### **4. ImageMagick (Línea de comandos)**
  153. ```bash
  154. # Convertir a PNG-8 optimizado
  155. magick convert input.png -colors 256 -quality 95 output.png
  156.  
  157. # Redimensionar y optimizar
  158. magick convert input.png -resize 64x64 -colors 256 output.png
  159.  
  160. # Batch: optimizar toda una carpeta
  161. for file in *.png; do
  162. magick convert "$file" -colors 256 "optimized_$file"
  163. done
  164. ```
  165.  
  166. ---
  167.  
  168. ## 📦 FORMATOS RECOMENDADOS
  169.  
  170. ### **PNG-8 vs PNG-24 vs WebP**
  171.  
  172. | Formato | Peso | Calidad | Transparencia | Soporte |
  173. |---------|------|---------|---------------|---------|
  174. | PNG-8 | ⭐⭐⭐⭐⭐ Muy ligero | ⭐⭐⭐⭐ Excelente para pixel art | ✅ Sí | ✅ 100% |
  175. | PNG-24 | ⭐⭐ Pesado | ⭐⭐⭐⭐⭐ Perfecta | ✅ Sí | ✅ 100% |
  176. | WebP | ⭐⭐⭐⭐⭐ Muy ligero | ⭐⭐⭐⭐⭐ Excelente | ✅ Sí | ⚠️ 96% |
  177.  
  178. **Recomendación:**
  179. - **PNG-8** para todos tus assets (mejor balance)
  180. - **WebP como fallback** para navegadores modernos
  181.  
  182. ---
  183.  
  184. ## 🚀 ESTRATEGIA DE CARGA OPTIMIZADA
  185.  
  186. ### **1. Lazy Loading (Carga Perezosa)**
  187.  
  188. ```html
  189. <!-- Carga solo cuando sea visible -->
  190. <img src="placeholder.png"
  191. data-src="edificio-castillo.png"
  192. class="lazy pixel-art"
  193. loading="lazy"
  194. alt="Castillo">
  195. ```
  196.  
  197. ```javascript
  198. // Usando Intersection Observer
  199. const images = document.querySelectorAll('img.lazy');
  200.  
  201. const imageObserver = new IntersectionObserver((entries, observer) => {
  202. entries.forEach(entry => {
  203. if (entry.isIntersecting) {
  204. const img = entry.target;
  205. img.src = img.dataset.src;
  206. img.classList.remove('lazy');
  207. observer.unobserve(img);
  208. }
  209. });
  210. });
  211.  
  212. images.forEach(img => imageObserver.observe(img));
  213. ```
  214.  
  215. ### **2. Preload de Assets Críticos**
  216.  
  217. ```html
  218. <!-- En el <head> -->
  219. <link rel="preload" as="image" href="personaje-x-frontal.png">
  220. <link rel="preload" as="image" href="fondo-pueblo.png">
  221. ```
  222.  
  223. ### **3. Sprite Sheets (Recomendado para animaciones)**
  224.  
  225. En lugar de 8 imágenes separadas para movimiento:
  226.  
  227. ```
  228. sprites-personaje-x.png (256x64 píxeles)
  229. ├── Frame 1: 0-32px
  230. ├── Frame 2: 32-64px
  231. ├── Frame 3: 64-96px
  232. └── ... (8 frames en total)
  233.  
  234. Peso: 12 KB (en lugar de 8×3KB = 24KB)
  235. ```
  236.  
  237. ```css
  238. .sprite {
  239. width: 32px;
  240. height: 32px;
  241. background: url('sprites-personaje-x.png') no-repeat;
  242. image-rendering: pixelated;
  243. transform: scale(4); /* Escala 4x = 128px */
  244. }
  245.  
  246. .sprite.frame-1 { background-position: 0 0; }
  247. .sprite.frame-2 { background-position: -32px 0; }
  248. .sprite.frame-3 { background-position: -64px 0; }
  249. ```
  250.  
  251. ### **4. Progressive Web App (PWA) con Cache**
  252.  
  253. ```javascript
  254. // Service Worker para cachear assets
  255. self.addEventListener('install', (event) => {
  256. event.waitUntil(
  257. caches.open('pixel-art-cache-v1').then((cache) => {
  258. return cache.addAll([
  259. '/assets/personaje-x.png',
  260. '/assets/edificio-casa.png',
  261. '/assets/edificio-molino.png',
  262. '/assets/edificio-iglesia.png',
  263. '/assets/edificio-castillo.png',
  264. '/assets/fondo-cesped.png'
  265. ]);
  266. })
  267. );
  268. });
  269.  
  270. // Una vez cacheado, carga instantánea
  271. self.addEventListener('fetch', (event) => {
  272. event.respondWith(
  273. caches.match(event.request).then((response) => {
  274. return response || fetch(event.request);
  275. })
  276. );
  277. });
  278. ```
  279.  
  280. ---
  281.  
  282. ## 📊 EJEMPLO REAL DE PESOS
  283.  
  284. ### **Tu Aplicación Completa:**
  285.  
  286. ```
  287. PERSONAJES (9 assets):
  288. ├── X frontal: 2 KB
  289. ├── X sprites movimiento (8): 3 KB cada uno = 24 KB
  290. └── Total: 26 KB
  291.  
  292. RETRATOS NPCs (5 assets):
  293. ├── Poblador: 5 KB
  294. ├── Molinero: 5 KB
  295. ├── Sacerdote: 5 KB
  296. ├── Rey: 5 KB
  297. ├── Caos: 6 KB
  298. └── Total: 26 KB
  299.  
  300. EDIFICACIONES (8 assets):
  301. ├── Casa dañada: 15 KB
  302. ├── Casa reparada: 15 KB
  303. ├── Molino dañado: 18 KB
  304. ├── Molino reparado: 18 KB
  305. ├── Iglesia dañada: 20 KB
  306. ├── Iglesia reparada: 20 KB
  307. ├── Castillo dañado: 25 KB
  308. ├── Castillo reparado: 25 KB
  309. └── Total: 156 KB
  310.  
  311. FONDOS/UI (5 assets):
  312. ├── Fondo césped (tileable): 20 KB
  313. ├── Cuadro de diálogo: 3 KB
  314. ├── Botones UI: 8 KB
  315. ├── Torre Caos: 30 KB
  316. ├── Cinemática final: 50 KB
  317. └── Total: 111 KB
  318.  
  319. ═══════════════════════════
  320. TOTAL GENERAL: ~320 KB (0.32 MB)
  321. ═══════════════════════════
  322.  
  323. Tiempo de carga en 4G: < 1 segundo
  324. Tiempo de carga en 3G: 2-3 segundos
  325. ```
  326.  
  327. ---
  328.  
  329. ## ⚡ TÉCNICAS AVANZADAS DE OPTIMIZACIÓN
  330.  
  331. ### **1. Paleta de Colores Reducida**
  332.  
  333. Cuando generes el pixel art, especifica:
  334. ```
  335. Limited color palette, 32 colors maximum, indexed color mode
  336. ```
  337.  
  338. Menos colores = archivos más pequeños
  339.  
  340. ### **2. Comprimir con Herramientas CLI**
  341.  
  342. ```bash
  343. # Usando pngquant (mejor compresor para pixel art)
  344. pngquant --quality=85-95 --ext .png --force *.png
  345.  
  346. # Usando oxipng (ultra compresión)
  347. oxipng -o 6 --strip safe *.png
  348. ```
  349.  
  350. ### **3. WebP con Fallback**
  351.  
  352. ```html
  353. <picture>
  354. <source srcset="personaje-x.webp" type="image/webp">
  355. <img src="personaje-x.png" class="pixel-art" alt="X">
  356. </picture>
  357. ```
  358.  
  359. ### **4. Base64 para Assets Muy Pequeños**
  360.  
  361. Para iconos ultra pequeños (< 2KB):
  362.  
  363. ```css
  364. .icon-star {
  365. background: url('data:image/png;base64,iVBORw0KGgoAAAANS...') no-repeat;
  366. /* Evita 1 request HTTP */
  367. }
  368. ```
  369.  
  370. ---
  371.  
  372. ## 🎯 RECOMENDACIONES FINALES PARA TU APP
  373.  
  374. ### **Tamaños de Generación en IA:**
  375.  
  376. ```
  377. Personaje X: 64x64 píxeles (luego escalar a 32x32)
  378. Retratos NPCs: 128x128 píxeles (luego escalar a 64x64)
  379. Edificaciones: 256x256 píxeles (luego escalar a 128x128)
  380. Fondos: 512x512 píxeles (luego escalar a 256x256)
  381. ```
  382.  
  383. ### **Flujo de Trabajo:**
  384.  
  385. 1. **Generar** en IA con tamaño 2x del final
  386. 2. **Redimensionar** con ImageMagick o Photoshop (Nearest Neighbor)
  387. 3. **Optimizar** con TinyPNG
  388. 4. **Convertir** a WebP también (con Squoosh)
  389. 5. **Implementar** con CSS `image-rendering: pixelated`
  390.  
  391. ### **Prompt Actualizado para IA:**
  392.  
  393. Agrega al final de tus prompts:
  394. ```
  395. 64x64 pixels resolution, indexed color mode, limited color palette 32 colors, optimized for web, clean pixel art
  396. ```
  397.  
  398. ---
  399.  
  400. ## 📱 EJEMPLO DE IMPLEMENTACIÓN COMPLETA
  401.  
  402. ```html
  403. <!DOCTYPE html>
  404. <html lang="es">
  405. <head>
  406. <style>
  407. * {
  408. image-rendering: -moz-crisp-edges;
  409. image-rendering: -webkit-crisp-edges;
  410. image-rendering: pixelated;
  411. image-rendering: crisp-edges;
  412. }
  413.  
  414. .character {
  415. width: 128px;
  416. height: 128px;
  417. object-fit: contain;
  418. }
  419.  
  420. .building {
  421. width: 300px;
  422. height: 300px;
  423. }
  424.  
  425. .background {
  426. background: url('cesped-tile.png') repeat;
  427. background-size: 128px 128px; /* 2x del original 64px */
  428. }
  429. </style>
  430. </head>
  431. <body class="background">
  432. <picture>
  433. <source srcset="personaje-x.webp" type="image/webp">
  434. <img src="personaje-x.png"
  435. class="character"
  436. loading="lazy"
  437. alt="Personaje X">
  438. </picture>
  439. </body>
  440. </html>
  441. ```
  442.  
  443. ---
  444.  
  445. ## ✅ CHECKLIST FINAL
  446.  
  447. - [ ] Generar assets en tamaño correcto (32-256px)
  448. - [ ] Optimizar con TinyPNG
  449. - [ ] Aplicar `image-rendering: pixelated` en CSS
  450. - [ ] Implementar lazy loading
  451. - [ ] Crear sprite sheets para animaciones
  452. - [ ] Cachear assets con Service Worker
  453. - [ ] Probar en móviles reales
  454.  
  455. ---
  456.  
  457. **¿Con esto quedó claro cómo optimizar todo para que pese casi nada pero se vea increíble?** 🚀✨
Advertisement
Add Comment
Please, Sign In to add comment