Exemplo n.º 1
0
    def process(self, image):

        logging.info('Processing %s', image.url)

        imageSizing = self.settings.getUser('imagesizing')

        # Get the starting point
        filename = os.path.join(self.settings.get('tempfolder'), image.id)

        # Make sure it's oriented correctly
        filename = helper.autoRotate(filename)

        # At this point, we have a good image, store it if allowed
        if image.cacheAllow and not image.cacheUsed:
            self.cacheMgr.setCachedImage(filename, image.getCacheId())

        # Frame it
        if imageSizing == 'blur':
            filename = helper.makeFullframe(filename,
                                            self.settings.getUser('width'),
                                            self.settings.getUser('height'))
        elif imageSizing == 'zoom':
            filename = helper.makeFullframe(filename,
                                            self.settings.getUser('width'),
                                            self.settings.getUser('height'),
                                            zoomOnly=True)
        elif imageSizing == 'auto':
            filename = helper.makeFullframe(filename,
                                            self.settings.getUser('width'),
                                            self.settings.getUser('height'),
                                            autoChoose=True)

        # Color match it
        return self._colormatch(filename)
Exemplo n.º 2
0
 def downloadImage(self, uri, dest):
     logging.debug('Downloading %s...' % uri)
     filename, ext = os.path.splitext(dest)
     temp = "%s-org%s" % (filename, ext)
     if self.oauth.request(uri, destination=temp):
         helper.makeFullframe(temp, self.settings.getUser('width'),
                              self.settings.getUser('height'))
         if self.colormatch.hasSensor():
             if not self.colormatch.adjust(temp, dest):
                 logging.warning(
                     'Unable to adjust image to colormatch, using original')
                 os.rename(temp, dest)
             else:
                 os.remove(temp)
         else:
             os.rename(temp, dest)
         return True
     else:
         return False
Exemplo n.º 3
0
 def process(self, filename):
     imageSizing = self.settings.getUser('imagesizing')
     if imageSizing == None or imageSizing == "none":
         return self._colormatch(filename)
     if imageSizing == 'blur':
         filenameProcessed = helper.makeFullframe(
             filename, self.settings.getUser('width'),
             self.settings.getUser('height'))
     elif imageSizing == 'zoom':
         filenameProcessed = helper.makeFullframe(
             filename,
             self.settings.getUser('width'),
             self.settings.getUser('height'),
             zoomOnly=True)
     elif imageSizing == 'auto':
         filenameProcessed = helper.makeFullframe(
             filename,
             self.settings.getUser('width'),
             self.settings.getUser('height'),
             autoChoose=True)
     return self._colormatch(filenameProcessed)
Exemplo n.º 4
0
 def downloadImage(self, photo_id, dest):
   #logging.debug('Downloading %s...' % uri)
   filename, ext = os.path.splitext(dest)
   temp = "%s-org%s" % (filename, ext)
   #picture      
   url = 'https://photoslibrary.googleapis.com/v1/mediaItems/'+photo_id
   data = self.oauth.request(url)
   if data.status_code == 200:
     if self.oauth.request(data.json()['baseUrl']+"=w"+str(self.settings.getUser("width"))+"-h"+str(self.settings.getUser("height")), destination=temp):
       if self.settings.getUser('blur') == 'activated':
         helper.makeFullframe(temp, self.settings.getUser('width'), self.settings.getUser('height'))
       if self.colormatch.hasSensor():
         if not self.colormatch.adjust(temp, dest):
           logging.warning('Unable to adjust image to colormatch, using original')
           os.rename(temp, dest)
         else:
           os.remove(temp)
       else:
         os.rename(temp, dest)
       return True
     else:
       return False
Exemplo n.º 5
0
    def presentation(self):
        self.services.getServices(readyOnly=True)

        if not slideshow.SHOWN_IP:
            slideshow.SHOWN_IP = True
            # Once we have IP, show for 10s
            cd = 10
            while (cd > 0):
                self.display.message('Starting in %d seconds' % (cd))
                cd -= 1
                time.sleep(1)
            self.display.clear()

        logging.info('Starting presentation')
        delay = 0
        useService = 0
        supportedFormats = [
            'image/jpeg', 'image/png', 'image/gif', 'image/bmp'
            # HEIF to be added once I get ImageMagick running with support
        ]

        self.delayer.clear()
        imageOnScreen = False
        while True:
            # Avoid showing images if the display is off
            if self.queryPowerFunc is not None and self.queryPowerFunc(
            ) is False:
                logging.info("Display is off, exit quietly")
                break

            # For now, just pick the first service
            time_process = time.time()

            services = self.services.getServices(readyOnly=True)
            if len(services) > 0:
                # Very simple round-robin
                if useService >= len(services):
                    useService = 0
                svc = services[useService]['id']

                filename = os.path.join(self.settings.get('tempfolder'),
                                        'image')
                result = self.services.servicePrepareNextItem(
                    svc, filename, supportedFormats, {
                        'width': self.settings.getUser('width'),
                        'height': self.settings.getUser('height'),
                        "orientation": self.settings.getUser("orientation")
                    })
                if result['error'] is not None:
                    self.display.message(
                        '%s failed:\n\n%s' %
                        (services[useService]['name'], result['error']))
                else:
                    self.imageMime = result['mimetype']
                    self.imageCurrent = filename

                    if self.settings.getUser('imagesizing') == 'blur':
                        helper.makeFullframe(filename,
                                             self.settings.getUser('width'),
                                             self.settings.getUser('height'))
                    elif self.settings.getUser('imagesizing') == 'zoom':
                        helper.makeFullframe(filename,
                                             self.settings.getUser('width'),
                                             self.settings.getUser('height'),
                                             zoomOnly=True)
                    elif self.settings.getUser('imagesizing') == 'auto':
                        helper.makeFullframe(filename,
                                             self.settings.getUser('width'),
                                             self.settings.getUser('height'),
                                             autoChoose=True)
                    if self.colormatch.hasSensor():
                        if not self.colormatch.adjust(filename):
                            logging.warning(
                                'Unable to adjust image to colormatch, using original'
                            )
                useService += 1
            else:
                self.display.message(
                    'Photoframe isn\'t ready yet\n\nPlease direct your webbrowser to\n\nhttp://%s:7777/\n\nand add one or more photo providers'
                    % self.settings.get('local-ip'))

            time_process = time.time() - time_process

            # Delay before we show the image (but take processing into account)
            # This should keep us fairly consistent
            if time_process < delay and (imageOnScreen
                                         or self.imageCurrent is None):
                triggered = self.delayer.wait(delay - time_process)
                self.delayer.clear()
                if triggered:
                    logging.info(
                        'Change of configuration, flush data and restart')
                    # We need to expunge any pending image now
                    # so we get fresh data to show the user
                    if self.imageCurrent:
                        os.remove(self.imageCurrent)
                        self.imageCurrent = None
                        imageOnScreen = False
                        self.display.clear()

            if self.imageCurrent is not None and os.path.exists(
                    self.imageCurrent):
                self.display.image(self.imageCurrent)
                os.remove(self.imageCurrent)
                imageOnScreen = True

            delay = self.settings.getUser('interval')
        self.thread = None