Python 成像替代方案
我有 python 代码,只需要对照片做一些简单的事情:裁剪、调整大小和覆盖水印。我使用过 PIL,重新采样/调整大小的结果很糟糕。我使用过imagemagick,其界面和命令是通过将一只猫包装在一个盒子里,然后在键盘上反复将它扔下一组楼梯来设计的。
我正在寻找一些不是 PIL 或 Imagemagick 的东西,我可以将其与 python 一起使用来进行简单、高质量的图像转换。就此而言,如果命令行界面良好,它甚至不需要 Python 绑定。
哦,它需要相对平台无关,我们的生产服务器是 Linux,但我们的一些开发人员在 Windows 上开发。它也不需要安装一堆愚蠢的 GUI 代码来用作库。
I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a set of stairs at a keyboard.
I'm looking for something which is not PIL or Imagemagick that I can use with python to do simple, high-quality image transformations. For that matter, it doesn't even have to have python bindings if the command line interface is good.
Oh, and it needs to be relatively platform agnostic, our production servers are linux, but some of our devs develop on windows. It can't require the installation of a bunch of silly gui code to use as a library, either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
它们不应该是这样,只要您:
quality=
级别设置为适当的值(默认值相当低)是They shouldn't be, as long as you:
quality=
level to something appropriate when saving JPEGs (the default is quite low)我不确定为什么 Image.thumbnail 受到如此严厉的批评。在我正在运行的当前版本中,它所做的只是找出所需的大小并就地调整图像大小。只要您使用正确的重新采样过滤器并首先转换为 RGB(如 bobince 所说),缩略图就不应该与调整大小有任何不同。
这是缩略图方法的实际来源:
I'm unsure as to why Image.thumbnail is getting such flak. In the present release that I'm running off of it does little more than figure out the desired size and resize the image in place. As long as you're using the proper resample filter and convert to RGB first (as bobince says) thumbnail shouldn't be any different than resize.
Here's the actual source for the thumbnail method:
PIL 可以很好地调整大小。确保您的源图像处于 RGB 模式,而不是调色板颜色,并尝试不同的算法选择。
PIL can do good resizing. Make sure your source image is in RGB mode, not palette colors, and try the different algorithm choices.
虽然 imagemagick 似乎是事实上的开源图像库,但可能 DevIL (跨平台,似乎执行简单的图像操作)或 FreeImage。
While imagemagick seems to be the de facto open-source imaging library, possibly DevIL (cross platform, seems to do simple image operations) or FreeImage.
您检查过 pypi 吗?粗略搜索显示了一些与图像相关的工具,我还发现了 python-gd,但不知道它有多有用。
我自己对 PIL 从来没有遇到过任何问题,但某种变化可能会很有趣。
Have you checked pypi? A cursory search shows some image related tools there, I also discovered python-gd, no clue how useful it might be though.
I've never had any issues with PIL myself, but some kind of variety might be interesting.
我认为 GIMP 有一个合理的命令行界面。
GIMP has a reasonable command-line interface, I think.
看一下其中一些图像库:
hxxp://pypi.python.org/pypi/collective.croppingimagefield/0.1beta
hxxp://pypi.python.org/pypi/cropresize/0.1.1
hxxp://pypi .python.org/pypi/image_resize/1.0
Take a look at some of these imaging libraries:
hxxp://pypi.python.org/pypi/collective.croppingimagefield/0.1beta
hxxp://pypi.python.org/pypi/cropresize/0.1.1
hxxp://pypi.python.org/pypi/image_resize/1.0
PIL 中的调整大小在很多方面都受到了破坏,而且 PIL 很长一段时间都没有得到维护。从 Pillow 2.7 开始,大多数问题都已解决性能显着提高。确保您使用的是最新的 Pillow。
Resizing in PIL was broken in many ways and PIL is not maintained for a long time. Starting from Pillow 2.7 most of the problems are fixed along with dramatically performance improvement. Make sure you are using latest Pillow.
上次我比较时,这个缩减器的输出几乎与 GIMP 的“立方”选项:
IIRC 的输出相同,差异在视觉上无法区分 - 由于舍入,一些像素值 +/-1,并且它们往往是圆形边缘。速度也不慢。
cf: http://www.mail-archive.com/ [电子邮件受保护]/msg00248.html
Last time I compared, this downscaler's output is almost identical to that of GIMP's "cubic" option:
IIRC, the differences are visually indistinguishable -- some pixel values +/-1 due to rounding, and they tend to be round the edges. It's not slow either.
cf: http://www.mail-archive.com/[email protected]/msg00248.html