Пример #1
0
def get_images_from_md(md_text):
    '''get a list of images and their thumbnails from markdown text'''
    text_md_subst, img_blocks = preprocess_md(md_text)

    thumbs_abspath = os.path.join( current_app.config['RUN_ABSPATH'],
                                   'media/thumbs' )

    images = []
    for img_block in img_blocks:
        image_src = img_block[1]
        image_thumb = os.path.join('/media/thumbs', os.path.basename(image_src))

        # handle "external" images
        if image_src.startswith('http://'):
            image_thumb = image_src
            image_src = 'External URL: ' + image_src

        image = { 'src': image_src,
                  'thumb': image_thumb }

        images.append(image)

        # generate thumbnail
        image_abspath = os.path.join( current_app.config['RUN_ABSPATH'],
                                      os.path.relpath(image_src, '/') )
        # (debug output)
        #sys.stderr.write('\nRUN_ABSPATH:'+str(current_app.config['RUN_ABSPATH']))
        #sys.stderr.write('\nIMG SRC:'+image_src)
        make_thumb_samename(image_abspath, thumbs_abspath)

    return images
Пример #2
0
def process_image(image_file, image_dir, ref):
    '''process image data
- exif information
- insert image in db
- create thumbnail
'''
    image_file_abspath = os.path.join(image_dir, image_file)

    # extract exif into json
    if os.path.splitext(image_file)[1] in current_app.config['JPEG_EXTS']:
        img_exif = ExifNice(image_file_abspath)
        if img_exif.has_exif:
            exif_json = img_exif.get_json()
            datetime_norm = datetimesec_norm( img_exif.datetime,
                                              "%Y:%m:%d %H:%M:%S" )
        # --> set defaults in ExifNice !!
        else:
            exif_json = ""
            datetime_norm = ""
    else:
        exif_json = ""
        datetime_norm = ""

    # add thumb ref
    thumb_ref = os.path.join('thumbs', image_file)

    # insert in db
    db_insert_image( ref,
                     thumb_ref,
                     datetime_norm,
                     exif_json,
                     gallery_id )

    # create thumbnail if not exists
    # (existence is checked in function --> maybe better check here ? ==> No, WTF?)
    make_thumb_samename(image_file_abspath, thumbs_abspath)