0
當我嘗試在我的新編輯的圖像上放置邊框時,會出現此錯誤。錯誤來自這行代碼。類型錯誤'int'對象沒有屬性'__getitem__'
img_with_border = ImageOps.expand(imgred,border=25,fill='red')
有沒有人有修復? (我是Python的小白。)
def family():
q1=raw_input('What is the directory of your image? : ')
q2=raw_input('Which of these best fits you?: Christian, Patriot, or Satanist? : ')
q3=raw_input('What is the width of your frame? : ')
filename = (q1)
img = plt.imread(filename)
# Read the image data into an array
imgred = plt.imread(filename)
img = plt.imread(filename)
imgpat = plt.imread(filename)
imgblue = plt.imread(filename)
imggreen = plt.imread(filename)
imggrey = plt.imread(filename)
height = len(imgred)
width = len(imgred[0])
if q2 == 'Satanist':
for c1 in range(height):
for c2 in range(width):
imgred[c1][c2][1]=0
imgred[c1][c2][2]=0
r=abs(imgred[c1][c2][0]-255)
g=abs(imggreen[c1][c2][1]-255)
b=abs(imgblue[c1][c2][2]-255)
imgred[c1][c2]=[r,g,b]
r=abs(imgred[c1][c2][0]-255)
g=abs(imggreen[c1][c2][1]-255)
b=abs(imgblue[c1][c2][2]-255)
imgred[c1][c2]=[r,g,b]
def give_image():
img_with_border = ImageOps.expand(imgred,border=25,fill='red')
# Create figure with 3 subplots
fig, ax = plt.subplots(1, 3)
# Show the image data in a subplot
ax[0].imshow(img, interpolation='none')
ax[1].imshow(imgred, interpolation='none')
ax[2].imshow(img_with_border, interpolation='none')
MCVE: 當我嘗試邊框添加到已編輯的圖片,在錯誤出現。 例子:
image_file = ('woman.jpg')
filename = 'C:/Users/Dylan/woman.jpg'
imgred = plt.imread(filename)
height = len(imgred)
width = len(imgred[0])
for c1 in range(height):
for c2 in range(width):
imgred[c1][c2][1]=0
imgred[c1][c2][2]=0
def give_image():
img_with_border = ImageOps.expand(imgred,border=25,fill='red')
# Create figure with 3 subplots
fig, ax = plt.subplots(1, 1)
# Show the image data in a subplot
ax.imshow(imgred, interpolation='none')
但是,當它是不是編輯的圖片,我嘗試添加邊框,沒有錯誤。
image_file = ('woman.jpg')
filename = 'C:/Users/Dylan/woman.jpg'
img = plt.imread(filename)
img = Image.open('woman.jpg')
img_with_border = ImageOps.expand(img,border=25,fill='violet')
def give_image():
fig, ax = plt.subplots(1, 1)
# Show the image data in a subplot
ax.imshow(img_with_border, interpolation='none')
錯誤本身。
235 "Add border to image"
236 left, top, right, bottom = _border(border)
--> 237 width = left + image.size[0] + right
238 height = top + image.size[1] + bottom
239 out = Image.new(image.mode, (width, height), _color(fill, image.mode))
謝謝。
謝謝。我現在會嘗試。 – DZapza
我回來了......我怎樣才能把邊界變成4個東西的列表? – DZapza
@DZapza它需要返回一個列表:'返回左邊,頂部,右邊,底部' – Barmar