Google Groups Home Help | Sign in
Resize images on demand
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 28 - Collapse all   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Michel Thadeu Sabchuk  
View profile
 More options Apr 17 2007, 2:54 pm
From: Michel Thadeu Sabchuk <miche...@gmail.com>
Date: Tue, 17 Apr 2007 18:54:20 -0000
Local: Tues, Apr 17 2007 2:54 pm
Subject: Resize images on demand
Hi guys!

I done a cool functionality to my site, the possibility to resize
images on demand. It's not 100% done  yet but my goal is to do
something like:

...
class Article(models.Model):
    photo = models.ImageField(upload_to='some/path/some/where')
    def get_photo_200x200(self):
       return self.get_photo_miniature(200, 200)
...

The method self.get_photo_miniature will work like get_photo_url, but
it receives the limits of the image miniature, this method check if
there is a file called some/path/some/where/photo_200x200.jpg
(supposing the image filename is photo.jpg). If this file exists,
returns the proper url to it, if not, it resizes the image and store
on this file to then return the miniature url.

I need PIL to this work, but it works a pretty way. The above is
working for me, but the custom method get_photo_miniature is defined
on my model. I want to know if this is a useful feature, then I can
dig up where to put this to make it generic.

Now that I done, I think I can do it another way, maybe using filters.
As images generally goes in templates, I can do something like:

...
<img src="{{ object.image|thumbnail:"200x200" }}">
...

I think you catch the idea. What do you think?
I sent a post about the problem of the filename being unique, I don't
bother about this anymore, I see that if I put 2 files with same name,
the files start to append a _ on the filename. But I still think the
upload_to keyword could receive id.

Thanks for all help, sorry if I was meaningless.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Kaplan-Moss  
View profile
 More options Apr 17 2007, 2:56 pm
From: "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
Date: Tue, 17 Apr 2007 13:56:15 -0500
Local: Tues, Apr 17 2007 2:56 pm
Subject: Re: Resize images on demand
Hey Michel --

Please direct questions of this nature to django-users; django-dev is
used to discuss the development of Django itself, not to answer usage
questions.

Thanks!

Jacob


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michel Thadeu Sabchuk  
View profile
 More options Apr 18 2007, 12:02 pm
From: Michel Thadeu Sabchuk <miche...@gmail.com>
Date: Wed, 18 Apr 2007 16:02:35 -0000
Local: Wed, Apr 18 2007 12:02 pm
Subject: Re: Resize images on demand
Hi

Ok, sorry about that Jacob!
Thanks for pointing me at right place!

Best Regards,


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
chris.moffitt@gmail.com  
View profile
 More options Apr 18 2007, 9:05 pm
From: "chris.moff...@gmail.com" <chris.moff...@gmail.com>
Date: Wed, 18 Apr 2007 18:05:19 -0700
Local: Wed, Apr 18 2007 9:05 pm
Subject: Re: Resize images on demand
Just a question out to the developers-

Would you consider adding a thumbnail capability to Django?  I know
there are contributions out there that do it and the dependency on PIL
might be a negative but I believe this is a very common use case.  How
many apps have an image field and don't use some sort of thumbnail?  I
bet very few.

Having a standard integrated in Django would be a big plus IMHO.

-Chrus


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Kaplan-Moss  
View profile
 More options Apr 18 2007, 9:28 pm
From: "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
Date: Wed, 18 Apr 2007 20:28:00 -0500
Subject: Re: Resize images on demand
On 4/18/07, chris.moff...@gmail.com <chris.moff...@gmail.com> wrote:

> Would you consider adding a thumbnail capability to Django?  I know
> there are contributions out there that do it and the dependency on PIL
> might be a negative but I believe this is a very common use case.  How
> many apps have an image field and don't use some sort of thumbnail?  I
> bet very few.

I'd be +1 on adding something as a contrib app. I've got some code we
use at work, but it'll likely be some time before I'm able to
generalize it enough for public consumption, so I'd be thrilled to see
an effort by a few committed community members...

Jacob


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michel Thadeu Sabchuk  
View profile
 More options Apr 19 2007, 9:20 am
