• R/O
  • HTTP
  • SSH
  • HTTPS

otptools: Commit

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


Commit MetaInfo

Revision3cec808899621e1ef46c0a7cd53c041b272a8fc2 (tree)
Time2013-04-24 19:30:02
Authorhylom <hylom@hylo...>
Commiterhylom

Log Message

fix: change filename and figure size when figure size is large

Change Summary

Incremental Difference

--- a/wp_imgswap.py
+++ b/wp_imgswap.py
@@ -66,21 +66,21 @@ def replace_img_tag(line, tagstr, path):
6666 return line
6767
6868 attrs = htmltaglib.parse_attributes(tagstr)
69+ (root, ext) = os.path.splitext(os.path.basename(path))
6970
7071 if 'width' in attrs:
7172 (w, h) = _get_png_geom(path)
72- if int(w) != image_width:
73+ if int(w) > image_width:
7374 attrs['height'] = str(h * image_width / w)
7475 attrs['width'] = str(image_width)
76+ filename = '''%s-%sx%s%s''' % (root, attrs['width'], attrs['height'], ext)
7577 else:
7678 attrs['height'] = str(h)
7779 attrs['width'] = str(w)
80+ filename = '''%s%s''' % (root, ext)
7881
79- (root, ext) = os.path.splitext(os.path.basename(path))
80- wp_image_url = '''%s%s-%sx%s%s''' % (image_dir, root, attrs['width'], attrs['height'], ext)
81- else:
82- wp_image_url = image_dir + os.path.basename(path)
8382
83+ wp_image_url = '''%s%s''' % (image_dir, filename)
8484 attrs['src'] = wp_image_url
8585 # if tag has 'alt' attribute, use it
8686 if rex_alt.search(tagstr):
@@ -105,7 +105,15 @@ def replace_a_tag(line, tagstr, path):
105105
106106 def replace_figure_tag(line, tagstr, path):
107107 attrs = htmltaglib.parse_attributes(tagstr)
108- attrs['style'] = "width:480px;"
108+ width = image_width
109+ if 'style' in attrs:
110+ m = re.search(ur'width:\s*([0-9]+)px', attrs['style'])
111+ if m:
112+ w = int(m.group(1))
113+ if w <= 480:
114+ width = w
115+
116+ attrs['style'] = "width:" + str(width) + "px;"
109117 new_tag_str = htmltaglib.build_tag('figure', attrs)
110118
111119 return line.replace(tagstr, new_tag_str)
Show on old repository browser