0

Suppose, I have 20 images of size 1600 X 900 in a page. How do I load the images in the size that I specify on a template? In the css I can do it. But I want to change the actual size of the image, so that when clicked on the particular image, it will load the original image with its original size. Is there any way that I can do it? I tried using easy_thumbnails and it was great, until it gave me problems when I deployed it using the apache server. Any help will be deeply appreciated. Thank you!

EDIT:

.html:

 {% for Status in status %}
    <p class="user">{{ Status.creator.get_full_name }}</p>
    {% if Status.image %}
        <div class="image_image">
            <center>
                <img src="{{ MEDIA_URL }}{{Status.image}}" width=300px />
            </center>
        </div>
        <p class="status_image">{{Status}}</p>
        <span class="clear"></span>
        <hr>
    {% else %}
        <p class="status_status">{{Status}}</p>
        <span class="clear_right"></span>
        <hr>
    {% endif %}
{% endfor %}
Community
  • 1
  • 1
Robin
  • 5,366
  • 17
  • 57
  • 87

1 Answers1

0

Try to use sorl thumbnail, it even supports Amazon S3 Server.

pip install sorl-thumbnail

To Installed apps: 'sorl.thumbnail',

add {% load thumbnail %} to your template.

{% thumbnail firma.firma_logo "130x110" format="PNG" as im %}
        <div class="logo" style="background-image:url('{{ im.url }}')"></div>
{% endthumbnail %}

The make image format PNG is important, it converts into JPEG by the default. And if the user uploads file in transparent format, it sucks.

cem
  • 1,535
  • 19
  • 25
  • You should also install image formats, it is such in ubuntu: sudo apt-get install libwebp4 libwebp4-dev libfreetype6 libfreetype6-dev libjpeg8 libjpeg8-dev liblcms1 liblcms1-dev libwebp4 libwebp4-dev – cem Sep 09 '13 at 18:11
  • Thanks! By the way can't I use PIL? And do I have to specify `{% empty %}` in the template? – Robin Sep 09 '13 at 18:31
  • You don't have to use empty, and even you use pil, you can need to install those libraries. And I can't remember why but I had to install Pillow instead of PIL. – cem Sep 09 '13 at 18:33
  • Ok. But I really got confused with its tags. Can you please check my html and correct me how to place those tags??? I have edited and have added. – Robin Sep 09 '13 at 18:38
  • {% thumbnail Status.image "300x110" format="PNG" as im %} {% endthumbnail %} – cem Sep 09 '13 at 18:47
  • Thanks it worked! But again, its acting as it did with easy_thumbnails when I use the apache server? Is anything wrong with apache and these??? – Robin Sep 09 '13 at 19:00
  • I have never tried django in apache server (i use nginx) and i never had a such problem, and i don't think i can check the apache settings. What is the url of resized image? – cem Sep 09 '13 at 19:05
  • Its blank!!!
    But others are something like this:
    Only when I run it through django's inbuilt server it loads the uploaded images again. I think it does not process the sorl.thumbnail with apache... Any thoughts please..?
    – Robin Sep 09 '13 at 19:24
  • Or do I have to specify it in the models too? – Robin Sep 09 '13 at 19:36
  • from sorl.thumbnail import ImageField Image = ImageField(upload_to='img', verbose_name=_(u"Image"), null=True, blank=True) – cem Sep 10 '13 at 08:18
  • I tried it implementing in the models.py too, but with no luck. It does not load the uploaded image by the apache, until I load the page with django's inbuilt server. Have you tried it using for the users uploaded media? – Robin Sep 10 '13 at 11:54
  • I will post another question, can you please answer there how to integrate apache and nginx together? Or only nginx will also help. I am a windows guy, so its hard to find the solution for integrating them. Thank you once again. – Robin Sep 10 '13 at 13:39
  • For every single thing to do, there seems to be an app in django, inspite of it advertising itself as all the bells and whistles. – Gajendra D Ambi Oct 07 '22 at 18:22