代码如下:
from PIL import Image
from os import listdir
import math
import numpy as np
import cv2
def textureSquare( imgPath):
img = Image.open(imgPath)
width, height = img.size
delta = width - height
if(delta > 0):
repeat = delta / height
result = Image.new(img.mode, (width, height + delta))
region1 = img.crop((0, height - (delta - repeat * height), width, height))
result.paste(region1, box = (0, 0))
for i in range(0, repeat + 1):
result.paste(img, box = (0, delta - repeat * height + i * height))
return result
elif(delta < 0):
delta = abs(delta)
repeat = delta / width
result = Image.new(img.mode, (width + delta, height))
region1 = img.crop((0, 0, delta - repeat * width, height))
result.paste(region1, box = (0, 0))
for i in range(0, repeat + 1):
result.paste(img, box = (delta - repeat * width + i * width, 0))
return result
else:
return img
def textureTransform( imgPath, offsetX, offsetY, uvScale):
imgOriginal = Image.open(imgPath)
img = textureSquare("E:\\PythonProjects\\pro_obj_converter\\a.jpg")
# print img.size
img.save("E:\\PythonProjects\\pro_obj_converter\\a.jpg")
来源:CSDN
作者:sh15285118586
链接:https://blog.csdn.net/sh15285118586/article/details/84033214