Beispiel #1
0
    def combine_images(self, final_image_path):
        width_diff = 0
        if self.get_current_aspect_ratio() > get_screen_aspect_ratio():
            # need to add more height to the image
            image_width = self.get_total_size(RedditImage.WIDTH)
            image_height = int(image_width // get_screen_aspect_ratio())
        else:
            # need to add more width to the image

            image_height = self.get_max_size(RedditImage.HEIGHT)
            combined_width = self.get_total_size(RedditImage.WIDTH)
            image_width = int(image_height * get_screen_aspect_ratio())
            width_diff = (image_width - combined_width) // (len(self.selectedImages) - 1)

        temp = Image.new("RGB", (image_width, image_height))

        log("Start Image Combining Process")
        beg_x = 0
        nextColor = None
        for pic in self.selectedImages:
            portrait = Image.open(pic.imagePath).convert('RGB')
            if nextColor is not None:
                # make gradient for in between images
                currColor = average_pixel_color(portrait, LEFT)
                do_gradient(temp, (beg_x - width_diff, 0), (beg_x, image_height - 1), nextColor, currColor)
            nextColor = average_pixel_color(portrait, RIGHT)
            height_factor = (image_height - RedditImage.get_size_data(pic, RedditImage.HEIGHT)) // 2
            temp.paste(portrait, (beg_x, height_factor))
            beg_x += RedditImage.get_size_data(pic, RedditImage.WIDTH) + width_diff

        log("Save Resulting Image")
        temp.save(final_image_path, format="JPEG")
        log("Combined Image Saved")
Beispiel #2
0
    def do_daily_iteration(self):
        log("Start Daily Iteration", is_heading=True)
        self.incorrect_aspect = []
        self.correct_aspect = []
        dailyDirectory = os.path.join(dest_directory, "DailySource")
        remove_all_files(dailyDirectory)
        progressBar = None
        try:
            urls = self.get_submissions_for_subreddit("day")
            log("URLS Gathered")

            totalCount = len(urls)
            if self.args.show_progress:
                progressBar = Bar("Downloading Daily Images",
                                  max=totalCount,
                                  suffix='%(index)d / %(max)d  %(percent)d%%')
                progressBar.start()
            # get suitable image for desktop background
            while len(urls) != 0:
                # select specific url at random
                attempt, urls = get_random_url(urls)
                image_url, post_permalink = attempt
                log("Process URL:", image_url, "URLS Left:", len(urls))

                # save first attempt at okay file url
                imageObj = RedditImage(image_url, post_permalink)
                imageObj.get_image_from_url(dailyDirectory)
                if not imageObj.image_downloaded():
                    continue

                if imageObj.image_is_landscape():
                    self.correct_aspect.append(imageObj)
                else:
                    self.incorrect_aspect.append(imageObj)
                if progressBar is not None:
                    progressBar.next()
                log("URL has been processed")

            if progressBar is not None:
                progressBar.finish()
                progressBar = None

            RedditDatabase().insert_images(self.correct_aspect +
                                           self.incorrect_aspect)
            if len(self.incorrect_aspect) > 0:
                log("Start Image Combining Process")
                ci = CombineImages(self.incorrect_aspect, dest_directory)
                log("Save Resulting Image")
                pathOfResult = ci.do_combine_landscape_process()
                RedditDatabase().insert_combined(ci)
                log("Set Image as Desktop Background")
                RedditImage.set_image_to_desktop_background(pathOfResult)
            else:
                self.correct_aspect[0].set_to_desktop_background()
        finally:
            # cleanup all images that had been temporarily downloaded
            if progressBar is not None:
                progressBar.finish()
Beispiel #3
0
 def insert_image(self, image_object: RedditImage):
     if image_object.imageObj is not None:
         return image_object.imageObj.imageId
     image_object.create_image_model()
     self.session.add(image_object.imageObj)
     self.session.commit()
Beispiel #4
0
    def insert_combined(self, combined_object: CombineImages):
        images = combined_object.get_selected_images()
        combine_id = self.get_next_combineid()
        objects = []
        for index, image in enumerate(images):
            self.insert_image(image)
            obj = combined.Combined(combine_id, image.imageObj.imageId, index)
            objects.append(obj)
            self.session.add(obj)

        self.session.commit()
        combined_object.combineId = combine_id

    def insert_images(self, image_objects: List[RedditImage]):
        [self.insert_image(x) for x in image_objects]

    def insert_image(self, image_object: RedditImage):
        if image_object.imageObj is not None:
            return image_object.imageObj.imageId
        image_object.create_image_model()
        self.session.add(image_object.imageObj)
        self.session.commit()


if __name__ == "__main__":
    obj = RedditDatabase.get_object()
    temp = RedditImage("url", "submissionurl")
    obj.insert_image(temp)
    print(obj.get_next_primary("images"))
Beispiel #5
0
    def do_weekly_iteration(self):
        if RedditAPI.should_run_weekly():
            log("Start Weekly Iteration", is_heading=True)
            initialSource = os.path.join(base_directory, "PictureSource",
                                         "LockScreenSource")
            finalSource = os.path.join(base_directory, "PictureSource",
                                       "LockScreen")
            remove_all_files(initialSource)
            remove_all_files(finalSource)
            progressBar = None
            try:
                weekly_urls = self.get_submissions_for_subreddit("week")
                log("URLS Gathered")
                totalCount = len(weekly_urls)
                landscape = []
                portrait = []
                if self.args.show_progress:
                    progressBar = Bar(
                        "Downloading Weekly Images",
                        max=totalCount,
                        suffix='%(index)d / %(max)d  %(percent)d%%')
                    progressBar.start()

                with open(
                        os.path.join(base_directory, "PictureSource",
                                     "lockScreenStat.txt"), "w") as f:
                    while len(weekly_urls) > 0:
                        # select specific url at random
                        attempt, urls = get_random_url(weekly_urls)
                        image_url, post_permalink = attempt

                        log("Process URL:", image_url, "URLS Left:", len(urls))

                        # get image and save if able
                        imageObj = RedditImage(image_url, post_permalink)
                        imageObj.get_image_from_url(initialSource)
                        if imageObj.image_is_landscape():
                            landscape.append(imageObj)
                        else:
                            portrait.append(imageObj)
                        if imageObj.image_downloaded():
                            f.write(str(imageObj) + "\n")

                        if progressBar is not None:
                            progressBar.next()

                        log("URL has been processed")

                    if progressBar is not None:
                        progressBar.finish()

                    for imageObj in landscape:
                        imageObj.move_to_folder(finalSource)
                        print("did the copy")

                    RedditDatabase().insert_images(landscape + portrait)

                    # iterate through creating landscape photos
                    resulting = CombineImages.iterate_combine_landscape(
                        portrait, finalSource)
                    RedditDatabase().insert_all_combined(resulting)
                self.set_weekly_run_file()
            finally:
                if progressBar is not None:
                    progressBar.finish()
Beispiel #6
0
 def get_max_size(self,  size_type):
     max_item = RedditImage.get_size_data(self.selectedImages[0], size_type)
     for image in self.selectedImages[1:]:
         max_item = max(max_item, RedditImage.get_size_data(image, size_type))
     return max_item
Beispiel #7
0
 def get_total_size(self, size_type):
     item = 0
     for image in self.selectedImages:
         item += RedditImage.get_size_data(image, size_type)
     return item
Beispiel #8
0
    urls = ["https://i.redd.it/jo7eoqh9gue41.jpg",
         "https://i.imgur.com/EutiMfe.jpg",
         "https://i.redd.it/99qky2zx6ve41.png",
         "https://i.redd.it/fszcdofojue41.jpg",
         "https://i.redd.it/wwt28ys8lue41.jpg",
         "https://i.redd.it/bmdk44wvmxe41.png",
         "https://i.redd.it/slraqbhomxe41.png",
         "https://i.redd.it/lzitvr0hxue41.jpg",
         "https://i.redd.it/olcckyd4iue41.jpg"]

    imageObjects = []
    # get image objects for urls
    dest_directory = os.path.join(base_directory, "PictureSource")
    for url in urls:
        print(url)
        imageObj = RedditImage(url, "")
        imageObj.get_image_from_url(dest_directory)
        imageObj.image_is_landscape()
        imageObjects.append(imageObj)

    ci = CombineImages(imageObjects, dest_directory)
    pathOfResult = ci.do_combine_landscape_process()
    for imageObj in imageObjects:
        imageObj.cleanup()
    print(pathOfResult)

    exit(0)
    # test gradient util method
    test = Image.new("RGB", (1000, 1000), (0, 0, 0))

    do_gradient(test, (0, 0), (1000, 1000), (117, 103, 108), (178, 156, 111))