在python中创建具有一定宽度边框的图像 [英] create an image with border of certain width in python
本文介绍了在python中创建具有一定宽度边框的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用过PIL
#back_color_width
for x in range(w):
for y in range(h):
if x==0 or y==0 or x==w-1 or y==h-1 :
pixels[x,y] = back_color
我需要在图像上添加一个边框,并在图像的所有4边上都设置宽度
I need to add a border to the image with a width on all 4 sides of image
推荐答案
您需要进行以下更改,以使边框的像素宽度达到任意数量:
This is what you need to change to make the border any number of px wide:
for x in range(w):
for y in range(h):
if (x<border_width
or y<border_width
or x>w-border_width-1
or y>h-border_width-1):
pixels[x,y] = (0,0,0)
#other 3 boxes
和#primary box
不创建框,而是分别为3点和1点.
#other 3 boxes
and #primary box
Doesn't make boxes but instead 3 points and 1 point respectively.
这篇关于在python中创建具有一定宽度边框的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文