Skip to content

Instantly share code, notes, and snippets.

@rinsuki
Created June 22, 2016 10:15
Show Gist options
  • Save rinsuki/409e17be8b7c50751f5f70e15614f8d2 to your computer and use it in GitHub Desktop.
Save rinsuki/409e17be8b7c50751f5f70e15614f8d2 to your computer and use it in GitHub Desktop.
#!python2
# coding: utf-8
import PIL.Image
import os
import hashlib
from PyQt4.QtCore import *
from PyQt4.QtGui import *
filename=""
def main():
global filename
app = QApplication([])
win = QWidget()
win.setWindowTitle(u"SlackのEmoji用に画像をいい感じにする奴")
# main sizer
main_sizer = QVBoxLayout()
main_sizer.addWidget(QLabel(u"1.元画像を選択してください"))
show_file_path = QLineEdit()
show_file_path.setDisabled(True)
main_sizer.addWidget(show_file_path)
select_base_image = QPushButton(u"選択する")
def onClick(ev):
global filename
filename = QFileDialog.getOpenFileNameAndFilter(None,u"SlackのEmoji用にいい感じにしたい画像を選択",QString(),u"画像ファイル (*.png *.jpg *.bmp *.gif)")[0]
print filename
show_file_path.setText(filename)
return
select_base_image.clicked.connect(onClick)
main_sizer.addWidget(select_base_image)
main_sizer.addWidget(QLabel(u"2.変換ボタンを押してください"))
convert_image_button = QPushButton(u"変換する")
def convert():
global filename
outdir = os.environ.get("TEMP",os.environ.get("TMP","/tmp"))+os.sep+"SlackEmojiResizer"
print outdir
if(not os.path.exists(outdir)):
os.makedirs(outdir)
hasher = hashlib.sha1()
hasher.update(filename)
outfile = outdir+os.sep+hasher.hexdigest()+".png"
print outfile
# それでは画像変換の方をやっていきます
image = PIL.Image.open(str(filename.replace("/",os.sep)),"r")
resize_img = image.resize((128,128))
resize_img.save(outfile,"PNG")
msgbox = QMessageBox()
clipboard = app.clipboard()
clipboard.setText(outfile)
msgbox.setText(u"変換に成功しました!\nクリップボードにフルパスをコピーしました。")
msgbox.exec_()
convert_image_button.clicked.connect(convert)
main_sizer.addWidget(convert_image_button)
# owari
win.setLayout(main_sizer)
win.show()
app.exec_()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment