ใช้ CSS filter property ใส่เอฟเฟกต์ต่างๆ ให้รูปภาพ เช่น Invert, Blur, Sepia, Brightness, Contrast ได้ทันที
ตัวอย่างโค้ด (Invert)
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> img{ margin: 20px; } img.normal{ margin-left: 30%; width: 300px; height: 300px; } img.filter { width: 300px; height: 300px; filter: invert(100%); } </style> </head> <body> <h1 style="text-align: center;">CSS Image effects example</h1> <img class="normal" src="https://i.picsum.photos/id/237/536/354.jpg"> <img class="filter" src="https://images.pexels.com/photos/237/536/354.jpg"> </body> </html>
CSS Filter Functions พื้นฐาน
| Function | คำอธิบาย | ค่า |
|---|---|---|
grayscale() | ขาวดำ | 0% - 100% |
sepia() | สีน้ำชา/โบราณ | 0% - 100% |
blur() | เบลอ | px (เช่น 5px) |
brightness() | ความสว่าง | 0% - 200%+ |
contrast() | คอนทราสต์ | 0% - 200%+ |
invert() | เนกะทีฟสี | 0% - 100% |
saturate() | ความอิ่มตัวสี | 0% - 500%+ |
hue-rotate() | หมุนสี (Hue) | deg (เช่น 90deg) |
opacity() | ความทึบ | 0% - 100% |
drop-shadow() | เงา (รองรับ Alpha) | x y blur color |