2

Tried resize my image (weight > 100 MB) using:

>>> from PIL import Image
>>> image = Image.open(path_to_the_file)
>>> new_image = image.resize((200, 200))

and received ValueError: tile cannot extend outside image.

The size of original image is

>>> image.size
>>> (4922, 3707)

The same error I received while doing thumbnails, rotate etc.

What I am doing wrong?

Edit: Checked image using ImageMagic:

$ identify file.tif
file.tif[0] TIFF 4922x3707 4922x3707+0+0 32-bit Grayscale Gray 31.23MB   0.000u 0:00.009
file.tif[1] TIFF 2461x1854 2461x1854+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
filetif[2] TIFF 1231x927 1231x927+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
file.tif[3] TIFF 616x464 616x464+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
file.tif[4] TIFF 308x232 308x232+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
file.tif[5] TIFF 154x116 154x116+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
identify: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/881.
identify: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/881.
identify: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/881.
identify: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/881.
4
  • 1
    Is your TIFF image a single frame? Also, you could try using image.thumbnail((200, 200), Image.ANTIALIAS) Commented Dec 11, 2017 at 15:02
  • 1
    @MartinEvans Image.ANTIALIAS doesn't seem to be a listed re-sampling option for Image.thumbnail(). It's been renamed to Image.LANCZOS since PIL version 2.7.0 Commented Dec 11, 2017 at 15:04
  • The TIFF image is in single band. The mode is Float32 Commented Dec 11, 2017 at 15:05
  • ".. while doing thumbnails, rotate etc." – so, can you do anything at all with your image? If not, then PIL may not support it properly. Commented Dec 11, 2017 at 15:21

4 Answers 4

1

The problem might be here, from the docs:

Note that the bilinear and bicubic filters in the current version of PIL are not well-suited for large downsampling ratios (e.g. when creating thumbnails). You should use ANTIALIAS unless speed is much more important than quality.

In this case, add at your code Image.ANTIALIAS

from PIL import Image
image = Image.open(path_to_the_file)
new_image = image.resize((200, 200) Image.ANTIALIAS)

Should now do the trick.

Sign up to request clarification or add additional context in comments.

Comments

1

I was using ggdalwarp like this :

gdal.Warp('output.tiff', 'input.tiff', xRes=0.5, yRes=0.5)

Comments

0

You should install pytho-resize-image package.

One example

from PIL import Image

from resizeimage import resizeimage


with open('acajeb-image.jpeg', 'r+b') as f:
    with Image.open(f) as image:
        cover = resizeimage.resize_cover(image, [200, 200])
        cover.save('test-image-cover.jpeg', image.format)

You can install package with

pip install python-resize-image

1 Comment

This is not what op asked for.
0

Try adding the Image.ANTIALIAS parameter:

new_image = image.resize((200, 200), Image.ANTIALIAS)

This worked for me in one of my previous projects.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.