七牛云
安裝requests庫
pip install requests
獲取圖床信息
選擇新建存儲空間,記住這個空間的名字剂府。
image
獲取訪問域名
image
圖床認(rèn)證信息
獲取AK和SK
image
Alfred
安裝
下載地址 http://7xp77w.com1.z0.glb.clouddn.com/alfred%203.0.3.dmg
必須得激活视卢,不然用不了workflow.
workflow
下載地址 http://7xp77w.com1.z0.glb.clouddn.com/markdown%20img.alfredworkflow
workflow
在 alfred 里面輸入mdimgsetup,就會彈出一個文本文檔,如下:
image
修改為前面獲取到的信息。
image
調(diào)整URL
# coding: utf-8
from clipboard import get_paste_img_file
from upload import upload_qiniu
import util
import os
import subprocess
import sys
import time
if not os.path.exists(util.CONFIG_FILE):
util.generate_config_file()
config = util.read_config()
if not config:
util.notice('請先設(shè)置你的七牛圖床信息')
util.open_with_editor(util.CONFIG_FILE)
sys.exit(0)
url = '%s/%s' % (config['url'], config['prefix'])
img_file, need_format, format = get_paste_img_file()
if img_file:
# has image
# use time to generate a unique upload_file name, we can not use the tmp file name
upload_name = "%s.%s" % (int(time.time() * 1000), format)
if need_format:
size_str = subprocess.check_output('sips -g pixelWidth %s | tail -n1 | cut -d" " -f4' % img_file.name, shell=True)
size = int(size_str.strip()) / 2
markdown_url = '<img src="%s/%s" width="%d"/>' % (url, upload_name, size)
else:
markdown_url = '%s/%s' % (url, upload_name)
# make it to clipboard
os.system("echo '%s' | pbcopy" % markdown_url)
os.system('osascript -e \'tell application "System Events" to keystroke "v" using command down\'')
upload_file = util.try_compress_png(img_file, format!='gif')
if not upload_qiniu(upload_file.name, upload_name): util.notice("上傳圖片到圖床失敗上荡,請檢查網(wǎng)絡(luò)后重試")
else:
util.notice("剪切版里沒有圖片哎壳!")
根據(jù)個人需求毅待,設(shè)置markdown_url拼接格式。
使用方式
截圖
使用任意截圖工具截圖之后归榕,在任意編輯器里面你需要插入markdown格式圖片的地方尸红,按下cmd + ctrl + P即可!
已有圖片
如果你已經(jīng)有一張圖片了刹泄,希望上傳到圖床得到一個鏈接外里;通常的方式需要圖床客戶端或者瀏覽器插件,通過這個alfred插件:
直接復(fù)制本地圖片特石,然后按下cmd + ctrl + P 就能得到圖床的鏈接盅蝗!