I am working in Blender and so I wanted to use a bump map I found on the internet. The image is here. However, when I tried to use it, Blender crashed. I am assuming that happened because of the size of the image. That's why I wanted to create a simple script that would resize an image.
This is my script:
from PIL import Image
from math import sqrt
path = raw_input("Enter file path: ")
Image.warnings.simplefilter('ignore', Image.DecompressionBombWarning)
img = Image.open(path)
size = img.size
pixelsize = size[0] * size[1]
print "Current pixel size:", pixelsize
maxsize = input("Enter maximum pixel size: ")
img = img.convert(mode="RGB")
square1 = sqrt(pixelsize)
ratio = (size[0] / square1, size[1] / square1)
square2 = sqrt(maxsize)
newsize = (int(round(maxsize * ratio[0])), int(round(maxsize * ratio[1])))
img = img.resize(newsize)
oldname = path.split("/")[-1]
newname = "SMALLER_" + oldname
img.save(newname)
When I run the script I get the following error:
Traceback (most recent call last):
File "C:/Users/*****/Desktop/smaller/makeImageSmaller.py", line 19, in <module>
img = img.resize(newsize)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1550, in resize
return self._new(self.im.resize(size, resample))
ValueError: image has wrong mode
As you can see from the script, I already tried changing the mode to "RGB" (line 14), assuming that would fix the problem.
The image is quite large but I don't get the memory error.
I am stuck on that problem for quite a while and I just don't know what the problem is. Any help would be appreciated.