def main(): ### CHANGE THESE VALUES: to = console.input_alert('Send Email To', 'Enter an email address below') subject = console.input_alert('Subject', 'Enter the subject of the email below') gmail_pwd = keychain.get_password('Gmail', '*****@*****.**') gmail_user = '******' #Load a sample image, modify as needed: image = clipboard.get_image() print 'Connecting...' smtpserver = smtplib.SMTP("smtp.gmail.com", 587) console.show_activity() smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver.login(gmail_user, gmail_pwd) print 'Preparing message...' outer = MIMEMultipart() outer['Subject'] = subject outer['To'] = to outer['From'] = gmail_user outer.preamble = 'You will not see this in a MIME-aware email reader.\n' attachment = get_attachment(image) outer.attach(attachment) composed = outer.as_string() print 'Sending...' smtpserver.sendmail(gmail_user, to, composed) smtpserver.close() console.hide_activity() sound.play_effect('Bleep') print 'Done.'
def main(): global b64str cpimage = clipboard.get_image() #if image was in clipboard. if cpimage: #resize to icon size. icon = cpimage.resize((57, 57), Image.BILINEAR) #convert to rgb format. icon = icon.convert('RGB') # icon.show() #show resized image. #create string buffer to write png file to. iconstr = StringIO() #write image to string buffer in png format. icon.save(iconstr, 'png') #convert save buffer to base64. b64str = base64.standard_b64encode(iconstr.getvalue()) #put base64 string in clipboard. clipboard.set(b64str) #now decode to test. mystr = base64.standard_b64decode(b64str) #read file from string buffer. stb = StringIO(mystr) img = Image.open(stb) #show the image. img.show() #print some info. print(str(img.format)) print(str(img.mode)) print(str(img.size)) print(str(img.info))
def main(): global b64str cpimage = clipboard.get_image() #if image was in clipboard. if cpimage: #resize to icon size. icon = cpimage.resize((57, 57), Image.BILINEAR) #convert to rgb format. icon = icon.convert('RGB') # icon.show() #show resized image. #create string buffer to write png file to. iconstr = StringIO() #write image to string buffer in png format. icon.save(iconstr, 'png') #convert save buffer to base64. b64str = base64.standard_b64encode(iconstr.getvalue()) #put base64 string in clipboard. clipboard.set(b64str) #now decode to test. mystr = base64.standard_b64decode(b64str) #read file from string buffer. stb = StringIO(mystr) img = Image.open(stb) #show the image. img.show() #print some info. print str(img.format) print str(img.mode) print str(img.size) print str(img.info)
def main(): img = clipboard.get_image() if not img: print('No input image') return if not img.mode.startswith('RGB'): img = img.convert('RGB') gray_img = ImageOps.grayscale(img) clipboard.set_image(gray_img)
def pic_save(image, image_mode, width, height, quality, resize): print('\nPicture save is in process ...') if resize: image = image.resize((width, height), Image.ANTIALIAS) background = Image.new(image_mode, (width,height), 'white') background.paste(image, (0, 0)) clipboard.set_image((background), format='jpeg', jpeg_quality=quality) photos.save_image(clipboard.get_image()) fmt = 'Completed!\nResolution = {} x {}, quality = {:.0f}%, mode = {}' print(fmt.format(width, height, quality * 100, image_mode))
def pic_save(image, m, x, y, q, r, filename): print print 'File: ' + filename + ' is in process ...' if r == True: image = image.resize((x, y), Image.ANTIALIAS) background = Image.new(m, (x, y), 'white') background.paste(image,(0,0)) clipboard.set_image((background), format='jpeg', jpeg_quality=q) image2 = clipboard.get_image() image2.save(filename, 'JPEG')
def pic_save(image, width, height, text, font, fontsize, color, x, y, scale): background = Image.new('RGBA', (width,height), 'white') background.paste(image, (0, 0)) draw = ImageDraw.Draw(background) y = height - (y * scale) x = x * scale f = ImageFont.truetype(font, int(fontsize * scale)) textsize = draw.textsize(text, font=f) x -= textsize[0]/2 y -= ((textsize[1]/1.15)/2) # remove offset / add div factor 1.15 (difference between pixel size and font size) draw.text((x, y), text, font=f, fill=color) clipboard.set_image(background, format='jpeg', jpeg_quality=0.98) photos.save_image(clipboard.get_image())
def pic_save(image, width, height, text, font, fontsize, color, x, y, scale): background = Image.new('RGBA', (width,height), 'white') background.paste(image, (0, 0)) draw = ImageDraw.Draw(background) offset = fontsize / 3.2 # offset is relative to the fontsize fontsize *= scale y = height - y f = ImageFont.truetype(font, int(fontsize)) textsize = draw.textsize(text, font=f) x -= textsize[0]/2 y -= (textsize[1]/2) + offset draw.text((x, y), text, font=f, fill=color) clipboard.set_image(background, format='jpeg', jpeg_quality=0.98) photos.save_image(clipboard.get_image())
def getClipboardImages(): _sizs = [] _scales = [] for i in range(max_imags): _im = clipboard.get_image(idx=i) if not _im: break else: image_list.append(_im) _sizs.append(_im.size) (w, h) = _im.size _scales.append(round(w / h, 2)) print('clipboard images:{}{}'.format(_sizs, _scales)) return image_list
def main(): print 'Loading image from clipboard...' img = clipboard.get_image() if img is None: print 'No image in clipboard, using default image instead...' img = Image.open('Test_Mandrill') img.show() print 'Enter the top caption (press return for none):' caption_top = unicode(raw_input(), 'utf-8') caption_top = caption_top.upper() if caption_top != '': draw_caption(img, caption_top, top=True) print 'Enter the bottom caption (press return for none):' caption_btm = unicode(raw_input(), 'utf-8') caption_btm = caption_btm.upper() if caption_btm != '': draw_caption(img, caption_btm, top=False) img.show()
def getimg(s): img=clipboard.get_image(idx=0) img_bytes=io.BytesIO() widge,height=img.size img.save(img_bytes,format='PNG') img_bytes='0'.encode()+str(widge).encode()+'|'.encode()+str(height).encode()+'&'.encode()+img_bytes.getvalue() # img.show() i=0 if(len(img_bytes)>1024): while 1: end=900+i if(end>len(img_bytes)): s.sendall(img_bytes[i:]) break s.sendall(img_bytes[i:end]) i=end else: s.send(img_bytes)
def extract_code(): language_preference = ['fi', 'en', 'se'] load_framework('Vision') VNRecognizeTextRequest = ObjCClass('VNRecognizeTextRequest') VNImageRequestHandler = ObjCClass('VNImageRequestHandler') pil_image = clipboard.get_image() text = "" if pil_image is not None: buffer = io.BytesIO() pil_image.save(buffer, format='PNG') image_data = buffer.getvalue() req = VNRecognizeTextRequest.alloc().init().autorelease() req.setRecognitionLanguages_(language_preference) handler = VNImageRequestHandler.alloc().initWithData_options_( image_data, None).autorelease() success = handler.performRequests_error_([req], None) if success: for result in req.results(): text += str(result.text()) + "\n" else: print('Problem recognizing anything') text = re.sub(" ", "", text) dtext = text.split("\n") code = "" for d in dtext: try: if d[0] == "X" and len(d) == 16: code = d except: abco = 1 if d.count("AQ") > 0: code = d if not code == "": print(code) keyboard.insert_text(code) else: console.hud_alert("認識できませんでした。", "error", 0.3)
reduction_amounts = {'Retina iPhone': 35, 'Non-retina iPhone': 50, 'Retina iPad': 60, 'Non-retina iPad': 75 } for amount in reduction_amounts: if reduction_amounts[amount] >= 100: print 'One of your reduction_amounts is too high, must be lower than 100.\nExample: If you want the resulting image to be 1/4 its original size, the reduction_amounts would be 25.' sys.exit() # This takes a max of 5 arguments including the title and message, # so you can really only put in 2 devices and 'Custom'. Set the two # you want here. # Make sure they match the string in reduction_amounts exactly! q1 = 'Retina iPhone' q2 = 'Non-retina iPad' if not clipboard.get_image(idx=0): print 'I don\'t think there are any images on the clipboard.' sys.exit() resizeAmountQ = console.alert('What percent of original size?','','{0}% (default for {1})'.format(reduction_amounts[q1], q1),'{0}% (default for {1})'.format(reduction_amounts[q2], q2), 'Custom') if resizeAmountQ == 1 : resizeAmount = float(reduction_amounts[q1]) / 100 elif resizeAmountQ == 2 : resizeAmount = float(reduction_amounts[q2]) / 100 elif resizeAmountQ == 3 : resizeAmount = float(console.input_alert('What percent of original size?','Number only','40')) / 100 else: print 'Whups!' sys.exit() x = 0
# https://forum.omz-software.com/topic/2353/encoding-images-in-base64 # coding: utf-8 import workflow import clipboard import photos import base64 source_selection = workflow.get_variable('source') if source_selection == 'photo': image_selection = photos.pick_image() else: image_selection = clipboard.get_image() if not image_selection: console.alert('No Image', 'Clipboard does not contain an image') w, h = image_selection.size encoded = base64.b64encode(str(image_selection) workflow.set_variable('encodedImage', str(encoded)) workflow.set_variable('origSize', str(w))
##### Takes Image on Pasteboard from Iphone and saves via FTP a 600px image to Dropbox Returns a link to iPhone sized image to view import Image, ImageOps, ImageFilter import ftplib import console import clipboard import datetime from io import BytesIO import urllib today = datetime.datetime.now() image = clipboard.get_image() fileName = console.input_alert("Image Title", "Enter Image File Name") fileName = fileName + '_' + today.strftime("%Y-%m-%d-%H%M%S") + '.png' userName = "******" userPass = "******" host = "prodjohn8.bluefly.corp" port = 22 urlBase = "http://192.168.21.111:8082/Dropbox_sites/SpyderMac/py_iphone/uploads_from_iphone" remotePath = "/Users/johnb/Dropbox_sites/SpyderMac/py_iphone/uploads_from_iphone" datePath = today.strftime("%Y/%m/") # Used to create full remote file path remoteFilePath = remotePath + datePath def customSize(img): w, h = img.size print 'w: ' + str(w) print 'h: '+ str(h)
# https://forum.omz-software.com/topic/4504/image-processing-using-objc from PIL import Image, ImageOps, ImageFilter, ImageChops import photos, clipboard, webbrowser imo = clipboard.get_image(idx=0) if not imo.mode == 'RGB': img = imo.convert('RGB') im1 = img.filter(ImageFilter.MaxFilter(size=9)) im2 = ImageChops.subtract(im1, img) im3 = ImageOps.invert(im2) im4 = im3.filter(ImageFilter.SHARPEN) im5 = ImageOps.autocontrast(im4, cutoff=1) clipboard.set_image(im5, jpeg_quality=1.0) webbrowser.open('workflow://')
- $yCategories status: $yStatus photos: - url: $yPhotos --- $yContent''' # standard locations for images and content for Statamic imgBase = "/assets/img/" contentBase = "/_content/" imgRemotePath = rootDir + imgBase txtRemotePath = rootDir + contentBase # Let's get the image from the clipboard and ask some questions today = datetime.datetime.now() image = clipboard.get_image() imgFileName = console.input_alert("Image Title", "Enter Image File Name") title = console.input_alert("Article Title", "Enter the article title") sts = console.alert("Status","Choose the article status","Live","Draft","Hidden") category = console.input_alert("Post category", "Enter a category") words = console.input_alert("Article Text", "Enter your thoughts") imgFileName = imgFileName +'_'+ today.strftime("%Y-%m-%d-%H%M%S") +'.png' if sts == 1: status = "live" elif sts == 2: status = "draft" elif sts == 3: status = "hidden" # Can we connect to the FTP?
def run(self): self.status = 'complete' img = clipboard.get_image() return ElementValue(type=self.get_output_type(), value=img)
import clipboard import Image import console import webbrowser import photos im1 = clipboard.get_image(idx=0) im2 = clipboard.get_image(idx=1) im3 = clipboard.get_image(idx=2) im4 = clipboard.get_image(idx=3) background = Image.new('RGBA', (612, 612), (255, 255, 255, 255)) console.clear() print "Generating image..." console.show_activity() a = im1.resize((306, 306), Image.ANTIALIAS) b = im2.resize((306, 306), Image.ANTIALIAS) c = im3.resize((306, 306), Image.ANTIALIAS) d = im4.resize((306, 306), Image.ANTIALIAS) background.paste(a, (0, 0)) background.paste(b, (306, 0)) background.paste(c, (0, 306)) background.paste(d, (306, 306)) background.show() console.hide_activity() photos.save_image(background) inst = 'instagram://camera' webbrowser.open(inst)
q1 = riPhone q2 = nriPad resizeAmountQ = console.alert('What percent of original size?','',q1,q2,'Custom') if resizeAmountQ == 1 : resizeAmount = float(q1[0:2]) / 100 elif resizeAmountQ == 2 : resizeAmount = float(q2[0:2]) / 100 elif resizeAmountQ == 3 : resizeAmount = float(console.input_alert('What percent of original size?','Number only','40')) / 100 else: print 'Whups!' exit while True: img = clipboard.get_image(idx=x) if img: width, height = img.size smaller = img.resize( (int(width * resizeAmount), int(height * resizeAmount) ), Image.ANTIALIAS) photos.save_image(smaller) x += 1 elif x == 0 : print 'No images found on the clipboard.' else: print 'Looks like it worked. The downsampled images should be in your camera roll.' break
# @viticci # Taken from Viticci :: https://github.com/viticci/pythonista-scripts # Takes two iPhone 5 screenshots, places them side-by-side in a single image set to the clipboard. # Python version of this Keyboard Maestro macro: http://www.macstories.net/tutorials/a-better-way-to-combine-iphone-screenshots-with-keyboard-maestro/ # Unlike ScreenshotsClipboard, this script lets you set the placement of screenshots in the final image # You can, for instance, decide to paste the first Photos.app screenshot (index starts at 0) as the second image on the right # If you choose "the second image", the second file copied in Photos.app will be pasted first. # Inspired by Gabe Weatherhead: http://www.macdrifter.com/pythonista-app-from-toy-to-tool.html import photos import clipboard import Image if clipboard.get_image(idx=0) and clipboard.get_image(idx=1): im1 = clipboard.get_image(idx=0) im2 = clipboard.get_image(idx=1) else: im1 = photos.get_image(-1) im2 = photos.get_image(-2) _1 = im1.resize((366,650),Image.ANTIALIAS) _2 = im2.resize((366,650),Image.ANTIALIAS) background = Image.new('RGBA', (746,650), (255, 255, 255, 255)) print "Which image goes on the left? (in Photos.app order)" print "[1] The first image" print "[2] The second image" formatType = raw_input("Select an image: ")
from __future__ import print_function # @viticci # Taken from Viticci :: https://github.com/viticci/pythonista-scripts # Takes two iPhone 5 screenshots, places them side-by-side in a single image set to the clipboard. # Python version of this Keyboard Maestro macro: http://www.macstories.net/tutorials/a-better-way-to-combine-iphone-screenshots-with-keyboard-maestro/ # Unlike ScreenshotsClipboard, this script lets you set the placement of screenshots in the final image # You can, for instance, decide to paste the first Photos.app screenshot (index starts at 0) as the second image on the right # If you choose "the second image", the second file copied in Photos.app will be pasted first. # Inspired by Gabe Weatherhead: http://www.macdrifter.com/pythonista-app-from-toy-to-tool.html import photos import clipboard import Image if clipboard.get_image(idx=0) and clipboard.get_image(idx=1): im1 = clipboard.get_image(idx=0) im2 = clipboard.get_image(idx=1) else: im1 = photos.get_image(-1) im2 = photos.get_image(-2) _1 = im1.resize((366, 650), Image.ANTIALIAS) _2 = im2.resize((366, 650), Image.ANTIALIAS) background = Image.new('RGBA', (746, 650), (255, 255, 255, 255)) print("Which image goes on the left? (in Photos.app order)") print("[1] The first image") print("[2] The second image")
from __future__ import print_function # https://gist.github.com/jefflovejapan/5076080 import requests import console import clipboard import Image console.clear() thisImage = clipboard.get_image(0) thisImage.show() user = '******' passw = 'du7rte9ghil7ce8phi7theg5spul' #derp = console.login_alert('Welcome to The Verge') s = requests.Session() r = s.get('http://www.theverge.com/admin/assets/new?community_id=372', auth=(user, passw)) print(r.url) print(r.text) payload = { 'title': 'test', 'uploaded_data': thisImage, 'tags': 'testing1, testing2', 'disable_resize_on_save': 'false' } final = s.get('', params=payload)
# Imports two screenshots (iPhone 5) from the iOS clipboard and creates a single image # Based on: http://www.macstories.net/tutorials/a-better-way-to-combine-iphone-screenshots-with-keyboard-maestro/ # Images are pasted in order of Photos.app import clipboard import Image im1 = clipboard.get_image(idx=0) im2 = clipboard.get_image(idx=1) _1 = im1.resize((366,650),Image.ANTIALIAS) _2 = im2.resize((366,650),Image.ANTIALIAS) background = Image.new('RGBA', (746,650), (255, 255, 255, 255)) background.paste(_1,(0,0)) background.paste(_2,(380,0)) background.show() clipboard.set_image(background)
'Non-retina iPad': 75 } for amount in reduction_amounts: if reduction_amounts[amount] >= 100: print 'One of your reduction_amounts is too high, must be lower than 100.\nExample: If you want the resulting image to be 1/4 its original size, the reduction_amounts would be 25.' sys.exit() # This takes a max of 5 arguments including the title and message, # so you can really only put in 2 devices and 'Custom'. Set the two # you want here. # Make sure they match the string in reduction_amounts exactly! q1 = 'Retina iPhone' q2 = 'Non-retina iPad' if not clipboard.get_image(idx=0): print 'I don\'t think there are any images on the clipboard.' sys.exit() resizeAmountQ = console.alert( 'What percent of original size?', '', '{0}% (default for {1})'.format(reduction_amounts[q1], q1), '{0}% (default for {1})'.format(reduction_amounts[q2], q2), 'Custom') if resizeAmountQ == 1: resizeAmount = float(reduction_amounts[q1]) / 100 elif resizeAmountQ == 2: resizeAmount = float(reduction_amounts[q2]) / 100 elif resizeAmountQ == 3: resizeAmount = float( console.input_alert('What percent of original size?', 'Number only', '40')) / 100
# @viticci # Taken from Viticci :: https://github.com/viticci/pythonista-scripts # Imports two screenshots (iPhone 5) from the iOS clipboard and creates a single image # Based on: http://www.macstories.net/tutorials/a-better-way-to-combine-iphone-screenshots-with-keyboard-maestro/ # Images are pasted in order of Photos.app import clipboard import Image im1 = clipboard.get_image(idx=0) im2 = clipboard.get_image(idx=1) _1 = im1.resize((366, 650), Image.ANTIALIAS) _2 = im2.resize((366, 650), Image.ANTIALIAS) background = Image.new('RGBA', (746, 650), (255, 255, 255, 255)) background.paste(_1, (0, 0)) background.paste(_2, (380, 0)) background.show() clipboard.set_image(background)
def main(): filename = 'clipboard.jpg' image = clipboard.get_image() if not image: print 'Clipboard is empty! Please copy a picture to the clipboard and then restart the script again.' else: r = False q = 95 x = image.size[0] y = image.size[1] if (x > y): b = 'v' #vertical elif (y > x): b = 'h' #horizontal else: b = 's' #square mp = round(x * y / 1000000.0, 1) m = image.mode print 'Clipboard-Information:', print 'resolution = {} x {} ({} MP), mode = {}'.format(x, y, mp, m) print print '!!! Changing the resolution is time-consuming !!! Resolution higher 6000 x 4000 (24MP) can cause a abend!' print print '0 = Auto processing (Resolution = {} x {}), quality = 95%, mode = {}'.format(x, y, m) print '1 = Same resolution ({} x {})'.format(x, y) print '2 = Define resolution' print '3 = 3MP (2048 x 1536)' print '5 = 5MP (2592 x 1936)' o = int(raw_input('Resolution: ')) if o == 0: pic_save(image, m, x, y, q, r, filename) q = q / 100.0 elif o == 1: a = pic_para(m) m = a[0] q = a[1] pic_save(image, m, x, y, q, r, filename) elif o == 2: print print 'Changing the ratio causes picture deformation!' x2 = int(raw_input('Width: ')) y2 = int(raw_input('Height: ')) if (x2 == x and y2 == y): r = False else: r = True x = x2 y = y2 a = pic_para(m) m = a[0] q = a[1] pic_save(image, m, x, y, q, r, filename) elif o == 3: if (b == 'v' and x == 2048 and y == 1536): r = False x = 2048 y = 1536 elif (b == 'h' and x == 1536 and y == 2048): r = False x = 1536 y = 2048 else: r = True if (b == 'v' or b == 's'): x = 2048 y = 1536 else: x = 1536 y = 2048 a = pic_para(m) m = a[0] q = a[1] pic_save(image, m, x, y, q, r, filename) elif o == 5: if (b == 'v' and x == 2592 and y == 1936): r = False x = 2592 y = 1936 elif (b == 'h' and x == 1936 and y == 2592): r = False x = 1936 y = 2592 else: r = True if (b == 'v' or b == 's'): x = 2592 y = 1936 else: x = 1936 y = 2592 a = pic_para(m) m = a[0] q = a[1] pic_save(image, m, x, y, q, r, filename) else: print 'Cancel: ' + str(o) + ' is no valid input.' sys.exit() print 'Completed! Now you can open the picture and press Action > "Save Image ..." to get a copy to your photo gallery.' print 'Resolution = {} x {}, quality = {:.0f}%, mode = {}'.format(x, y, q*100, m), info = os.stat(filename) size = info.st_size if (size > 1048576): size = size / 1048576.0 print 'filesize = {0:.2f} MB'.format(size) elif (size > 1024): size = size / 1024.0 print 'filesize = {0:.1f} KB'.format(size) else: print 'filesize = ' + str(size) + ' Bytes'