티스토리 뷰

반응형

안녕하세요 종백이 입니다!

 

지난번에 사업에 쓰는 캡처 프로그램을 한번 만들었는데요! 프로그램을 사용하는 도중 불편함을 느껴서 더 업그레이드된 화면 캡처 프로그램을 만들어봤습니다 ㅎㅎ 지난 프로그램 제작 리뷰 보려면 여기로!

 

구체적으로 제가 필요했던 내용은 정사각형 모양으로 이미지를 캡처한 후 1000 X 1000 JPG 파일로 저장까지 해주는 프로그램이 필요했습니다. 따라서 이전에는 q 버튼을 통해 시작점과 끝점을 찍어 캡처를 했는데 정사각형 가이드라인이 없다 보니 캡처를 여러 번 하는 상황이 많았습니다 ㅎㅎ 견디다 못해 바아로 파이썬 켜버리고 뚝딱 만들어 버렸습니다😎

 

이름하여... 원터치 캡처 프로그램!

사용 방법은 아주 간단합니다 ㅎㅎ

 

  1. 파일명 입력
  2. 마우스 휠로 캡처 이미지 크기 조절
  3. 마우스 왼쪽 버튼으로 클릭

 

위 3 가지 단계로 캡처를 할 수 있습니다. 매우 직관적이고 간편하게 만들었습니다! 아래 캡처에서 확인하시죠 ㅎㅎ

파일명 입력
1. 파일명 입력

처음 실행하면 위와 같이 파일 이름을 입력하라는 메뉴가 뜹니다! 바로 파일명 입력하시고~

이미지에 맞추기
2. 빨간선을 캡처하고자 하는 이미지에 맞추기

위와 같이 파란 영역을 캡처하고자 하면 마우스 휠을 조절하여 빨간 선을 캡처 크기에 맞춥니다!

사이즈 조절
3. 휠 조절을 통한 캡쳐 사이즈 조절

위 gif는 빨간 선을 마우스 휠로 조절하는 과정을 캡처해서 gif로 나타낸 것입니다 ㅎㅎ 최종적으로 딱 맞게 캡처된 것을 볼 수 있습니다. GIF 만드는 프로그램이 궁금하다면 여기로!

 

이렇게 아주 쉽고 직관적인 프로그램을 만듦으로써 제가 사업에 들이는 시간과 힘은 더 줄어들었습니다 ㅎㅎ 개꿀 ㅎㅎ

혹시 필요하신 분은 댓글에 메일 주소 남겨주시면 실행 파일로 변환해서 보내드릴게요~

 

소스는 아래 참고 부탁드립니다 ㅎㅎ

 

from PIL import Image, ImageTk
import pyautogui
import tkinter

def rectSizeModify(event):
    global rectSize
    resolution = 2
    scroolValue = int(-1*(event.delta/120))
    scroolValue = scroolValue * resolution
    if scroolValue == -2 or scroolValue == 2:
        rectSize += scroolValue

def rectDrawing(event):
    global start_x, start_y
    start_x, start_y = event.x, event.y
    canvas1.delete("rect1")
    canvas1.create_rectangle(start_x-rectSize,
                             start_y-rectSize,
                             start_x + rectSize,
                             start_y + rectSize,
                             outline="red",
                             tag="rect1")
def clickEvent(event):
    filepath = f"./이미지모음/{check}.jpg"
    img = pyautogui.screenshot(filepath, region = (start_x-rectSize+1,start_y-rectSize+1,(rectSize-1)*2,(rectSize-1)*2))

    img_resize = img.resize((1000, 1000), Image.LANCZOS)
    if img_resize.mode != 'RGB':
        img_resize = img_resize.convert('RGB')
    img_resize.save(filepath)
    print("캡처완료")
    root.destroy()

if __name__ == "__main__":
    global rectSize
    rectSize = 300
    while True:
        check = input("파일 이름을 입력하시오. (종료 원하면n): ")
        if check == "n":
            break
        img = pyautogui.screenshot()
        img_resized = img.resize(size=(int(img.width),
                                    int(img.height)),
                                resample=Image.LANCZOS)

        root = tkinter.Tk()
        root.attributes("-topmost", True)
        root.attributes("-fullscreen", True)

        img_tk = ImageTk.PhotoImage(img_resized)

        canvas1 = tkinter.Canvas(root,
                                bg="black",
                                width=img_resized.width,
                                height=img_resized.height)
        canvas1.create_image(0, 0, image=img_tk, anchor=tkinter.NW)

        canvas1.pack()
        canvas1.bind("<MouseWheel>", rectSizeModify)
        canvas1.bind("<Motion>", rectDrawing)
        canvas1.bind("<Button-1>", clickEvent)
        root.mainloop()

 

이상으로 리뷰 마치겠습니다.

글 내용이 도움되셨다면 구독 또는 좋아요 부탁드립니다~

더 많은 정보와 리뷰를 원하시면 여기로!

모바일은 여기로!

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
글 보관함