這篇文章主要介紹了利用python怎么實現一個旋轉和水平翻轉功能,此處通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考價值,需要的朋友可以參考下:
Python是一種編程語言,內置了許多有效的工具,Python幾乎無所不能,該語言通俗易懂、容易入門、功能強大,在許多領域中都有廣泛的應用,例如最熱門的大數據分析,人工智能,Web開發等。
如下所示:
# coding=utf-8 import glob import os from PIL import Image def rotate_270(imgae): """ 將圖片旋轉270度 """ # 讀取圖像 im = Image.open(imgae) # im.show() # 指定逆時針旋轉的角度 im_rotate = im.rotate(270) # im_rotate.show() return im_rotate def flip_horizontal(image): """ 將圖片水平翻轉 """ im = Image.open(image) # im.show() im_fh = im.transpose(Image.FLIP_LEFT_RIGHT) # im_fh.show() return im_fh def createFile(path): isExists = os.path.exists(path) # 判斷結果 if not isExists: # 如果不存在則創建目錄 # 創建目錄操作函數 os.makedirs(path) return True else: # 如果目錄存在則不創建,并提示目錄已存在 print('%s 目錄已存在' % path) return False def main(): path = 'D:/VideoPhotos/hongshi/' createFile('D:/VideoPhotos/hongshi_rotate') createFile('D:/VideoPhotos/hongshi_flip_horizontal') dirs = os.listdir(path) for dir in dirs: # print(dir) createFile('D:/VideoPhotos/hongshi_rotate/' + dir) createFile('D:/VideoPhotos/hongshi_flip_horizontal/' + dir) images = glob.glob(path + dir + r"\*.jpg") for image in images: image_name = image[image.find("\\"):] print(image_name) rotate_270(image).save('D:/VideoPhotos/hongshi_rotate/' + dir + image_name) flip_horizontal(image).save( 'D:/VideoPhotos/hongshi_flip_horizontal/' + dir + image_name) if __name__ == '__main__': main()
到此這篇關于利用python怎么實現一個旋轉和水平翻轉功能的文章就介紹到這了,更多相關利用python怎么實現一個旋轉和水平翻轉功能的內容請搜索創新互聯以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持創新互聯!
網站欄目:利用python怎么實現一個旋轉和水平翻轉功能-創新互聯
文章起源:http://m.kartarina.com/article6/cdcoig.html
成都網站建設公司_創新互聯,為您提供營銷型網站建設、建站公司、網站排名、Google、網站營銷、網站設計
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