0

How can I resize image when I upload with ImageField by protecting aspect ratio of image.

Example: (Width x Height) from 1100x600 to 550x300

And, is it possible with [ImageKit] ? https://github.com/matthewwithanm/django-imagekit

Efraim
  • 43
  • 6

1 Answers1

0

You can use easy-thumbnails package for optimizing images. Just follow these steps:

  1. First install easy-thumbnails package using command:

    pip install easy-thumbnails
    
  2. Go to settings.py file and add easy_thumbnails to the INSTALLED_APPS setting as like:

    INSTALLED_APPS = [
         # ...
         'easy_thumbnails',
    ]
    
  3. Run this command to apply changes in database

    python manage.py migrate
    
  4. Now go to your template and replace the line(as I supposed):

    <img src="{{ image.image.url }}">
    

    To the following lines:

    {% load thumbnail %}
    
    <img src="{% thumbnail image.image 550x300 %}"