def generate_images_old_version(sentence_filename,
                                output_dir,
                                img_url_dir,
                                fontName='Times New Roman'):
    """
   Saves image representations of the sentences to the output dir.
   The file name contains the article ID and the segment number.
   """
    sentences = read_lines_from_file(sentence_filename)
    seg_ids = read_lines_from_file(sentence_filename + '.seg_ids')
    img_urls = []
    width = 350
    extension = 'png'
    # create a placeholder file in case we have an odd number of segments
    dnt_filename = output_dir + '/do-not-translate.png'
    retval = str2img("Do not translate this sentence.",
                     font=fontName,
                     output=dnt_filename,
                     width=width)
    # create images for all sentences
    for i, sentence in enumerate(sentences):
        seg_id = seg_ids[i]
        sentence = format_for_image(sentence)
        img_outputfile = '%s/%s.%s' % (output_dir, seg_id, extension)
        retval = str2img(sentence,
                         font=fontName,
                         output=img_outputfile,
                         width=width)
        img_url = '%s/%s.%s' % (img_url_dir, seg_id, "png")
        img_urls.append(img_url)
    return img_urls
def generate_images_old_version(sentence_filename, output_dir, img_url_dir, fontName='Times New Roman'):
   """
   Saves image representations of the sentences to the output dir.
   The file name contains the article ID and the segment number.
   """
   sentences = read_lines_from_file(sentence_filename)
   seg_ids = read_lines_from_file(sentence_filename + '.seg_ids')
   img_urls = []
   width = 350
   extension = 'png'
   # create a placeholder file in case we have an odd number of segments
   dnt_filename = output_dir + '/do-not-translate.png'
   retval = str2img("Do not translate this sentence.", font=fontName, output=dnt_filename, width=width)
   # create images for all sentences
   for i, sentence in enumerate(sentences):
       seg_id = seg_ids[i]
       sentence = format_for_image(sentence)
       img_outputfile = '%s/%s.%s' % (output_dir, seg_id, extension)
       retval = str2img(sentence, font=fontName, output=img_outputfile, width=width)
       img_url = '%s/%s.%s' % (img_url_dir, seg_id, "png")
       img_urls.append(img_url)
   return img_urls
Esempio n. 3
0
def _gen_text_image(sentence, output_path):
    """
    dunno
    """
    web_path = DEFAULT_WEB_PATH
    width = DEFAULT_PYDJANGO_WIDTH
    extension = 'png'
    output = '%s/%s.%s' % (output_path, sentence.id, extension)
    dataurl = '%s/%s.%s' % (web_path, sentence.id, extension)
    retval = str2img(sentence.text,
                     #font='Nafees',
                     output=output,
                     width=width)
    data = {
        'type': 'image',
        'subtype': extension,
        'file_path': output,
        'dataurl': dataurl,
        'width': width,
        'sentence': sentence.text,
    }
    return data
Esempio n. 4
0
def _gen_text_image(sentence, output_path):
    """
    dunno
    """
    web_path = DEFAULT_WEB_PATH
    width = DEFAULT_PYDJANGO_WIDTH
    extension = 'png'
    output = '%s/%s.%s' % (output_path, sentence.id, extension)
    dataurl = '%s/%s.%s' % (web_path, sentence.id, extension)
    retval = str2img(
        sentence.text,
        #font='Nafees',
        output=output,
        width=width)
    data = {
        'type': 'image',
        'subtype': extension,
        'file_path': output,
        'dataurl': dataurl,
        'width': width,
        'sentence': sentence.text,
    }
    return data