Пример #1
0
 def __init__(self, width, height):
     self.frame = (0, 0, width, height)
     self.iwidth = 200.0
     self.iheight = 150.0
     framesize = 5
     iw = self.iwidth - 2 * framesize
     ih = self.iheight - 2 * framesize
     ratio = ih / iw
     self.img = []
     self.imgcount = photos.get_count()
     if self.imgcount < 100:
         console.hud_alert(
             'Please wait while {} photos are loading...'.format(
                 self.imgcount))
     else:
         console.hud_alert('Please wait while 100 photos are loading...')
         self.imgcount = 100
     for i in range(self.imgcount):
         img = ui.Image.from_data(photos.get_image(i, raw_data=True))
         w, h = img.size
         rat = h / w
         x_ratio = 1.0
         y_ratio = 1.0
         x = framesize
         y = framesize
         if rat > ratio:  #portrait
             x = ((iw - ih * rat) / 2) + framesize
             x_ratio = ih * rat / iw
         else:  #landscape
             y = ((ih - iw * rat) / 2) + framesize
             y_ratio = iw * rat / ih
         with ui.ImageContext(self.iwidth, self.iheight) as ctx:
             img.draw(x, y, iw * x_ratio, ih * y_ratio)
             self.img.append(ctx.get_image())
Пример #2
0
def show_photo(filename):
    parse_photoid = re.compile(r"photo(\d+)(_thmb)?\.jpg\Z")
    r = parse_photoid.match(filename)
    if r != None:
        if not users.check_permission_to_view(session, int(r.group(1))):
            return "Ei oikeuksia"
        return photos.get_image(filename)
    return "kuvaa ei ole"
Пример #3
0
    def __init__(self, width, height):
        self.frame = (0, 0, width, height)
        self.iwidth = 200.0
        self.iheight = 200.0
        framesize = 10
        iw = self.iwidth - 2 * framesize
        ih = self.iheight - 2 * framesize

        ratio = ih / iw
        self.img = []
        self.imgcount = min(photos.get_count(), 100)
        console.hud_alert(
            "Please wait while {} photos are loading...".format(self.imgcount)
        )
        for i in range(self.imgcount):
            s = photos.get_metadata(i)
            if s["filename"][-3:] == "MOV":  # skip movies
                self.img.append(None)
                continue
            img = ui.Image.from_data(photos.get_image(i, raw_data=True))
            w, h = img.size
            rat = h / w
            x_ratio = 1.0
            y_ratio = 1.0
            x = framesize
            y = framesize

            if ratio < 1:  # landscape canvas
                if rat <= ratio:  # full width
                    y = ((ih - iw * rat) / 2) + framesize
                    y_ratio = iw * rat / ih
                else:  # full height
                    x = ((iw - ih / rat) / 2) + framesize
                    x_ratio = ih / rat / iw
            elif ratio > 1:  # portrait canvas
                if rat > ratio:  # full height
                    x = ((iw - ih / rat) / 2) + framesize
                    x_ratio = ih / rat / iw
                else:  # full width
                    y = ((ih - iw * rat) / 2) + framesize
                    y_ratio = iw * rat / ih
            else:  # cubic canvas
                if rat < 1:  # full width
                    y = ((ih - iw * rat) / 2) + framesize
                    y_ratio = iw * rat / ih
                elif rat > 1:  # full height
                    x = ((iw - ih / rat) / 2) + framesize
                    x_ratio = ih / rat / iw
                else:  # cubic
                    pass  # x_ratio = y_ratio = 1.0
            with ui.ImageContext(self.iwidth, self.iheight) as ctx:
                img.draw(x, y, iw * x_ratio, ih * y_ratio)
                self.img.append(ctx.get_image())
Пример #4
0
 def __init__(self, width, height):
     self.frame = (0,0,width,height)
     self.iwidth = 200.0
     self.iheight = 200.0
     framesize = 10
     iw = self.iwidth - 2 * framesize
     ih = self.iheight - 2 * framesize
     
     ratio = ih / iw
     self.img = []
     self.imgcount = min(photos.get_count(), 100)
     console.hud_alert('Please wait while {} photos are loading...'.format(self.imgcount))
     for i in xrange(self.imgcount):
         s = photos.get_metadata(i)
         if s['filename'][-3:] == 'MOV':     #skip movies
             self.img.append(None)
             continue
         img = ui.Image.from_data(photos.get_image(i,raw_data=True))
         w, h = img.size
         rat = h / w
         x_ratio = 1.0
         y_ratio = 1.0
         x = framesize
         y = framesize
         
         if ratio < 1:      #landscape canvas
             if rat <= ratio:     #full width
                 y = ((ih - iw * rat) / 2) + framesize
                 y_ratio = iw * rat / ih
             else:                #full height
                 x = ((iw - ih / rat) / 2) + framesize
                 x_ratio = ih / rat / iw
         elif ratio > 1:    #portrait canvas
             if rat > ratio:      #full height
                 x = ((iw - ih / rat) / 2) + framesize
                 x_ratio = ih / rat / iw
             else:                #full width
                 y = ((ih - iw * rat) / 2) + framesize
                 y_ratio = iw * rat / ih
         else:              #cubic canvas
             if rat < 1:          #full width
                 y = ((ih - iw * rat) / 2) + framesize
                 y_ratio = iw * rat / ih
             elif rat > 1:        #full height
                 x = ((iw - ih / rat) / 2) + framesize
                 x_ratio = ih / rat / iw
             else:                #cubic
                 pass             #x_ratio = y_ratio = 1.0
         with ui.ImageContext(self.iwidth, self.iheight) as ctx:
             img.draw(x,y,iw * x_ratio,ih * y_ratio)
             self.img.append(ctx.get_image())
