def test_factors_unit(self): # Arrange import factors # Act mid1 = factors.get_middleish_factor(1) mid4 = factors.get_middleish_factor(4) mid12 = factors.get_middleish_factor(12) mid100 = factors.get_middleish_factor(100) # Assert self.assertEqual(mid1, 1) self.assertEqual(mid4, 2) self.assertEqual(mid12, 3) self.assertEqual(mid100, 10)
def create_average_in_batches(inspec): # Create in batches i = 0 batch_number = 0 batch = " " files = get_file_list(inspec) number = len(files) if args.batch_size == 'auto': import factors args.batch_size = factors.get_middleish_factor(number) print("Auto batch size:", args.batch_size) else: args.batch_size = int(args.batch_size) if args.batch_size == 1: print("No point using batch size of 1, create in one go instead") create_average_in_one_go(inspec) return number_of_batches = number/args.batch_size print("Number of files:", number) print("Number of batches:", number_of_batches) remainder = number % args.batch_size print("Remainder:", remainder) if remainder is not 0: print( "Warning: Get better results when batches are " "all the same size with zero remainder") temp_dir = create_temp_dir() for f in files: if i < (args.batch_size): # print(i) batch += '"' + f + '" ' i += 1 else: temp_file = os.path.join( temp_dir, TEMP_PREFIX + str(batch_number) + TEMP_SUFFIX) print("Batch number:", batch_number+1, "/", number_of_batches) print("Number in batch:", i) imagemagick_average(batch, temp_file) batch_number += 1 i = 0 batch = " " # print(batch) # print(i) # Now make an average from the temp files imagemagick_average(os.path.join( temp_dir, TEMP_PREFIX + "*" + TEMP_SUFFIX), args.outfile)
def create_average_in_batches(inspec): # Create in batches i = 0 batch_number = 0 batch = " " files = get_file_list(inspec) number = len(files) if args.batch_size == 'auto': import factors args.batch_size = factors.get_middleish_factor(number) print("Auto batch size:", args.batch_size) else: args.batch_size = int(args.batch_size) if args.batch_size == 1: print("No point using batch size of 1, create in one go instead") create_average_in_one_go(inspec) return number_of_batches = number/args.batch_size print("Number of files:", number) print("Number of batches:", number_of_batches) remainder = number % args.batch_size print("Remainder:", remainder) if remainder != 0: print( "Warning: Get better results when batches are " "all the same size with zero remainder") temp_dir = create_temp_dir() for f in files: if i < (args.batch_size): # print(i) batch += '"' + f + '" ' i += 1 else: temp_file = os.path.join( temp_dir, TEMP_PREFIX + str(batch_number) + TEMP_SUFFIX) print("Batch number:", batch_number+1, "/", number_of_batches) print("Number in batch:", i) imagemagick_average(batch, temp_file) batch_number += 1 i = 0 batch = " " # print(batch) # print(i) # Now make an average from the temp files imagemagick_average(os.path.join( temp_dir, TEMP_PREFIX + "*" + TEMP_SUFFIX), args.outfile)
def make( ncols_nrows, inspec, reverse, outfile, thumbsize, half, quarter, margins, padding, quality): ncols, nrows = ncols_nrows files = glob.glob(inspec) if len(files) == 0: sys.exit("No input files found.") if outfile in files: files.remove(outfile) # don't include any pre-existing montage if reverse: files = files[::-1] if not thumbsize: thumbsize = Image.open(files[0]).size if half: thumbsize = (thumbsize[0]/2, thumbsize[1]/2) elif quarter: thumbsize = (thumbsize[0]/4, thumbsize[1]/4) if args.aspect_ratio: ncols, nrows = aspect_ratio(len(files), thumbsize, args.aspect_ratio) if not nrows and not ncols: # Grab a middle-ish factor for the number of rows nrows = factors.get_middleish_factor(len(files)) if nrows and not ncols: ncols = len(files) // nrows elif not nrows and ncols: nrows = len(files) // ncols # print(len(files),ncols,nrows,ncols*nrows) print("Files:\t", len(files)) print("Rows:\t", nrows) print("Cols:\t", ncols) # Don't bother reading in files we aren't going to use if len(files) > ncols*nrows: files = files[:ncols*nrows] margins = [margins, margins, margins, margins] print("Making contact sheet") inew = make_contact_sheet( files, (ncols, nrows), thumbsize, margins, padding) print("Saving to", outfile) inew.save(outfile, quality=quality) print("Done.")
def make(ncols_nrows, inspec, reverse, shuffle, outfile, thumbsize, half, quarter, margins, padding, quality, bgcolour="white", thumbnail=False, flip=False): ncols, nrows = ncols_nrows files = sorted(glob.glob(inspec)) if len(files) == 0: sys.exit("No input files found.") if outfile in files: files.remove(outfile) # don't include any pre-existing montage if reverse: files = files[::-1] if shuffle: random.shuffle(files) if not thumbsize: thumbsize = Image.open(files[0]).size if half: thumbsize = (thumbsize[0] / 2, thumbsize[1] / 2) elif quarter: thumbsize = (thumbsize[0] / 4, thumbsize[1] / 4) if args.aspect_ratio: ncols, nrows = aspect_ratio(len(files), thumbsize, args.aspect_ratio) if not nrows and not ncols: # Grab a middle-ish factor for the number of rows nrows = factors.get_middleish_factor(len(files)) if nrows and not ncols: ncols = len(files) // nrows elif not nrows and ncols: nrows = len(files) // ncols # print(len(files),ncols,nrows,ncols*nrows) print("Files:\t", len(files)) print("Rows:\t", nrows) print("Cols:\t", ncols) # Don't bother reading in files we aren't going to use if len(files) > ncols * nrows: files = files[:ncols * nrows] margins = [margins, margins, margins, margins] print("Making contact sheet") inew = make_contact_sheet(files, (ncols, nrows), thumbsize, margins, padding, bgcolour, thumbnail, flip) print("Saving to", outfile) inew.save(outfile, quality=quality) print("Done.")