Python 缩放图像-保持位置-枕头
伙计们,我试着缩放一个图像,缩小和扩展它,但保持它在图像中的位置。让我解释一下。如下图所示: ,我需要扩展它,但要保持位置 我使用下面的代码来做,但它没有保留位置。有什么想法吗Python 缩放图像-保持位置-枕头,python,python-imaging-library,pillow,Python,Python Imaging Library,Pillow,伙计们,我试着缩放一个图像,缩小和扩展它,但保持它在图像中的位置。让我解释一下。如下图所示: ,我需要扩展它,但要保持位置 我使用下面的代码来做,但它没有保留位置。有什么想法吗 from PIL import Image, ImageChops, ImageOps,ImageStat, ImageFilter def scaling_thumbline(image1): scale = Image.new("1", image1.size, "white"); image1.sh
from PIL import Image, ImageChops, ImageOps,ImageStat, ImageFilter
def scaling_thumbline(image1):
scale = Image.new("1", image1.size, "white");
image1.show()
x = image1.size[0]
y = image1.size[1]
print (x,y)
image2 = image1.resize((x/2,y/2),Image.ANTIALIAS);
image2.show()
print image2.size
for x in range(0,image2.size[0]):
for y in range(0,image2.size[1]):
scale.putpixel((x,y),image2.getpixel((x,y)));
scale.show()
print scale.size
image1 = Image.open("Problems/Basic Problems C/Basic Problem C-02/A.png").convert("1");
scaling_thumbline(image1)
我得到,
,我需要扩展它,但要保持位置。注意,在中间,图像移到了顶部。
有什么想法吗?帮助?我认为该功能正是您所需要的。我在MacOSXYosemite上使用Python2.7.10测试了下面的代码,得到了正确的结果
>>> from PIL import Image
>>> a = Image.open('test.png')
>>> size = a.size
>>> newSize = tuple([dimension/10 for dimension in size])
>>> b = a.resize(newSize)
>>> a.show()
>>> b.show()
为什么不直接使用image1.resize?你能展示你想要的输出的示例图像吗?