← 输入框|github.com|刷新
Skip to content
This repository was archived by the owner on Sep 22, 2020. It is now read-only.
This repository was archived by the owner on Sep 22, 2020. It is now read-only.

Size parameter doesn't support omitting length or width #36

Open

Description

@roytang

According to the docs at https://python-thumbnails.readthedocs.io/en/latest/creating-thumbnails.html

size – String with the wanted thumbnail size. On the form: 200x200, 200 or x200.

But using the second or third forms causes an exception:

>>> get_thumbnail('d:\\temp\\test.jpg', '200x200', crop='center') 
<thumbnails.images.Thumbnail object at 0x0000022108309B08>
>>> get_thumbnail('d:\\temp\\test.jpg', '200x', crop='center')    
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\USER\Envs\cypress\lib\site-packages\thumbnails\__init__.py", line 53, in get_thumbnail
    size = engine.parse_size(size)
  File "C:\Users\USER\Envs\cypress\lib\site-packages\thumbnails\engines\base.py", line 183, in parse_size
    return int(size.split('x')[0]), int(size.split('x')[1])
ValueError: invalid literal for int() with base 10: ''
>>> get_thumbnail('d:\\temp\\test.jpg', 'x200', crop='center')  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\USER\Envs\cypress\lib\site-packages\thumbnails\__init__.py", line 54, in get_thumbnail
    thumbnail.image = engine.get_thumbnail(original, size, crop, options)
  File "C:\Users\USER\Envs\cypress\lib\site-packages\thumbnails\engines\base.py", line 37, in get_thumbnail
    image = self.create(original, size, crop, options)
  File "C:\Users\USER\Envs\cypress\lib\site-packages\thumbnails\engines\base.py", line 58, in create
    crop = self.parse_crop(crop, self.get_image_size(image), size)
  File "C:\Users\USER\Envs\cypress\lib\site-packages\thumbnails\engines\base.py", line 209, in parse_crop
    x_offset = self.calculate_offset(x_crop, original_size[0], size[0])
  File "C:\Users\USER\Envs\cypress\lib\site-packages\thumbnails\engines\base.py", line 226, in calculate_offset
    min(percent * original_length / 100.0, original_length - length / 2) - length / 2)
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

Activity

  1. relekang commented on Sep 21, 2020

    @relekang
    Member

    The last commit on this project was three years ago, so I would guess it needs a bit of work to be compatible with current versions of python and django. Even though, this might be a smaller bug. Anyways, I'm happy to give you access to the repo if you want to try to fix it. However, I would guess there are other solutions for creating thumbnails now.

  2. roytang commented on Sep 21, 2020

    @roytang
    Author

    Yeah, no problem. After logging this issue, I ended up using a different library instead. At least it's there in case someone wants to pick this up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions