Blurring an image via CSS?
Asked Answered
G

6

59

On many smartphones (Samsung Galaxy II being an example) when you browse through a photo gallery, its blurred copy is laid out in the background. Can this be achieved by CSS dynamically (ie. without the copy of the photo being prepared upfront saved)? Is there any kind of complex CSS image filter to blur an image?

Gritty answered 3/12, 2012 at 10:59 Comment(4)
Here you can find all your answers! [CSS3][1] is the way! (: [1]:inserthtml.com/2012/06/css-filtersNeal
Note that while this is possible with CSS3 'filter: blur(3px)' it is currently extremely expensive in terms of processing power.Radarman
My post got deleted. but here was the original link thenewcode.com/534/Cross-browser-Image-Blur-with-CSSEconomy
blur filter on MDNGracielagracile
A
44

You can use CSS3 filters. They are relatively easy to implement, though are only supported on webkit at the minute. Samsung Galaxy 2's browser should support though, as I think that's a webkit browser?

Amygdaline answered 3/12, 2012 at 11:5 Comment(1)
this works but unfortunately only with webkit. For now it seems that maybe the only approach is to blur an image with photoshop and place it as background if you want the same effect in each browser.Gadabout
L
32

With CSS3 we can easily adjust an image. But remember this does not change the image. It only displays the adjusted image.

See the following code for more details.

To make an image gray:

img {
 -webkit-filter: grayscale(100%);
}

To give a sepia look:

img {
 -webkit-filter: sepia(100%);
}

To adjust brightness:

img {
 -webkit-filter: brightness(50%);
}

To adjust contrast:

img {
 -webkit-filter: contrast(200%);
}

To Blur an image:

img {
 -webkit-filter: blur(10px);
}

You should also do it for different browser. That is include all css statements

  filter: grayscale(100%);
 -webkit-filter: grayscale(100%);
 -moz-filter: grayscale(100%);

To use multiple

 filter: blur(5px) grayscale(1);

Codepen Demo

Lightly answered 19/1, 2014 at 11:59 Comment(4)
@Raj it works. but each of these effects only work one time. I mean when I apply blur, i cannot apply brightness and vice versa. how do I use them multiple?>Shela
Just do it inline, like this: filter: blur(2px) contrast(10%) so far and so on..Cirrose
Demo link is broken.Guano
None of those are supported by IEIlluminati
F
11

This code is working for blur effect for all browsers.

filter: blur(10px);
-webkit-filter: blur(10px);
-moz-filter: blur(10px);
-o-filter: blur(10px);
-ms-filter: blur(10px);
Frottage answered 15/12, 2015 at 11:47 Comment(0)
C
2

Yes there is using the following code will allow you to apply a blurring effect to the specified image and also it will allow you to choose the amount of blurring.

img {
  -webkit-filter: blur(10px);
    filter: blur(10px);
}
Cranford answered 17/4, 2015 at 23:6 Comment(0)
O
0

CSS3 filters currently work only in webkit browsers (safari and chrome).

Olympic answered 19/1, 2014 at 13:29 Comment(1)
Link points to some other article regarding making images grayscale.Boudoir
C
0
img {
  filter: blur(var(--blur));
}
Curable answered 5/7, 2017 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.