Django 项目的用户定义缩略图?
我正在建立一个大量使用图像的网站。这些图像需要以不同的尺寸进行缩略图以适应不同的模板。
我知道像 sorl-thumbnail 这样的解决方案,它在各方面似乎都很完美,除了一个:如果计算机的选择不好,我需要能够覆盖自动调整大小和裁剪。
例如:假设我上传一张 1,000 x 1,000 像素的图像。我需要该图像的 300 x 200 缩略图。如果我理解正确的话,sorl-thumbnail 解决方案是将图像重新缩放到 300×300,然后剪掉顶部和底部。
我想要做的是a)接受sorl风格的解决方案,如果它适用于图像,但是b)能够覆盖sorl选择 - 在管理员中,可能 - 如果这会更好。例如,如果这是一个人的照片,也许我宁愿剪掉这个人的躯干,只从她的脸上制作一个缩略图,而这个缩略图恰好位于右上角?
据我所知,没有现成的可插入解决方案(但如果我错了,请纠正我)。除此之外,我想听听您对解决该问题的方法的想法。有没有某种 jQuery 插件可以帮助我实现目标?
帮助!
I'm putting together a Web site that makes heavy use of images. Those images need to be thumbnailed at various sizes to fit different templates.
I'm aware of solutions like sorl-thumbnail, which seems perfect in every way except one: I need to be able to override automatic resizing and cropping if the computer's choice is a bad one.
For instance: Say I upload a 1,000-by-1,000 pixel image. I need a 300-by-200 thumbnail of that image. The sorl-thumbnail solution, if I understand it right, is to rescale the image to 300-by-300 and then lop off the top and the bottom.
What I want to be able to do is a) accept the sorl-style solution if it works for the image, but b) be able to override the sorl choice -- in the admin, probably -- if that would work better. If it's a picture of a person, for example, maybe I would rather crop out the person's torso and just make a thumbnail out of her face, which happens to be located in the upper right corner?
There's no off-the-shelf pluggable solution for this, so far as I can tell (but please correct me if I'm wrong). Barring that, I'd like to hear your ideas about ways that the problem might be approached. Is there some sort of jQuery plugin that will get me halfway there?
Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想使用现成的可插拔插件,可以使用
django-photologue< /a>django-imagehandler。它允许您生成缩略图并在管理员上进行“手动裁剪”。另一个现成的解决方案是 django-thumbs。 django-thumbs 会覆盖您的图像字段。唯一的缺点是您需要设置生成缩略图的尺寸。
这两个应用程序都不能完全解决您的问题。但至少你知道从哪里开始:)
django-photologue 可以生成缩略图并添加效果和水印。
编辑:如果您想使用 jQuery 裁剪图像,那么您可以查看 jCrop。它非常容易使用。主要问题是您需要将图像上传到服务器,然后手动裁剪。
编辑2:信息错误。它不是 django-photologue,而是 django-imagehandler。
If you want to use an off-the-shelf pluggable there is
django-photologuedjango-imagehandler. It allows you to generate thumbnails and do "manual-cropping" on the admin.Another off-the-shelf solution is django-thumbs. django-thumbs overwrittes your imagefields. The only drawback is that you need to set up the sizes it will generate the thumbnails.
None of these 2 applications can fully solve your problem. But atleast you know where to start :)
django-photologue can generate thumbnails and add effects and watermarks.
EDIT: if you want to use jQuery to crop your images then you can take a look at jCrop. It's pretty easy to use. The main problem is that you will need to upload the image to your server and then crop it manually.
EDIT 2:Wrong information. It was not django-photologue but django-imagehandler.
sorl-thumbnail 具有智能裁剪功能,可以剪掉图像中熵最少的部分。您需要做的就是添加crop=“smart”。它在大多数情况下都非常有效。
否则你可以查看 django-imagehandler
sorl-thumbnail has smart cropping which will cut off the parts of the image with the least entropy. All you need to do is add crop="smart". It works really really well in most situations.
Otherwise you could check out django-imagehandler