Hi,
This is how I solved the aspect ratio and got the caption from a Picasa edited photo, by using IPTCinfo and PIL Python libraries to get the information I needed.
This version works on a Pi2 OSMC (Kodi)**:
1) Install IPTCinfo (pip install iptcinfo)
2) Add PIL to the addon.xml
Code:
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.pil" version="1.1.7"/>
</requires>
Here's the main code. I only added it to the TableTop class because that's all I'm using. It could possibly need tidying further, but it works for me:
Code:
# open image and get dimensions and iptc info
ar = float(self.image_aspect_ratio)
image_url = image_url.replace("Pictures", "Pictures/")
ar = 1
wImg = 1280*2
hImg = 720*2
caption = ''
try:
img = Image.open(image_url)
# Create new info object
try:
info = IPTCInfo(image_url)
# Check if file had IPTC data
if len(info.data) >= 4:
# Get specific attributes...
caption = info.data['caption/abstract']
except:
caption = ''
imgSize = img.size
wImg = imgSize[0] #x width
hImg = imgSize[1] #y height
if hImg != 0:
ar = float(wImg) / float(hImg)
except IOError:
ar = 1
width = wImg
height = hImg
if height >= width and height > 720:
scale = height / 720.0
height = int(height / scale)
width = int(width / scale)
if width >= height and width > 1280:
scale = width / 1280.0
height = int(height / scale)
width = int(width / scale)
width = random.randint(width/3, width)
height = int(float(width) / ar)
while height > 700:
height = height - 10
width = width - 10
while width > 1260:
height = height - 10
width = width - 10
x_position = random.randint(0, 1280 -width)
y_position = random.randint(0, 720 - height)
drop_height = random.randint(400, 800)
drop_duration = drop_height * 1.5
rotation_degrees = random.uniform(-20, 20)
rotation_duration = drop_duration
cmd = 'XBMC.Notification("{header}", "{message}")'.format(
header='info',
message=caption
)
if caption:
xbmc.executebuiltin(cmd)
I had to turn the Kodi notification sounds off to stop the sound when the caption was being displayed & I made the photos change every 5s to match the notification pop-up time.
I had a problem with some image paths. They are all under Pictures\ however sometimes an image_url was like this ...PicturesDSC120013.jpg...i.e. the '\' after the folder name was missing, hence I add one before doing an Image.open().
I also tried PIL's _getexif() but it did not return the field with the Picasa comment.
An enhancement would be to test if a photo was taken rotated (it's in the EXIF I believe) & correct that before displaying.... I'll save that for another day,
Hope someone finds it useful.
Steve Russell
** 3/5/15 : Works in Windows too. I had to download the IPTCinfo package, manually unzip & copy the iptcinfo.py file into the multi photo slide show's addons folder under Users/Appdata/Roaming......kodi/addons. There's probably a better/correct place to put the package, but I didn't have time to look it up.
Much better than my old Google Photo Screensaver solution - I can have the same setup across Pi & Windows platforms on the TVs around my house. I can also modify the code to do anything else.... show time, show weather, show track playing info..... good work Sphere.