Thumbnails in RichText fields (issue #816)

42 views
Skip to first unread message

Ahmad Khayyat

unread,
Jun 2, 2014, 7:10:38 PM6/2/14
to mezzani...@googlegroups.com

I was wondering about what happened to issue #816: “add image resizing feature to media library”.

It is closed, but I can’t tell whether it has been implemented, and if not, why has it been closed.

Stephen McDonald

unread,
Jun 2, 2014, 8:00:22 PM6/2/14
to mezzani...@googlegroups.com
Looks like it's a dupe of https://github.com/stephenmcd/mezzanine/issues/567 which is open.


On Tue, Jun 3, 2014 at 9:10 AM, Ahmad Khayyat <akha...@gmail.com> wrote:

I was wondering about what happened to issue #816: “add image resizing feature to media library”.

It is closed, but I can’t tell whether it has been implemented, and if not, why has it been closed.

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephen McDonald
http://jupo.org

Stephen McDonald

unread,
Jun 2, 2014, 8:24:49 PM6/2/14
to mezzani...@googlegroups.com
Sorry I jumped the gun a little there. It's not really a dupe. 

Grappelli originally had image resizing built in and I removed it. I feel like having content managers responsible for maintaining a pool of image sizes isn't work they should have to do and that it's something that should be managed at the template level by the programmer.

Ahmad Khayyat

unread,
Jun 2, 2014, 9:14:12 PM6/2/14
to mezzani...@googlegroups.com, st...@jupo.org
I agree.. I'm glad the media library does not allow resizing. I was actually looking for the feature discussed in #567, or more specifically, generate the thumbnails using some default size without the author having to specify one (not even in the WYSIWYG editor). The size should be specified by the designer, and set by the developer. I guess we're not there yet.

Thanks for the clarification.

Ahmad Khayyat

unread,
Jun 3, 2014, 1:13:47 AM6/3/14
to mezzani...@googlegroups.com, st...@jupo.org
Now that `RICHTEXT_FILTERS` is plural, perhaps this is simply a matter of shipping a filter in Mezzanine that calls `mezzanine.core.templatetags.mezzanine_tags.thumbnail`, or at least documenting this procedure. The thumbnail size (and any other parameters accepted by `thumbnail`) can be set in a custom filter or as settings.

Stephen McDonald

unread,
Jun 3, 2014, 3:25:43 AM6/3/14
to mezzani...@googlegroups.com
That would be clean but I'm worried about performance. I can't see any other way of making this working without introducing lxml or BeautifulSoup - either of those will parse the HTML, replacing img src attributes with results from the thumbnail template tag (btw I imagined width/height would simply be extracted from the img tags too).

As I understand lxml is much better from a performance perspective, and if we were using it then perhaps parsing HTML on every request would be OK. But it isn't a pure Python lib, and I fear introducing installation headaches if we include it as a dependency. Believe me, it will break for someone somewhere, and we have to support that. Alternatively we can introduce pure-Python BeautifulSoup as the dependency, but it's much slower and so it'd make more sense for the thumbnail replacement to occur on save of the model, rather than on the fly in templates.










On Tue, Jun 3, 2014 at 3:13 PM, Ahmad Khayyat <akha...@gmail.com> wrote:
Now that `RICHTEXT_FILTERS` is plural, perhaps this is simply a matter of shipping a filter in Mezzanine that calls `mezzanine.core.templatetags.mezzanine_tags.thumbnail`, or at least documenting this procedure. The thumbnail size (and any other parameters accepted by `thumbnail`) can be set in a custom filter or as settings.

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen McDonald

unread,
Jun 3, 2014, 3:48:00 AM6/3/14
to mezzani...@googlegroups.com
Another option I'd consider - using Python's built-in HTMLParser class to do the work. This would remove the need for any dependencies. The only problem is that it will choke on bad HTML. In that case I think we can just handle an exception, and not perform thumbnail generation - TinyMCE and others should produce valid HTML. Again this would fall under the "slow" camp that would need to occur on save.

Stephen McDonald

unread,
Jun 3, 2014, 3:58:00 AM6/3/14
to mezzani...@googlegroups.com
Actually I've just realised that for this to work correctly, it would need to happen on the fly and not on save - if we do replacement on save and store the thumbnail path directly in the HTML before saving, further resizing of the image would be very awkward - the thumbnail itself would be resized rather than the original image.

So, let's forget performance - in production these things should be cached anyway. Perhaps we can also move the bleach/clean phase to a richtext filter as well. That would mean the original HTML source would always be stored in the DB and only cleaned on output, so the developer could modify the filtering level etc to restore any HTML that had been saved and cleaned already.




Ahmad Khayyat

unread,
Jun 3, 2014, 8:18:56 AM6/3/14
to mezzani...@googlegroups.com
Wouldn't a simple regular expression work here?

Stephen McDonald

unread,
Jun 3, 2014, 5:56:24 PM6/3/14
to mezzani...@googlegroups.com
That'd be awesome if possible. My understanding is you'll hit an edge case eventually where regex won't be capable of parsing what you want. Perhaps what we're doing is simple enough to work with regex. There's a hilariously famous stackoverflow answer on this: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags


On Tue, Jun 3, 2014 at 10:18 PM, Ahmad Khayyat <akha...@gmail.com> wrote:
Wouldn't a simple regular expression work here?

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen McDonald

unread,
Jun 3, 2014, 5:59:27 PM6/3/14
to mezzani...@googlegroups.com
Although we do want to extract width and height too, so I suspect regex won't be the right approach.

I've also realised HTMLParser is probably insufficient without a lot of work, since we want to modify HTML, not simply parse it.

Seems like the final result might be using BeautifulSoup with a definition in the RICHTEXT_FILTERS setting.

Stephen McDonald

unread,
Jun 4, 2014, 12:19:19 AM6/4/14
to mezzani...@googlegroups.com
Good news, I've got this working using html5lib which is an implicit dependency of Mezzanine's already.

Will push soon.

Ahmad Khayyat

unread,
Jun 4, 2014, 7:39:16 AM6/4/14
to mezzani...@googlegroups.com
Great! Thanks Steve.


You received this message because you are subscribed to a topic in the Google Groups "Mezzanine Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mezzanine-users/dIfRc26LJbY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mezzanine-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages