|
| 1 | +--- |
| 2 | +id: Image-Formats-And-Optimisation |
| 3 | +title: Image Formats And Optimisation |
| 4 | +sidebar_label: Image Formats And Optimisation |
| 5 | +sidebar_position: 2 |
| 6 | +tags: [html, Img] |
| 7 | +--- |
| 8 | + |
| 9 | +# Optimisation |
| 10 | +Optimizing images for the web is crucial for improving website performance and user experience. By choosing the appropriate image format and applying optimization techniques, you can minimize file sizes without compromising image quality. |
| 11 | + |
| 12 | +When optimizing images for use on an HTML webpage, it's essential to consider the format and optimization techniques to ensure fast loading times and good user experience. |
| 13 | + |
| 14 | +### 1. JPEG (Joint Photographic Experts Group): |
| 15 | +- **Description**: Ideal for photographs and images with gradients. |
| 16 | +- **Optimization Techniques**: |
| 17 | + - Adjust compression levels: Balance image quality and file size by adjusting the compression level. |
| 18 | + - Optimize dimensions: Resize images to the actual size they will be displayed on the webpage. |
| 19 | + - Remove unnecessary metadata: Strip EXIF data and other metadata to reduce file size. |
| 20 | + - Use progressive encoding: Load images gradually for faster perceived performance. |
| 21 | + |
| 22 | +```html |
| 23 | +<img src="photo.jpg" alt="Description" width="800" height="600"> |
| 24 | +``` |
| 25 | + |
| 26 | +### 2. PNG (Portable Network Graphics): |
| 27 | +- **Description**: Suitable for images with transparency and sharp lines. |
| 28 | +- **Optimization Techniques**: |
| 29 | + - Use PNG-8 for simple graphics: PNG-8 supports up to 256 colors and is suitable for images with limited colors. |
| 30 | + - Optimize transparency: Use alpha transparency only where needed to minimize file size. |
| 31 | + - Compress PNG-24: Compress PNG-24 images to reduce file size while maintaining quality. |
| 32 | + |
| 33 | +```html |
| 34 | +<img src="logo.png" alt="Description" width="200" height="100"> |
| 35 | +``` |
| 36 | + |
| 37 | +### 3. GIF (Graphics Interchange Format): |
| 38 | +- **Description**: Suitable for simple animations and images with limited colors. |
| 39 | +- **Optimization Techniques**: |
| 40 | + - Limit color palette: Reduce the number of colors used in the image to minimize file size. |
| 41 | + - Optimize animations: Limit the number of frames and optimize frame duration for GIF animations. |
| 42 | + |
| 43 | +```html |
| 44 | +<img src="animation.gif" alt="Description" width="300" height="200"> |
| 45 | +``` |
| 46 | + |
| 47 | +### 4. WebP: |
| 48 | +- **Description**: Modern image format offering both lossy and lossless compression. |
| 49 | +- **Optimization Techniques**: |
| 50 | + - Convert JPEG/PNG to WebP: Convert existing images to WebP format for better compression and smaller file sizes. |
| 51 | + - Serve WebP images conditionally: Detect browser support for WebP and serve WebP images to compatible browsers. |
| 52 | + |
| 53 | +```html |
| 54 | +<picture> |
| 55 | + <source srcset="image.webp" type="image/webp"> |
| 56 | + <source srcset="image.jpg" type="image/jpeg"> |
| 57 | + <img src="image.jpg" alt="Description" width="400" height="300"> |
| 58 | +</picture> |
| 59 | +``` |
| 60 | + |
| 61 | +By implementing these optimization techniques and choosing the appropriate image format, you can enhance the performance and user experience of your HTML webpages. |
0 commit comments