screen capture helper

Screen Capture Tool

I made a small python tool to automatic generate the markdown text for image from clipboard.

  1. save the clipboard image to Save Path
  2. generate the markdown text of it
  3. copy it to this blog

screencapture.png

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
from PIL import ImageGrab
import PySimpleGUI as sg

# im = ImageGrab.grabclipboard()
# im.save('somefile.png','PNG')

layout = [
[sg.Text("Save Path"),sg.In(size=(25, 1), enable_events=True, key="-FOLDER-",default_text="save path"), sg.FolderBrowse()],
[sg.Text("Root"), sg.In(size=(25, 1), enable_events=True, key="root", default_text="../../source/_posts/{}/")],
[sg.Text("File Name"), sg.In(size=(25, 1), enable_events=True, key="FileName", default_text=".png"),sg.Button("Markdown")],
[sg.In(size=(25, 1), enable_events=True, key="markdown", default_text="")]
]

window = sg.Window("Screenshot Helper", layout)

while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Cancel'):
break
if event == "Markdown":
directory = values["-FOLDER-"]
im = ImageGrab.grabclipboard()
if im is not None:
file_name = values['FileName']
file_path = directory + "\\" + file_name
im.save(file_path, 'PNG')
markdown_path = values['root']+file_name
markdown_text = "![{}]({})".format(file_name, markdown_path)
window.Element('markdown').update(value = markdown_text)
print('save successfully')
window.close()

then convert it to an .exe file

pyinstaller –onefile -w screenshot_helper.py

how to insert image

first modify the _config.yml

1
2
# post_asset_folder: false
post_asset_folder: true

it will generate a folder with same name of your post, you can put the image there.

post_folder.png

insert the image use

1
![screencapture.png](screencapture.png)

when you preview your markdown page, the image will not be shown correctly.
shown_incorrect.png
but it will be shown correctly when you deploy on your github page.

try to uninstall hexo-asset-image –save if not working