Пример #5
0
 def make_image_view(self, image_name=''):  # fullscreen background image
     image_view = ui.ImageView(frame=self.bounds)
     image_view.image = ui.Image.from_data(photos.get_image(raw_data=True))
     return image_view
Пример #6
0
main_view = ui.load_view('Views/gallery')
scroll = main_view['scrollview1']


def photo_fill(view, amount, spacing=32, source=[], y_offset=0, exceptions=[]):
    view.content_size = (2000, 2000)
    [view.add_subview(ui.ImageView()) for i in range(0, amount)]
    for i in range(len(view.subviews)):
        curr = view.subviews[i]
        prev = view.subviews[i - 1]
        if curr not in exceptions:
            curr.y = y_offset
            curr.image = ui.Image().from_data(random.choice(source))
            if i != 0:
                if curr.x < view.width:
                    curr.x = prev.x + spacing
            print(curr.x, curr.y)


# GETTING THERE!!!!
image_array = [
    'emj:Alien', 'emj:Angry', 'emj:Anger_Symbol', 'emj:Alien_Monster',
    'emj:Ambulance', 'emj:Airplane', 'emj:Artist_Palette', 'emj:Anchor',
    'emj:Bath', 'emj:Bug'
]
roll_array = [
    photos.get_image(x, raw_data=True) for x in range(random.randint(0, 100))
]
excep = [scroll]
main_view.present()
photo_fill(scroll, 20, 100, exceptions=excep, source=roll_array, y_offset=100)
    [view.add_subview(ui.ImageView()) for i in range(0, amount)]
    for i in range(len(view.subviews)):
        curr = view.subviews[i]
        prev = view.subviews[i - 1]
        if curr not in exceptions:
            curr.y = y_offset
            curr.image = ui.Image().from_data(random.choice(source))
            if i != 0:
                if curr.x < view.width:
                    curr.x = prev.x + spacing
            print(curr.x, curr.y)


# GETTING THERE!!!!
image_array = [
    "emj:Alien",
    "emj:Angry",
    "emj:Anger_Symbol",
    "emj:Alien_Monster",
    "emj:Ambulance",
    "emj:Airplane",
    "emj:Artist_Palette",
    "emj:Anchor",
    "emj:Bath",
    "emj:Bug",
]
roll_array = [photos.get_image(x, raw_data=True) for x in range(random.randint(0, 100))]
excep = [scroll]
main_view.present()
photo_fill(scroll, 20, 100, exceptions=excep, source=roll_array, y_offset=100)
Пример #8
0
import clipboard
import bitly
import datetime

def get_extension():
	ext = 'jpg'
	photo_meta = photos.get_metadata(-1).keys()
	if '{PNG}' in photo_meta:
		ext = 'png'
	elif '{GIF}' in photo_meta:
		ext = 'gif'
	elif '{TIFF}' and '{Exif}' in photo_meta:
		ext = 'jpg'	
	return ext
		
last_pic = photos.get_image(-1)
extension = get_extension()

base = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
filename = base + '.' + extension

pic_read = StringIO.StringIO()
last_pic.save(pic_read, extension)

USER = '******'
PASS = keychain.get_password('cloudapp', USER)

API_URL = 'http://my.cl.ly/items/new'

s = requests.Session()
s.auth = requests.auth.HTTPDigestAuth(USER, PASS)
Пример #9
0
# 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: ")

if formatType == "x":
Пример #10
0
 def make_image_view(self, image_name=''):  # fullscreen background photo
     image_view = ui.ImageView(frame=self.bounds)
     image_view.image = ui.Image.from_data(photos.get_image(raw_data=True))
     return image_view
Пример #11
0
# 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: ")

if formatType == "x":
Пример #12
0
import datetime


def get_extension():
    ext = 'jpg'
    photo_meta = photos.get_metadata(-1).keys()
    if '{PNG}' in photo_meta:
        ext = 'png'
    elif '{GIF}' in photo_meta:
        ext = 'gif'
    elif '{TIFF}' and '{Exif}' in photo_meta:
        ext = 'jpg'
    return ext


last_pic = photos.get_image(-1)
extension = get_extension()

base = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
filename = base + '.' + extension

pic_read = StringIO.StringIO()
last_pic.save(pic_read, extension)

USER = '******'
PASS = keychain.get_password('cloudapp', USER)

API_URL = 'http://my.cl.ly/items/new'

s = requests.Session()
s.auth = requests.auth.HTTPDigestAuth(USER, PASS)
Пример #13
0
# coding: utf-8
# MORE TRIAL AND ERROR
import ui,photos,random
from PIL import Image

main_view = ui.load_view('Views/gallery')
scroll = main_view['scrollview1']


# GETTING THERE!!!!
image_array=['emj:Alien','emj:Angry','emj:Anger_Symbol','emj:Alien_Monster','emj:Ambulance','emj:Airplane','emj:Artist_Palette','emj:Anchor','emj:Bath','emj:Bug']
roll_array = [photos.get_image(x,raw_data=True) for x in range(0,9)]
excep = [scroll]
main_view.present()
offset=45
def fill(view,amount,spacing=32,source=[],y_offset=0,exceptions=[]):
	[view.add_subview(ui.ImageView()) for i in range(0,amount)]
	for i in range(len(view.subviews)):
		curr = view.subviews[i]
		prev = view.subviews[i-1]
		if curr not in exceptions:
			curr.y=y_offset
			curr.image = ui.Image().named(random.choice(source))
			if i!=0:
				if curr.x<view.width:
					curr.x=prev.x+spacing
			print (curr.x,curr.y)
fill(scroll,50,3,image_array,0)


def photo_fill(view,amount,spacing=32,source=[],y_offset=0,exceptions=[]):