def download_file(url, tgt_fd):
    from time import sleep
    print('F**k you bitch, download it yourself...')
    sleep(5)
    print('Well f**k, if you insist...')

    outfile = tgt_fd.buffer

    print('Requesting \''+url+'\'')
    response = api.request(url)
    size = len(response.content)

    strlen = 0
    progress = 0
    for data in response.iter_content(chunk_size=4096):
        if data:
            outfile.write(data)
            outfile.flush()
            progress += len(data)
            g = tools.gauge(progress / size, 20, format='\r    Downloading... [%s]')
            s = g + ' ' + tools.format_data(progress, 2) + ' / ' + tools.format_data(size, 2)
            s += ' ' * (strlen - len(s))
            strlen = len(s)
            sys.stdout.write(s)
            sys.stdout.flush()
    sys.stdout.write('\n')
    sys.stdout.flush()
def find_final_img_char_width(kwargs):
    font_aspect_ratio = font_tools.get_aspect_ratio(kwargs['font_path'])
     
     
    #read in the text that will be colored to show a picture
#     print('reading in data text file...') 
    data = tools.read_text_file(kwargs['input_text_file_path'])
     
    #turn list of lines of data into one big string, use that to get number of chars in data, then split it into words
#     print('formatting data into word list...')
    data_str  = tools.format_data(data)
    num_chars = len(data_str)
    word_list = data_str.split(' ')
     
     
    #turn true_dimension_ratio into max number of lines and max chars per line
#     print('calculating ideal text image dimensions...')
    #find correct image dimensions by adjusting desired ratio for the difference between width and height of a char
    true_dimension_ratio = kwargs['output_image_dim_ratio'] * font_aspect_ratio
    ideal_dimentions = tools.calc_ideal_dimentions(true_dimension_ratio, num_chars)
     
    #make list of lines to be output in final image
#     print('creating text lines...')
    lines = tools.make_correct_lines(ideal_dimentions['num_lines'], ideal_dimentions['line_length'], word_list)
    
    return len(tools.find_longest_line(lines))
def build_unknown_char_dl(input_lines_t, font_path):
    unknown_char_dl = []

    font = TTFont(font_path)
    input_str = tools.format_data(input_lines_t)

    #     print(len(input_str))#```````````````````````````````````````````````````````````````````````````````````````````
    #     print(len(input_lines_t[0]))

    #add to unknown_char_dl when find a new char that is unknown to the font

    for char_num, char in enumerate(input_str):
        if tools.char_in_font(char, font) == False and new_unkown_char(
                tools.char_2_unicode(char), unknown_char_dl) == True:

            unknown_char_dl.append({
                'correct_char':
                None,
                'unknown_char_unicode':
                tools.char_2_unicode(char),
                '#_occurrences':
                1,
                'example':
                build_unknown_char_example(char_num, input_str, font)
            })

    return unknown_char_dl
Beispiel #4
0
 def response_handler(response):
     if self.temp_file == None:
         size = len(response.content)
         delay = tools.get_delay(self)
         self.print(
             tools.format_data(size, 2) + '  \t' +
             str(round(delay, 2)) + ' s    \t' +
             tools.format_data(size / delay, 2) + '/s')
         fd, temp_file = tempfile.mkstemp(
             '_e621dl.' + self.file_ext, str(self.id),
             tempfile.gettempdir() + config.TEMP_SUBD_DIR)
         with open(temp_file, 'wb') as outfile:
             outfile.write(response.content)
         #self.print('Downloaded ' + str(self.id))
         os.close(fd)
         self.temp_file = temp_file
     try:
         file_handler((self, self.temp_file))
         clear_load_flag(None)
     except Exception as e:
         self.print(e)
