• R/O
  • HTTP
  • SSH
  • HTTPS

otptools: 提交

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


Commit MetaInfo

修订版1585e16553b800d0ba027f74e4183b111e754b29 (tree)
时间2017-03-15 22:57:36
作者hylom <hylom@hylo...>
Commiterhylom

Log Message

fix size after resizing

更改概述

差异

--- a/sakura_imgswap.py
+++ b/sakura_imgswap.py
@@ -67,7 +67,7 @@ def replace_img_tag(line, tagstr, path):
6767 if 'width' in attrs:
6868 (w, h) = _get_png_geom(path)
6969 if int(w) > image_width:
70- attrs['height'] = str(h * image_width / w)
70+ attrs['height'] = str(int(round(float(h) * float(image_width) / float(w))))
7171 attrs['width'] = str(image_width)
7272 filename = '''%s-%sx%s%s''' % (root, attrs['width'], attrs['height'], ext)
7373 else:
--- a/wp_imgswap.py
+++ b/wp_imgswap.py
@@ -9,6 +9,7 @@ import codecs
99 import re
1010 import os.path
1111 import hashlib
12+import math
1213
1314 import htmltaglib
1415 import deterfile
@@ -34,14 +35,14 @@ except IndexError:
3435 link_prefix = ""
3536
3637 try:
37- max_image_width = int(sys.argv[5])
38+ max_image_width = float(sys.argv[5])
3839 except IndexError:
39- max_image_width = 480
40+ max_image_width = 480.0
4041
4142 try:
42- max_image_height = int(sys.argv[6])
43+ max_image_height = float(sys.argv[6])
4344 except IndexError:
44- max_image_height = 640
45+ max_image_height = 640.0
4546
4647 def _get_png_geom(filepath):
4748 s = filepath.split('.')
@@ -80,15 +81,15 @@ def replace_img_tag(line, tagstr, path):
8081 attrs['width'] = str(w)
8182 else:
8283 # use resized image
83- new_w = int(w)
84- new_h = int(h)
84+ new_w = float(w)
85+ new_h = float(h)
8586 if new_w > max_image_width:
86- new_h = h * max_image_width / w
87- new_w = max_image_width
87+ new_h = int(math.floor(h * max_image_width / w))
88+ new_w = int(max_image_width)
8889 print "replace width, %d %d" % (new_w, new_h)
8990 if new_h > max_image_height:
90- new_h = max_image_height
91- new_w = w * max_image_height / h
91+ new_h = int(max_image_height)
92+ new_w = int(math.floor(w * max_image_height / h))
9293 print "replace height, %d %d" % (new_w, new_h)
9394 attrs['height'] = str(new_h)
9495 attrs['width'] = str(new_w)
Show on old repository browser