List Info

Thread: Thumbnail images




Thumbnail images
user name
2006-11-20 21:51:15
OK, I'm getting fed up with trying to get nesh.thumbnails to
work. It
just fails me, with no error or anything to go on, so any
attempts to
troubleshoot are shots in the dark (see
http://groups.google.com/group/django-users/brow
se_thread/thread/9d17496819e1420f/b969d1d6c644e02d?lnk=raot#
b969d1d6c644e02d)

So, to get to the heart of the matter... can anyone help me
out with
generating some thumbnail images?

To be precise, I want to ensure that when a user uploads an
image, say
an avatar, that it's size does not exceed x. The ability to
store a
copy of the original and the revised would be nice, but is
not
absolutely necessary.

Thanks.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-20 22:06:13
> So, to get to the heart of the matter... can anyone
help me out with
> generating some thumbnail images?

Try installing PIL. Then, to make life easier for you, here
is a recent
function I wrote which is passed a model and a file's
contents from the
request.
IMAGE and IMAGE_FULL are tuples, image must be at least
IMAGE size in
both x and y. It's a starting point for you, anyway.

from PIL import Image
def create(profile, image):
    # Check image
    try:
        im = Image.open(StringIO(image))
    except IOError:
        raise ImageException('Unrecognised image format.')
    # Check dimensions
    x, y = im.size
    if x < IMAGE[0] or y < IMAGE[1]:
        raise ImageException('Image too small.')
    # Delete old images first
    delete(profile)
    # See if it's big enough for a full image (and save it).
    image, image_full = image_paths(profile.id)
    if x >= IMAGE_FULL[0] and y >= IMAGE_FULL[1]:
        im.thumbnail(IMAGE_FULL, Image.ANTIALIAS)
        im.save(image_full)
        profile.photo_full = True
    # Save image
    im.thumbnail(IMAGE, Image.ANTIALIAS)
    im.save(image)
    profile.photo = True


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-20 22:55:04
I have PIL installed, but I wonder if that's the problem I'm
having
with the nesh.thumbnails (not finding it).

In your function above, how does it know the size to make
the thumbnail?


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-21 00:33:26


On Nov 21, 11:55 am, "bax...gretschpages.com"
<mail.bax...gmail.com>
wrote:
> I have PIL installed, but I wonder if that's the
problem I'm having
> with the nesh.thumbnails (not finding it).
Can you import from the manage.py shell?

>
> In your function above, how does it know the size to
make the thumbnail?
"IMAGE and IMAGE_FULL are tuples"


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-21 06:07:27
When I'm developing and dont know what thumbnail size I'm
going to
use, I have a filter:

from django import template
from django.template import TemplateSyntaxError
from PIL import Image
from blog import settings
register = template.Library()

def thumbnail(url, given_size):
    try:
        im = Image.open(settings.MY_MEDIA + '/' + url)
        tab_size = given_size.split("x")
        size = int(tab_size[0]), int(tab_size[1])

        if len(url.split(".JPG")) == 1:
            thumb_url = url.split(".jpg")
        else:
            thumb_url = url.split(".JPG")

        thumb_url = thumb_url[0] + '_thumb_' + str(size[0])
+ 'x' +
str(size[1]) + '_.jpg'
        try:
            im_thumb = Image.open(settings.MY_MEDIA + '/' +
thumb_url)
            return thumb_url

        except IOError:
            #make a thumb
            im.thumbnail(size)
            im.save(settings.MY_MEDIA + '/' +thumb_url,
'JPEG')
            return thumb_url

    except IOError:
        return url

register.filter('thumbnail', thumbnail)

Its thumbnail.py file in templatetags dir.

I'm useing it like this in my templates:
{% load thumbnail %}
<a href="/site_media/upload/{{
p.filename|thumbnail:"600x600" }}">
<img src="/site_media/upload/{{
p.filename|thumbnail:"300x300" }}" />
</a>

I can change size of thumbnail inside template.

2006/11/21, SmileyChris <smileychrisgmail.com>:
>
>
>
> On Nov 21, 11:55 am, "bax...gretschpages.com"
<mail.bax...gmail.com>
> wrote:
> > I have PIL installed, but I wonder if that's the
problem I'm having
> > with the nesh.thumbnails (not finding it).
> Can you import from the manage.py shell?
>
> >
> > In your function above, how does it know the size
to make the thumbnail?
> "IMAGE and IMAGE_FULL are tuples"
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-21 14:24:43
Try http://trac
.studioquattro.biz/djangoutils 
its nice and very easy.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-21 18:18:15
Thanks guys.

comechao, that's what I started out with, and it wouldn't
work.

SmileyChris, saying they're tuples doesn't help me, as I
don't really
understand what you mean by that, or where they're set.

At any rate, I eventually figured out the nesh.thumbnails
couldn't find
my PIL install. So I've got that working, and I'll see how
it goes from
here.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-21 22:53:56
> SmileyChris, saying they're tuples doesn't help me, as
I don't really
> understand what you mean by that, or where they're set.
They're just set at the top of that .py file. For example:
IMAGE = (100, 100)
FULL_IMAGE = (500, 800)

>
> At any rate, I eventually figured out the
nesh.thumbnails couldn't find
> my PIL install. So I've got that working, and I'll see
how it goes from
> here.
Cool, it sounds like you are making progress then!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-21 22:59:51
I am... I got the avatars sorted out, now if I could just
figure out
why my (other) form won't upload the images!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Thumbnail images
user name
2006-11-22 15:13:22
Ok, try put PIL in your path. Like
/usr/lib/python2.4/site-packages/Image or something like
that (i'm on
windows at work right now : ).


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

[1-10] [11]

about | contact  Other archives ( Real Estate discussion Medical topics )