From: Michel Thadeu Sabchuk <miche...@gmail.com>
Date: Thu, 19 Apr 2007 13:20:22 -0000
Local: Thurs, Apr 19 2007 9:20 am
Subject: Re: Resize images on demand
Hi Jacob, how are you?

> I'd be +1 on adding something as a contrib app. I've got some code we
> use at work, but it'll likely be some time before I'm able to
> generalize it enough for public consumption, so I'd be thrilled to see
> an effort by a few committed community members...

I done some code to implement it. Look at the following snippet:
http://www.djangosnippets.org/snippets/192/

I used filters to implement this task, did you like the filter
approach or do you think to have a method like
object.get_image_thumbnail on the model is better? I must confess that
use filter was easier to implement and it's easier to use too, I don't
realize how to specify the limits of the image once I can't send
parameters to the get_image_thumbnail method:

Now the questions (not about usage but about directioning :P):

1) What could be the name of the contrib package? Could it be in
webdesign?
2) What is the better approach? Do a filter or a custom method on the
model?
3) Should I create a ticket?

Best regards!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michel Thadeu Sabchuk  
View profile
 More options Apr 19 2007, 9:38 am
From: Michel Thadeu Sabchuk <miche...@gmail.com>
Date: Thu, 19 Apr 2007 13:38:22 -0000
Local: Thurs, Apr 19 2007 9:38 am
Subject: Re: Resize images on demand
Hi guys,

On the user list I found a more complete solution:
http://code.google.com/p/django-utils/wiki/Thumbnail

Maybe this could be add as a contrib package?
Best regards!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brett Parker  
View profile
 More options Apr 19 2007, 10:32 am
From: Brett Parker <iDu...@sommitrealweird.co.uk>
Date: Thu, 19 Apr 2007 15:32:38 +0100
Local: Thurs, Apr 19 2007 10:32 am
Subject: Re: Resize images on demand

On Wed, Apr 18, 2007 at 08:28:00PM -0500, Jacob Kaplan-Moss <jacob.kaplanm...@gmail.com> wrote:

> On 4/18/07, chris.moff...@gmail.com <chris.moff...@gmail.com> wrote:
> > Would you consider adding a thumbnail capability to Django?  I know
> > there are contributions out there that do it and the dependency on PIL
> > might be a negative but I believe this is a very common use case.  How
> > many apps have an image field and don't use some sort of thumbnail?  I
> > bet very few.

> I'd be +1 on adding something as a contrib app. I've got some code we
> use at work, but it'll likely be some time before I'm able to
> generalize it enough for public consumption, so I'd be thrilled to see
> an effort by a few committed community members...

I've got a chunk of code that's reasonably generic but needs some
tidying up and decoupling... it's just a template tag... can be found:

http://arch.sommitrealweird.co.uk/viewarch/iDu...@sommitrealweird.co.uk--websites/alug--mainline--0.1--patch-32/alug/general /helpers.py

for the main code and:

http://arch.sommitrealweird.co.uk/viewarch/iDu...@sommitrealweird.co.uk--websites/alug--mainline--0.1--patch-32/alug/general /templatetags/thumbnail.py

there for the actual template tag.

It saves the thumbnail to the filesystem when it needs to regenerate it,
and so should even be reasonably fast after the first access.

Thanks,
Brett Parker.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
chris.moffitt@gmail.com  
View profile
 More options Apr 20 2007, 11:42 am
From: "chris.moff...@gmail.com" <chris.moff...@gmail.com>
Date: Fri, 20 Apr 2007 08:42:25 -0700
Local: Fri, Apr 20 2007 11:42 am
Subject: Re: Resize images on demand
I've started a page to discuss the different options here.

http://code.djangoproject.com/wiki/ThumbNails

-Chris


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SmileyChris  
View profile
 More options Apr 22 2007, 5:41 am
From: SmileyChris <smileych...@gmail.com>
Date: Sun, 22 Apr 2007 09:41:20 -0000
Local: Sun, Apr 22 2007 5:41 am
Subject: Re: Resize images on demand
I put together my take on django.contib.thumbnails and posted it as a
patch
http://code.djangoproject.com/ticket/4115

Please read through the documentation and give some feedback.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
chris.moffitt@gmail.com  
View profile
 More options Apr 22 2007, 5:25 pm
