Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maintain Image Quality When Applying CSS Transform & Scale
The CSS image-rendering property helps us set an algorithm for scaling our image. The images sometimes look blurry when the transform & scale is applied. To improve the image, use the CSS image-rendering property. Let us see how to maintain the image quality.
Syntax
The syntax of CSS image-rendering property is as follows −
Selector {
image-rendering: /*value*/
}
Above, the value can be −
auto − This is the default and the web browser choose the scaling algorithm automatically
smooth − Smooths out the color in your image.
high-quality − Provides higher-quality scaling
crisp-edges − Preserve the contrast and edges in your image
pixelated − The nearest-neighbor algorithm is considered if the image is scaled up.
The following examples illustrate CSS image-rendering property.
Example
In this example, we are trying to enhance the quality of an image using the smooth, pixelated, and crisp-edges values of the image-rendering properties −
#one {
image-rendering: smooth;
}
#two {
image-rendering: pixelated;
}
#three {
image-rendering: crisp-edges;
}
Let us see the example −
<!DOCTYPE html>
<html>
<head>
<style>
img {
height: 200px;
width: 200px;
}
#one {
image-rendering: smooth;
}
#two {
image-rendering: pixelated;
}
#three {
image-rendering: crisp-edges;
}
</style>
</head>
<body>
<img id="one" src="https://images.unsplash.com/photo-1610208309350-766d71494a03?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=128&ixlib=rb-1.2.1&q=80&w=128" />
<img id="two" src="https://images.unsplash.com/photo-1610208309350-766d71494a03?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=128&ixlib=rb-1.2.1&q=80&w=128" />
<img id="three" src="https://images.unsplash.com/photo-1610208309350-766d71494a03?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=128&ixlib=rb-1.2.1&q=80&w=128" />
</body>
</html>
Example
In this example, we are trying to enhance the quality of an image using the smooth, pixelated, crisp-edges, and high-quality values of the image-rendering properties −
#one {
image-rendering: pixelated;
}
#two {
image-rendering: smooth;
}
#three {
image-rendering: crisp-edges;
}
#three {
image-rendering: high-quality;
}
Let us see the example −
<!DOCTYPE html>
<html>
<head>
<style>
img {
padding: 5%;
border-radius: 40%;
height: 20%;
width: 20%;
}
#one {
image-rendering: pixelated;
}
#two {
image-rendering: smooth;
}
#three {
image-rendering: crisp-edges;
}
#three {
image-rendering: high-quality;
}
</style>
</head>
<body>
<img id="one" src="https://www.tutorialspoint.com/assets/profiles/123055/profile/200_187394-1565938756.jpg" />
<img id="two" src="https://www.tutorialspoint.com/assets/profiles/123055/profile/200_187394-1565938756.jpg" />
<img id="three" src="https://www.tutorialspoint.com/assets/profiles/123055/profile/200_187394-1565938756.jpg" />
<br/>
pixelated, smooth, crisp, high quality
</body>
</html>