Python imaging alternatives

后端 未结 9 1211
渐次进展
渐次进展 2021-01-31 12:31

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 TERRIB

相关标签:
9条回答
  • 2021-01-31 12:44

    I've used PIL, and the resample/resize results are TERRIBLE.

    They shouldn't be, as long as you:

    1. use only Image.ANTIALIAS filtering for downscaling operations
    2. use only Image.BICUBIC filtering for upscaling operations.
    3. remember to convert to 'RGB' colour mode before the resize if you are using a paletted image
    4. don't use .thumbnail(). it's crap
    5. set the quality= level to something appropriate when saving JPEGs (the default is quite low)
    0 讨论(0)
  • 2021-01-31 12:49

    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.

    0 讨论(0)
  • 2021-01-31 12:54

    PIL can do good resizing. Make sure your source image is in RGB mode, not palette colors, and try the different algorithm choices.

    0 讨论(0)
  • 2021-01-31 12:58

    While imagemagick seems to be the de facto open-source imaging library, possibly DevIL (cross platform, seems to do simple image operations) or FreeImage.

    0 讨论(0)
  • 2021-01-31 12:59

    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

    0 讨论(0)
  • 2021-01-31 13:03

    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:

    def thumbnail(self, size, resample=NEAREST):
      # preserve aspect ratio
      x, y = self.size
      if x > size[0]: y = max(y * size[0] / x, 1); x = size[0]
      if y > size[1]: x = max(x * size[1] / y, 1); y = size[1]
      size = x, y
    
      if size == self.size:
          return
    
      self.draft(None, size)
    
      self.load()
    
      try:
          im = self.resize(size, resample)
      except ValueError:
          if resample != ANTIALIAS:
              raise
          im = self.resize(size, NEAREST) # fallback
    
      self.im = im.im
      self.mode = im.mode
      self.size = size
    
      self.readonly = 0
    
    0 讨论(0)
提交回复
热议问题