Beispiel #5
0
 def response_handler(response):
     if self.temp_preview == None:
         size = len(response.content)
         delay = tools.get_delay(self)
         self.print(
             tools.format_data(size, 2) + '  \t' +
             str(round(delay, 2)) + ' s    \t' +
             tools.format_data(size / delay, 2) + '/s')
         ext = self.preview_url[::-1].split('.')[0][::-1]
         fd, temp_preview = tempfile.mkstemp(
             '_preview_e621dl.' + ext, str(self.id),
             tempfile.gettempdir() + config.TEMP_SUBD_DIR)
         with open(temp_preview, 'wb') as outfile:
             outfile.write(response.content)
         #self.print('Downloaded ' + str(self.id) + ' preview')
         os.close(fd)
         self.temp_preview = temp_preview
     try:
         file_handler((self, self.temp_preview))
         clear_load_flag(None)
     except Exception as e:
         self.print(e)
def find_max_font_size(font_path, text_file_path, output_dim_ratio):

    #     return 23#```````````````````````````````````````````````````````````````````````````````````````````````````

    print('getting font aspect ratio...')
    font_aspect_ratio = get_aspect_ratio(font_path)

    #read in the text that will be colored to show a picture
    print('reading in data text file...')
    data = tools.read_text_file(text_file_path)

    #turn list of lines of data into one big string, use that to get number of chars in data, then split it into words
    print('formatting data into word list...')
    data_str = tools.format_data(data)
    num_chars = len(data_str)
    word_list = data_str.split(' ')

    #turn true_dimension_ratio into max number of lines and max chars per line
    print('calculating ideal text image dimensions...')
    #find correct image dimensions by adjusting desired ratio for the difference between width and height of a char
    true_dimension_ratio = output_dim_ratio * font_aspect_ratio
    ideal_dimentions = tools.calc_ideal_dimentions(true_dimension_ratio,
                                                   num_chars)

    #     return 22#``````````````````````````````````````````````````````````````````````````````````````````````

    #make list of lines to be output in final image
    print('creating text lines...')
    lines = tools.make_correct_lines(ideal_dimentions['num_lines'],
                                     ideal_dimentions['line_length'],
                                     word_list)

    #     return 23#``````````````````````````````````````````````````````````````````````````````````````````````

    dummy_font_size = global_constants.MAX_FONT_SIZE_STR  #this whole section needs a lot of cleaning!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    #     return 24#``````````````````````````````````````````````````````````````````````````````````````````````
    font = make_font(font_path, dummy_font_size, lines)
    print(
        'returning perfect font size'
    )  #``````````````````````````````````````````````````````````````````````````````````````
    return font.size
Beispiel #7
0
def build_final_image(kwargs):

    start_time = timer.time()

    #     print(kwargs)#````````````````````````````````````````````````````````````````````````````````````````````````````````
    print('kwargs: ')

    #     print(args)
    #```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
    for key, value in kwargs.items():
        print('  %s : %s' % (key, value))
    print(' ')

    #IF IMAGE STARTS LOOKING WEIRD, LOOK INTO WHY SOMETIMES IN COLOR_CORDS,
    #THERE ARE 2 OF THE SAME CORD IN ONE COLOR'S LIST, COULD HAVE TO DO WITH ROUNDING? NOT SURE IF IT EFFECTS OTHER THINGS

    #MUST USE MONO-SPACED FONTS
    #high resolution images will give better results

    #might also be helpful for making big images: https://stackoverflow.com/questions/3397157/how-to-read-a-raw-image-using-pil?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
    #reading raw data: http://effbot.org/zone/pil-large-images.htm

    # why is there a space in front of every line?

    # make this work for filtering    dont clean this up until filtering works !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    #set this to None for no background color separation #there is a reason for this!  this trims the whitespace so that image size can be more consistent!!!!!!!!!!!!
    #     input_image_background_color = kwargs['input_image_background_color'] #(255, 255, 255) #gui not done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    #background
    #replace this bull shit with something to  deal with whitespace
    default_colors = {  #'background_image':        (100,100,100),#(255,255,255),#white
        'final_image_background': kwargs['final_image_background_color'],
        'default_text': kwargs['background_text_color']
    }

    save_image = True
    if len(kwargs['output_image_file_path']) == 0:
        save_image = False

