alt support added for thumbnailed images
This commit is contained in:
parent
0bf5da8bd1
commit
9512004e93
1 changed files with 37 additions and 17 deletions
|
|
@ -46,6 +46,7 @@ def thumbnail(image, name, args, size=(450,450)):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# size = (450, 450)
|
# size = (450, 450)
|
||||||
|
alt = ''
|
||||||
im = Image.open(image)
|
im = Image.open(image)
|
||||||
exif = None
|
exif = None
|
||||||
try:
|
try:
|
||||||
|
|
@ -79,13 +80,21 @@ def thumbnail(image, name, args, size=(450,450)):
|
||||||
cap = caption(image)
|
cap = caption(image)
|
||||||
else:
|
else:
|
||||||
cap = name
|
cap = name
|
||||||
|
# alt
|
||||||
|
alt_path = image + ".alt"
|
||||||
|
if os.path.isfile(alt_path):
|
||||||
|
f = open(alt_path, 'r', encoding='utf-8')
|
||||||
|
while True:
|
||||||
|
line = f.readline()
|
||||||
|
if not line: break
|
||||||
|
alt = alt + line + ' '
|
||||||
return (
|
return (
|
||||||
"<figure><a href='{}'><img class='thumbnail' src='data:image/jpg;base64,{}'></a><figcaption>{}</figcaption></figure>"
|
"<figure><a href='{}'><img class='thumbnail' src='data:image/jpg;base64,{}' alt='{}'></a><figcaption>{}</figcaption></figure>"
|
||||||
).format(name, data_url, cap)
|
).format(name, data_url, alt, cap)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print('Thumbnailer:', e)
|
print('Thumbnailer:', e)
|
||||||
return "<figure><a href='{}'><img src='{}'></a><figcaption>{}</figcaption></figure>".format(name, name, name)
|
return "<figure><a href='{}'><img src='{}' alt='{}'></a><figcaption>{}</figcaption></figure>".format(name, name, alt, name)
|
||||||
|
|
||||||
|
|
||||||
def div(args, type_, subtype, tag, name, fid):
|
def div(args, type_, subtype, tag, name, fid):
|
||||||
|
|
@ -202,15 +211,6 @@ def render_dir(args, directory):
|
||||||
|
|
||||||
if type_ == 'image':
|
if type_ == 'image':
|
||||||
a = FILE_TYPES[type_].format(relative_path, c, c)
|
a = FILE_TYPES[type_].format(relative_path, c, c)
|
||||||
if args.thumbnail:
|
|
||||||
thumbconf_path = "./{}/{}".format(root, "thumbconf.json")
|
|
||||||
size = (450, 450)
|
|
||||||
if os.path.isfile(thumbconf_path):
|
|
||||||
with open(thumbconf_path) as json_file:
|
|
||||||
json_data = json.load(json_file)
|
|
||||||
size = tuple(json_data['size'])
|
|
||||||
print("applying thumbconf.json: size: ", size)
|
|
||||||
a = thumbnail(full_path, relative_path, args, size)
|
|
||||||
if args.no_filenames:
|
if args.no_filenames:
|
||||||
c = ""
|
c = ""
|
||||||
if args.captions:
|
if args.captions:
|
||||||
|
|
@ -227,6 +227,16 @@ def render_dir(args, directory):
|
||||||
alt = alt + line + ' '
|
alt = alt + line + ' '
|
||||||
|
|
||||||
a = FILE_TYPES[type_].format(relative_path, alt, c)
|
a = FILE_TYPES[type_].format(relative_path, alt, c)
|
||||||
|
# if thumbnail, override.
|
||||||
|
if args.thumbnail:
|
||||||
|
thumbconf_path = "./{}/{}".format(root, "thumbconf.json")
|
||||||
|
size = (450, 450)
|
||||||
|
if os.path.isfile(thumbconf_path):
|
||||||
|
with open(thumbconf_path) as json_file:
|
||||||
|
json_data = json.load(json_file)
|
||||||
|
size = tuple(json_data['size'])
|
||||||
|
print("applying thumbconf.json: size: ", size)
|
||||||
|
a = thumbnail(full_path, relative_path, args, size)
|
||||||
|
|
||||||
if subtype in SUB_TYPES:
|
if subtype in SUB_TYPES:
|
||||||
a = SUB_TYPES[subtype]
|
a = SUB_TYPES[subtype]
|
||||||
|
|
@ -339,6 +349,16 @@ def distribusify(args, directory, freg): # noqa
|
||||||
alt = alt + line + ' '
|
alt = alt + line + ' '
|
||||||
|
|
||||||
a = FILE_TYPES[type_].format(name, alt, c)
|
a = FILE_TYPES[type_].format(name, alt, c)
|
||||||
|
# # if thumbnail, override.
|
||||||
|
# if args.thumbnail:
|
||||||
|
# thumbconf_path = "./{}/{}".format(root, "thumbconf.json")
|
||||||
|
# size = (450, 450)
|
||||||
|
# if os.path.isfile(thumbconf_path):
|
||||||
|
# with open(thumbconf_path) as json_file:
|
||||||
|
# json_data = json.load(json_file)
|
||||||
|
# size = tuple(json_data['size'])
|
||||||
|
# print("applying thumbconf.json: size: ", size)
|
||||||
|
# a = thumbnail(full_path, relative_path, args, size)
|
||||||
|
|
||||||
if subtype in SUB_TYPES:
|
if subtype in SUB_TYPES:
|
||||||
a = SUB_TYPES[subtype]
|
a = SUB_TYPES[subtype]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue