• R/O
  • HTTP
  • SSH
  • HTTPS

otptools: コミット

Open Tech Press向けの記事作成支援ツール


コミットメタ情報

リビジョン56d914350dcfc8481148922f6c96f1de5e2db55b (tree)
日時2013-05-13 18:52:17
作者hylom <hylom@hylo...>
コミッターhylom

ログメッセージ

fix: use thumbnail when figure size is smaller than thumbnail size

変更サマリ

差分

--- a/sakura_imgswap.py
+++ b/sakura_imgswap.py
@@ -19,6 +19,7 @@ usage = """usage: %s <target file> <output_file> <image_dir> [link_prefix] [imag
1919 rex_imgtag = re.compile(r"""<img\s+src=["'](.*?)["'].*?>""")
2020 rex_atag = re.compile(r"""<a\s+href=["'](.*?)["'].*?>""")
2121 rex_alt = re.compile(r"""alt=["'](.*?)["']""")
22+rex_figuretag = re.compile(r"""<figure\s+style=["'](.*?)["'].*?>""")
2223
2324 try:
2425 in_f = codecs.open(sys.argv[1], "r", "utf_8" )
@@ -60,21 +61,21 @@ def replace_img_tag(line, tagstr, path):
6061 return line
6162
6263 attrs = htmltaglib.parse_attributes(tagstr)
64+ (root, ext) = os.path.splitext(os.path.basename(path))
6365
66+ filename = ""
6467 if 'width' in attrs:
6568 (w, h) = _get_png_geom(path)
66- if int(w) != image_width:
69+ if int(w) > image_width:
6770 attrs['height'] = str(h * image_width / w)
6871 attrs['width'] = str(image_width)
72+ filename = '''%s-%sx%s%s''' % (root, attrs['width'], attrs['height'], ext)
6973 else:
7074 attrs['height'] = str(h)
7175 attrs['width'] = str(w)
76+ filename = '''%s%s''' % (root, ext)
7277
73- (root, ext) = os.path.splitext(os.path.basename(path))
74- wp_image_url = '''%s%s-%sx%s%s''' % (image_dir, root, attrs['width'], attrs['height'], ext)
75- else:
76- wp_image_url = image_dir + os.path.basename(path)
77-
78+ wp_image_url = '''%s%s''' % (image_dir, filename)
7879 attrs['src'] = wp_image_url
7980 # if tag has 'alt' attribute, use it
8081 if rex_alt.search(tagstr):
--- a/wp_imgswap.py
+++ b/wp_imgswap.py
@@ -68,6 +68,7 @@ def replace_img_tag(line, tagstr, path):
6868 attrs = htmltaglib.parse_attributes(tagstr)
6969 (root, ext) = os.path.splitext(os.path.basename(path))
7070
71+ filename = ""
7172 if 'width' in attrs:
7273 (w, h) = _get_png_geom(path)
7374 if int(w) > image_width:
@@ -79,7 +80,6 @@ def replace_img_tag(line, tagstr, path):
7980 attrs['width'] = str(w)
8081 filename = '''%s%s''' % (root, ext)
8182
82-
8383 wp_image_url = '''%s%s''' % (image_dir, filename)
8484 attrs['src'] = wp_image_url
8585 # if tag has 'alt' attribute, use it
旧リポジトリブラウザで表示