#     print('font_size:', kwargs['font_size'])#``````````````````````````````````````````````````````````````````````````

    print('getting font aspect ratio...')
    font_aspect_ratio = font_tools.get_aspect_ratio(kwargs['font_path'])

    #read in the text that will be colored to show a picture
    print('reading in data text file...')
    data = tools.read_text_file(kwargs['input_text_file_path'])

    #turn list of lines of data into one big string, use that to get number of chars in data, then split it into words
    print('formatting data into word list...')
    data_str = tools.format_data(data)
    num_chars = len(data_str)
    word_list = data_str.split(' ')

    #turn true_dimension_ratio into max number of lines and max chars per line
    print('calculating ideal text image dimensions...')
    #find correct image dimensions by adjusting desired ratio for the difference between width and height of a char
    true_dimension_ratio = kwargs['output_image_dim_ratio'] * font_aspect_ratio
    ideal_dimentions = tools.calc_ideal_dimentions(true_dimension_ratio,
                                                   num_chars)

    #make list of lines to be output in final image
    print('creating text lines...')
    lines = tools.make_correct_lines(ideal_dimentions['num_lines'],
                                     ideal_dimentions['line_length'],
                                     word_list)
    #     print('lines: ' , lines)#````````````````````````````````````````````````````````````````````````````````````````````````````````````````
    #     print("number of lines:", len(lines))#````````````````````````````````````````````````````````````````````````````````````````````````````````
    #     tools.write_text_file('TEST_LINES_TXT.txt', lines)#```````````````````````````````````````````````````````````````````````````````````````````

    print(
        'building unknown char list, MAKE SEPERATE BUTTON FO THIS STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '
    )  #`````````````````````````````````````
    unknown_char_list = font_tools.build_unknown_char_list(
        lines, kwargs['font_path'])
    #     print('  unknown char list:  ', len(unknown_char_list))

    print('building color_cords from input image...')
    og_color_cords = color_cords.get_color_cords(
        kwargs['input_image_file_path'], kwargs['image_size'],
        font_aspect_ratio, kwargs['input_image_background_color'],
        kwargs['background_text_color'])
    #     print('og_color_cords: ', og_color_cords)#`````````````````````````````````````````````````````````````````````````````````````````````````````````````````

    print(
        'calculating and adding user defined offset to adjusted_color_cords...'
    )
    offset_color_cords = offset.offset_color_cords(
        og_color_cords, kwargs['image_position_cords'], lines,
        kwargs['background_text_color'])

    print('making font...')
    font = font_tools.make_font(
        kwargs['font_path'], kwargs['font_size'], lines
    )  #font_tools.load_font(kwargs['font_path'], kwargs['font_size']) 1111111111111111111111111111

    import time  #```````````````````````````````````````````````````````````````````````````````````````````````````````````````````VVVVVVVVV`````````````````
    print(
        'sleeping'
    )  #````````````````````````````````````````````````````````````````````````````````````````````````````````````
    #     time.sleep(100)   # delays for 5 seconds. You can Also Use Float Value.
    print(
        'done sleeping'
    )  #`````````````````````````````````````````````````````````````````````````````````````````````````````````

    #put it all together and what have you got?  Bippity Boppity BOO!
    print('creating final image...')
    image = text_image.text_image(lines, offset_color_cords, default_colors,
                                  font)  #offset_adjusted_

    if save_image == True:
        # image.save('test_output.jpg', format='JPEG', subsampling=0,quality = 100)
        print('saving high-resolution image...')
        image.save(kwargs['output_image_file_path'],
                   subsampling=0,
                   quality=100)

    print('showing low-resolution image...')
    image.show()

    end_time = timer.time()
    print('Time elapsed: ', end_time - start_time)

    print('done!')