공부를 함시다/Python

[Python] 로컬 이미지를 클립보드에 복사하기

갈룩시노테7 2025. 1. 22. 23:43
반응형
from PIL import Image
from io import BytesIO
import win32clipboard
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

image = Image.open("local")

# 이미지 데이터를 BMP 형식으로 변환
output = BytesIO()
image.convert("RGB").save(output, "BMP")
bmp_data = output.getvalue()[14:]  # BMP 헤더 제거
output.close()

# 클립보드에 이미지 복사
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_DIB, bmp_data)
win32clipboard.CloseClipboard()

# 단어 값 정렬 및 순서 정렬

driver = webdriver.Chrome()
driver.get("https://www.editpad.org/")
driver.find_element(By.XPATH, '//*[@id="contentSec"]/button/img').click()
time.sleep(5)
driver.find_element(By.XPATH, '//*[@id="textform"]/div/div[5]/label/span').click()
time.sleep(5)
driver.find_element(By.XPATH, '//*[@id="editorTextarea"]/div[2]/div[2]').click()
time.sleep(5)
driver.find_element(By.XPATH, '//*[@id="editorTextarea"]/div[2]/div[2]').send_keys(Keys.CONTROL + 'v')
time.sleep(5)
반응형