def update_photolist(self, new_images): if new_images: self.opts.last_visited_dir = os.path.dirname( os.path.abspath(new_images[-1])) try: photolist = [] if self.history_index < len(self.history): photolist = copy.copy( self.history[self.history_index].photolist) photolist.extend(render.build_photolist(new_images)) if len(photolist) > 0: new_collage = UserCollage(photolist) new_collage.make_page(out_h=self.opts.out_h, out_w=self.opts.out_w) self.render_from_new_collage(new_collage) else: self.update_tool_buttons() except render.BadPhoto as e: dialog = ErrorDialog( self, _("This image could not be opened:\n\"%(imgname)s\".") % {"imgname": e.photoname}) dialog.run() dialog.destroy()
def make_poster(filename, new_images, args): photolist = [] photolist.extend(render.build_photolist(new_images)) opts = Options(args) if len(photolist) > 0: new_collage = UserCollage(photolist) new_collage.make_page(opts) save_poster(filename, opts, new_collage)
def run(args): tmp_file = [] tmp_file_photo = [] if args.user: if args.mode == "owned": url = owned_url elif args.mode == "ordered": url = ordered_url p = requests.get(url.format(args.user)).content url_re = re.compile(r'\<a href="\/item\/(\d+)"') fig_ids = re.findall(url_re, p) for i in fig_ids: u = img_url.format(i) q = requests.get(u).content print("Downloading " + u) if not q or len(q) < 300: u = img_url_big.format(i) print("Retrying " + u) q = requests.get(u).content fp = tempfile.NamedTemporaryFile() fp.write(q) fp.flush() tmp_file.append(fp) elif args.input: for r, d, f in os.walk(args.input): for file in f: tmp_file.append(open(os.path.join(r, file), 'rb')) if args.randomize: random.shuffle(tmp_file) total_x = total_y = 0 harmonic_mean_sum = 0 for i in tmp_file: with Image.open(i.name) as img: total_x += img.size[0] total_y += img.size[1] ratio = (1 / (float(total_y) / total_x)) harmonic_mean_sum += ratio harmonic_mean = len(tmp_file) / harmonic_mean_sum print(harmonic_mean) if not args.collage or args.collage == 1: tmp_file_names = map(lambda x: x.name, tmp_file) res = make_collage(tmp_file_names, args.output, int(300 * math.sqrt(len(tmp_file))), \ harmonic_mean * 300, enlarge=False) elif args.collage == 2: tmp_file_photo = build_photolist(tmp_file) pa = Page(min(4800, total_y / 2), harmonic_mean * 3, int(math.sqrt(len(tmp_file)) * 2)) for t in tmp_file_photo: pa.add_cell(t) pa.adjust() t = RenderingTask(pa, output_file=args.output, quality=QUALITY_BEST) t.start() print("Done")
def make_collage(filename, new_images, width, height): photolist = [] photolist.extend(render.build_photolist(new_images)) opts = Options(width, height, 1, 'black') if len(photolist) > 0: new_collage = UserCollage(photolist) new_collage.make_page(opts) save_poster(filename, opts, new_collage).join() return filename return ''
def __init__(self, image_list, border_w=0.01, border_c='black', out_w=800, out_r=1.0): assert len(image_list) > 0, 'Empty image list !!' super(PhotoCollage, self).__init__() self.history = [] self.history_index = 0 class Options(object): def __init__(self, border_w=0.01, border_c='black', out_w=800, out_h=600): self.border_w = border_w self.border_c = border_c self.out_w = out_w self.out_h = out_h self.opts = Options(border_w, border_c, out_w, int(out_w/out_r)) self.photo_list = render.build_photolist(image_list) self.collage = UserCollage(self.photo_list) self.collage.make_page(self.opts)
def update_photolist(self, new_images): try: photolist = [] if self.history_index < len(self.history): photolist = copy.copy( self.history[self.history_index].photolist) photolist.extend(render.build_photolist(new_images)) if len(photolist) > 0: new_collage = UserCollage(photolist) new_collage.make_page() self.render_from_new_collage(new_collage) else: self.update_tool_buttons() except render.BadPhoto as e: dialog = ErrorDialog( self, _("This image could not be opened:\n\"%(imgname)s\".") % {"imgname": e.photoname}) dialog.run() dialog.destroy()
def update_photolist(self, new_images): try: photolist = [] if self.history_index < len(self.history): photolist = copy.copy( self.history[self.history_index].photolist) photolist.extend(render.build_photolist(new_images)) if len(photolist) > 0: new_collage = UserCollage(photolist) new_collage.make_page(self.opts) self.render_from_new_collage(new_collage) else: self.update_tool_buttons() except render.BadPhoto as e: dialog = ErrorDialog( self, _("This image could not be opened:\n\"%(imgname)s\".") % {"imgname": e.photoname}) dialog.run() dialog.destroy()
def create_collage_for_place(place_id, filename): #place_id = "ChIJc3Lll6YEdkgRPJboSPvZGwQ" photos = fetch_photos_for_place_id(place_id, 5) photolist = [] for photo in photos: print(photo) response = requests.get(photo) photolist.append(io.BytesIO(response.content)) collage = UserCollage(build_photolist(photolist)) collage.make_page(Options()) os.makedirs(os.path.dirname(filename), exist_ok=True) t = RenderingTask(collage.page, output_file=filename, quality=2, on_fail=on_fail) t.start() t.join(5) if not os.path.exists(filename): return None return filename
if os.path.splitext(fn)[1].lower() in ('.jpg', '.jpeg', '.png') ] random.shuffle(img_paths) ##################################################################### # Options ##################################################################### out_h = 10000 out_w = 20000 savefile = 'collage_01.jpg' ##################################################################### # Run ##################################################################### photolist = render.build_photolist(img_paths) mycollage = collage.UserCollage(photolist) mycollage.make_page(out_h, out_w) print(mycollage.page) enlargement = float(out_w) / mycollage.page.w mycollage.page.scale(enlargement) t = render.RenderingTask(mycollage.page, output_file=savefile) t.start() t.is_alive == True
if len(args.folder) != 0: if args.recurse: for dir_path, dirs, files in os.walk(args.folder): for file in files: filename, file_extension = os.path.splitext(file) if file_extension in ( ".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG"): filenames.append(os.path.join(dir_path, file)) for entry in os.scandir(args.folder): if entry.is_file(): filename, file_extension = os.path.splitext(entry.name) if file_extension in ( "png", "PNG", "jpg", "JPG", "jpeg", "JPEG"): filenames.append(entry.name) photo_list = render.build_photolist(filenames) for photo in photo_list: if float(photo.w) / float(photo.h) > args.max_ratio: photo_list.remove(photo) if len(filenames) == 0: print("No images found.") exit(-1) i = 0 counter = 0 while i < args.amount: random.shuffle(photo_list) number_of_images = random.randint(args.min, args.max)