From: "chris.moff...@gmail.com" <chris.moff...@gmail.com>
Date: Sun, 22 Apr 2007 14:25:06 -0700
Local: Sun, Apr 22 2007 5:25 pm
Subject: Re: Resize images on demand
This is a really great patch.  I read the patch but have not attempted
to use yet.  Here are a couple of thoughts:
- I think the patch file itself may be a little messed up.  I see that
several of the files are repeated.  I could just be reading it wrong.
- Big positive in that you documented it so well!
- I like the fact that it's simple to create your own thumbnail
classes if necessary.
- Squash, crop and thumbnail are all very useful and I think it's
great to have all these available.
- This syntax looks just fine:
<img src="{{ object.imagefield|thumbnail:"150x100" }}" />

However, this feels a little bit clunky:
{% with object.imagefield|thumbnail:"150x100" as thumb %}
 <img src="{{ thumb.url }}" width="{{ thumb.thumbnail.size.0 }}"
height="{{ thumb.size.1 }}" />
 {% endwith %}

What if we had a shortcut like this:
{{ object.imagefield|thumbnail_full_tag:"150X100" }}

Which would generate:
<img src="source/file" width="150" height="100" />

- Also, one thing that is nice in Nesh's version is that it is easy to
cache thumbnails in memory. I think this would be a nice & fairly
simple thing to add.

Once again, really nice work.  I look forward to seeing this in
Django.  I think it would be really really useful.

-Chris


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SmileyChris  
View profile
 More options Apr 22 2007, 5:35 pm
From: SmileyChris <smileych...@gmail.com>
Date: Sun, 22 Apr 2007 21:35:33 -0000
Local: Sun, Apr 22 2007 5:35 pm
Subject: Re: Resize images on demand
On Apr 23, 9:25 am, "chris.moff...@gmail.com"
<chris.moff...@gmail.com> wrote:
> This is a really great patch.  I read the patch but have not attempted
> to use yet.  Here are a couple of thoughts:
> - I think the patch file itself may be a little messed up.  I see that
> several of the files are repeated.  I could just be reading it wrong.

Probably is messed up. I use tortoiseSVN and have noticed that it
seems to mess up added files like that.

> - Big positive in that you documented it so well!

This is usually the way to a submitter's heart. ;)

> - I like the fact that it's simple to create your own thumbnail
> classes if necessary.
> - Squash, crop and thumbnail are all very useful and I think it's
> great to have all these available.

I made crop recently for another project - squash isn't quite so nice
but people may want it ;)

> - This syntax looks just fine:
> <img src="{{ object.imagefield|thumbnail:"150x100" }}" />

> However, this feels a little bit clunky:
> {% with object.imagefield|thumbnail:"150x100" as thumb %}
>  <img src="{{ thumb.url }}" width="{{ thumb.thumbnail.size.0 }}"
> height="{{ thumb.size.1 }}" />
>  {% endwith %}

> What if we had a shortcut like this:
> {{ object.imagefield|thumbnail_full_tag:"150X100" }}

I felt a bit hesitant to even add that to documentation - it was more
to show you can access the attributes of the thumbnail object (it's
probably superfluous).
Perhaps it would be better just provide an thumbnail_tag filter to
handle it.
I'd suggest a separate tag to handle it:
{{ object.imagefield|thumbnail_crop:"150X100"|thumbnail_tag }}

> - Also, one thing that is nice in Nesh's version is that it is easy to
> cache thumbnails in memory. I think this would be a nice & fairly
> simple thing to add.

I thought about this, started implementing it and then scrapped the
idea. IMO this is getting in to serving of static files, which
historically Django has tried to steer very clear of.
It wouldn't be difficult to do if it was deemed important enough.

> Once again, really nice work.  I look forward to seeing this in
> Django.  I think it would be really really useful.

Thanks for the feedback, greatly appreciated. Anyone else (especially
real testing)?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
chris.moffitt@gmail.com  
View profile
 More options Apr 22 2007, 10:08 pm
From: "chris.moff...@gmail.com" <chris.moff...@gmail.com>
Date: Sun, 22 Apr 2007 19:08:30 -0700
Local: Sun, Apr 22 2007 10:08 pm
Subject: Re: Resize images on demand