Javascript Image Blur

| | | | | |

When you are designing a website, you may decide to add a blur effect to a certain image. For example, if you are designing a website for a cafe, you might want to blur an image so that you can place text in front of the image for the user to read.

This is where the CSS blur feature comes in. The blur feature applies a blur effect to a specified input image, which you can then use with the property "filter" to blur an image.

This tutorial will cover, for example, the basics of CSS Blur functionality and how you can use it to apply a blur effect to an image in your code. By the end of reading this tutorial, you will be an expert in using the CSS Blur feature.

CSS Filter

The CSS Filter property allows you to apply graphic effects to an element on a web page. Often the filter property is used to apply filters to images and backgrounds on a web page.

There are several filters offered by CSS. The opacity filter, for example, lets you make an element more or less visible, and the drop shadow filter lets you add a shadow under an element on a web page.

The syntax for applying a filter is as follows:

For this tutorial, we are going to focus on the CSS Blur feature, which adds a blur effect to an image.

CSS Blur

The CSS Blur Filter is a filter function that adds a blur effect to an image.

The syntax for using the blur filter is as follows:

In this syntax, "radius" refers to the radius of the blur effect that is to be applied. The higher the specified radius value, the more intense the blur added to a picture element will be. If you specify the value "0", no blur will be added to the picture element to which the style is applied.

The specified radius value can accept any length value, such as em, px, rem, and cm.

Let’s take an example to illustrate how this function works. Suppose we design a website for a local cafe. On the cafe’s homepage, they want an image of a cafe to appear. However, they want the image to appear with a blur effect with a radius of 2px. < br>

We could use the blur function and the filter property to do this. Here is the code we could use to create such an image with a blur function:

Our code returns: Click ’Image in the code editor above to see the output of our HTML / CSS code.

In our HTML file, we used an tag to add an image to our web page. This image refers to an image of a cafe. We use the "height" and "width" parameters to set the height and width of our image at 400px and 600px respectively.

In our CSS code, we use the property filter and the blur function to apply a blur effect to all tags on our web page. In this case, we are specifying a blur radius of 2px, which adds a slight blur effect to our image. As you can see above, the image of the coffee mug we’re using appears slightly blurry because we’ve used the blur effect.

Alternatively, if we wanted to specify a blur radius using some other unit of measure, we could do so by replacing "2px" with the value we want to use. So if we wanted our image to have a blur with a blur radius of 1.15 em, we could do that by overriding the "2px‚" blur radius that we specified above.


The CSS blur function allows you to create a blur for an image element on a web page. This function is used in conjunction with the filter property to apply the blur effect to an image.

This tutorial covered the basics of CSS filters and how to use the blur feature to add a blur effect to an image on a web page. blur an image like a pro !

Javascript Image Blur blur: Questions

Javascript Image Blur circle: Questions

How to do a scatter plot with empty circles in Python?

2 answers

In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks already plotted by scatter(), so as to highlight them, ideally without having to redraw the colored circles.

I tried facecolors=None, to no avail.


Answer #1

From the documentation for scatter:

Optional kwargs control the Collection properties; in particular:

        The string ‘none’ to plot faces with no outlines
        The string ‘none’ to plot unfilled outlines

Try the following:

import matplotlib.pyplot as plt 
import numpy as np 

x = np.random.randn(60) 
y = np.random.randn(60)

plt.scatter(x, y, s=80, facecolors="none", edgecolors="r")

example image

Note: For other types of plots see this post on the use of markeredgecolor and markerfacecolor.

plot a circle with pyplot

2 answers

surprisingly I didn"t find a straight-forward description on how to draw a circle with matplotlib.pyplot (please no pylab) taking as input center (x,y) and radius r. I tried some variants of this:

import matplotlib.pyplot as plt
# here must be something like circle.plot() or not?

... but still didn"t get it working.


Answer #1

You need to add it to an axes. A Circle is a subclass of an Patch, and an axes has an add_patch method. (You can also use add_artist but it"s not recommended.)

Here"s an example of doing this:

import matplotlib.pyplot as plt

circle1 = plt.Circle((0, 0), 0.2, color="r")
circle2 = plt.Circle((0.5, 0.5), 0.2, color="blue")
circle3 = plt.Circle((1, 1), 0.2, color="g", clip_on=False)

fig, ax = plt.subplots() # note we must use plt.subplots, not plt.subplot
# (or if you have an existing figure)
# fig = plt.gcf()
# ax = fig.gca()



This results in the following figure:

The first circle is at the origin, but by default clip_on is True, so the circle is clipped when ever it extends beyond the axes. The third (green) circle shows what happens when you don"t clip the Artist. It extends beyond the axes (but not beyond the figure, ie the figure size is not automatically adjusted to plot all of your artists).

The units for x, y and radius correspond to data units by default. In this case, I didn"t plot anything on my axes (fig.gca() returns the current axes), and since the limits have never been set, they defaults to an x and y range from 0 to 1.

Here"s a continuation of the example, showing how units matter:

circle1 = plt.Circle((0, 0), 2, color="r")
# now make a circle with no fill, which is good for hi-lighting key results
circle2 = plt.Circle((5, 5), 0.5, color="b", fill=False)
circle3 = plt.Circle((10, 10), 2, color="g", clip_on=False)
ax = plt.gca()
ax.cla() # clear things for fresh plot

# change default range so that new circles will work
ax.set_xlim((0, 10))
ax.set_ylim((0, 10))
# some data
ax.plot(range(11), "o", color="black")
# key data point that we are encircling
ax.plot((5), (5), "o", color="y")

which results in:

You can see how I set the fill of the 2nd circle to False, which is useful for encircling key results (like my yellow data point).


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method