matthewwithanm / django-imagekit

Automated image processing for Django. Currently v4.0
http://django-imagekit.rtfd.org/
BSD 3-Clause "New" or "Revised" License
2.26k stars 276 forks source link

how to blur a Image? #521

Closed harshjadon9 closed 10 months ago

harshjadon9 commented 3 years ago

### 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

julianwachholz commented 2 years ago

You can use GaussianBlur: https://github.com/matthewwithanm/pilkit/blob/2a9ad303e9eea7be33be7f046020d79b918383a4/pilkit/processors/filter.py#L3

ericel commented 2 years ago

@julianwachholz the module seems to not be available

julianwachholz commented 2 years ago

@ericel the latest version on PyPI is from 2017 unfortunately. It means you'll have to install the package from source.

matthewwithanm commented 2 years ago

@vstoykov Do you have permissions to push pilkit updates?

Aayush3014 commented 1 year ago
  1. 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})


2. Then apply these changes by running these commands in terminal:

> `python manage.py makemigrations`

> `python manage.py migrate`

3. 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:
```python
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

vstoykov commented 10 months ago

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.