django-imagekit
django-imagekit copied to clipboard
how to blur a Image?
### my model field :
image = ProcessedImageField(
processors=[ResizeToFit(1200)],
format='WEBP',
options={'quality': 10})
i want to blur a image and then save it to database
You can use GaussianBlur
: https://github.com/matthewwithanm/pilkit/blob/2a9ad303e9eea7be33be7f046020d79b918383a4/pilkit/processors/filter.py#L3
@julianwachholz the module seems to not be available
@ericel the latest version on PyPI is from 2017 unfortunately. It means you'll have to install the package from source.
@vstoykov Do you have permissions to push pilkit updates?
- First you have to create a Django model to represent the image you want to store in the database.
For example:
from django.db import models
from imagekit.models import ProcessedImageField
from imagekit.processors import Blur
class BlurredImage(models.Model):
image = ProcessedImageField(upload_to='images/',
processors=[Blur(radius=5)],
format='JPEG',
options={'quality': 90})
- Then apply these changes by running these commands in terminal:
python manage.py makemigrations
python manage.py migrate
- Now upload your image via a form that you already have created to store the image into your database take the image from the form and process it for blurring the image:
def upload_image(request):
if request.method == 'POST':
form = ImageUploadForm(request.POST, request.FILES)
if form.is_valid():
blurred_image = BlurredImage()
blurred_image.image = form.cleaned_data['image']
blurred_image.save()
# Additional logic or redirect
else:
form = ImageUploadForm()
return render(request, 'upload_image.html', {'form': form})
This code should be provided in views.py file
New version of pilkit
is released with the GaussianBlur
processor as suggested by @julianwachholz if you update pilkit
you will be able to blur images.