Skip to content

Instantly share code, notes, and snippets.

@mygeekdaddy
Created February 27, 2017 18:21
Show Gist options
  • Save mygeekdaddy/d1c7a1059ac51d802830f6bf46d785a4 to your computer and use it in GitHub Desktop.
Save mygeekdaddy/d1c7a1059ac51d802830f6bf46d785a4 to your computer and use it in GitHub Desktop.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# The MIT License (MIT)
#
# Copyright 2015 Adam Pritchard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
# and associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
import clipboard
from PIL import Image
import console
import photos
console.clear()
console.alert("Pick first image", "", "Select")
img1 = photos.pick_asset()
img1 = img1.get_image()
console.alert("Pick second image", "", "Select")
img2 = photos.pick_asset()
img2 = img2.get_image()
console.show_activity()
w1, h1 = img1.size
w2, h2 = img2.size
# Set the width and height of each image
img1_w = img1.size[0]
img1_h = img1.size[1]
img2_w = img2.size[0]
img2_h = img1.size[1]
def image_merge(img):
if (img1_w * 1.0) / img1_h > 1:
# Landscape screenshot
print("Landscape screenshot...")
background = Image.new('RGB', ((img1_w+20), ((img1_h*2)+30)), (88,88,88))
print ("Generating image...")
background.paste(img1,(10,10))
background.paste(img2,(10,(img1_h+20)))
photos.save_image(background)
print ("Image saved")
else:
#Portrait screenshot
print ("Portrait screenshot...")
background = Image.new('RGB', (((img1_w*2)+30),(img1_h+20)), (88, 88, 88))
print ("Generating image...")
background.paste(img1,(10,10))
background.paste(img2,((img1_w+20),10))
photos.save_image(background)
print("Image saved")
if img1_w == img2_w:
image_merge(img1)
print("Done...")
else:
console.alert("Incorrect image ratio", "", "Ok")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment