Created
April 14, 2020 15:12
-
-
Save zclongpop123/674ead536f11607602b8e78b0ae42676 to your computer and use it in GitHub Desktop.
添加图片半透明蒙版
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #======================================== | |
| # author: Changlong.Zang | |
| # mail: [email protected] | |
| # time: Tue Apr 14 22:22:51 2020 | |
| #======================================== | |
| from PIL import Image, ImageDraw | |
| #--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | |
| def main(): | |
| ''' | |
| ''' | |
| with Image.open('C:/Users/zangchanglong/Desktop/the_lion_king-002.jpg') as img: | |
| img = img.convert('RGBA') | |
| mask = Image.new('RGBA', (img.width, img.height)) | |
| draw = ImageDraw.Draw(mask) | |
| draw.rectangle(((0, 0), (240, img.height)), fill=(0, 0, 0, 128)) | |
| draw.rectangle(((img.width - 240, 0), (img.width, img.height)), fill=(0, 0, 0, 128)) | |
| img.alpha_composite(mask) | |
| img = img.convert('RGB') | |
| img.save('C:/Users/zangchanglong/Desktop/the_lion_king-003.jpg', 'jpeg') | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment