diff -urN saku-3.7.3/file/saku.ini saku-3.7.3-thi/file/saku.ini --- saku-3.7.3/file/saku.ini 2007-10-06 21:37:14.000000000 +0900 +++ saku-3.7.3-thi/file/saku.ini 2010-06-27 17:13:04.000000000 +0900 @@ -7,3 +7,6 @@ [Network] port: 8000 upnp: yes + +[Application Thread] +thumbnail_size: 400x400 diff -urN saku-3.7.3/file/sample.ini saku-3.7.3-thi/file/sample.ini --- saku-3.7.3/file/sample.ini 2009-12-13 23:18:19.000000000 +0900 +++ saku-3.7.3-thi/file/sample.ini 2010-06-27 16:28:46.000000000 +0900 @@ -122,3 +122,9 @@ # Page size for mobile mobile_page_size: 10 + +# Make thumbnail and thumbnai size. (max x-size "x" max y-size) +thumbnail_size: 400x400 + +# Auto make thumbnail another size. (yes/no) +force_thumbnail: yes diff -urN saku-3.7.3/shingetsu/cache.py saku-3.7.3-thi/shingetsu/cache.py --- saku-3.7.3/shingetsu/cache.py 2008-10-19 15:34:37.000000000 +0900 +++ saku-3.7.3-thi/shingetsu/cache.py 2010-06-27 17:14:05.000000000 +0900 @@ -44,6 +44,8 @@ from tag import * from tiedobj import * +import PIL.Image + __version__ = '$Revision: 1467 $' __all__ = ['Record', 'Cache', 'CacheList', 'UpdateList', 'RecentList'] @@ -238,7 +240,18 @@ else: return False - def attach_path(self, suffix=None): + def allthumbnail_path(self): + if self.path == "": + sys.stderr.write("Null file name\n") + return None + dir = "/".join((config.cache_dir, self.datfile, "attach")) + thumbnail = [] + for i in listdir(dir): + if i.startswith("s" + self.idstr): + thumbnail.append("/".join((dir, i))) + return thumbnail + + def attach_path(self, suffix=None, thumbnail_size=None): if self.path == "": sys.stderr.write("Null file name\n") return None @@ -247,15 +260,18 @@ suffix = re.sub(r"[^-_.A-Za-z0-9]", "", suffix) if suffix == "": suffix = "txt" - return dir + "/" + self.idstr + "." + suffix + if thumbnail_size is not None: + return dir + "/" + "s" + self.idstr + "." + thumbnail_size + "." + suffix + else: + return dir + "/" + self.idstr + "." + suffix for i in listdir(dir): if i.startswith(self.idstr): return dir + "/" + i return None - def attach_size(self, path=None): + def attach_size(self, path=None, thumbnail_size=None): if path is None: - path = self.attach_path() + path = self.attach_path(suffix=None, thumbnail_size=thumbnail_size) if path is None: return 0 else: @@ -275,6 +291,24 @@ sys.stderr.write(path + ": IOError\n") return False + def make_thumbnail(self, suffix=None, thumbnail_size=config.thumbnail_size): + if thumbnail_size is not None: + if suffix is None: + suffix = self.get('suffix', 'jpg') + attach_path = self.attach_path(suffix=suffix) + thumbnail_path = self.attach_path(suffix=suffix, thumbnail_size=thumbnail_size) + if not os.path.isfile(thumbnail_path): + size = thumbnail_size.split("x") + if len(size) == 2: + size = (int(size[0]), int(size[1])) + try: + im = PIL.Image.open(attach_path) + im.thumbnail(size, PIL.Image.ANTIALIAS) + im.save(thumbnail_path) + except IOError, err: + pass + return + def sync(self, force=False): """Save files.""" if self.removed(): @@ -291,6 +325,7 @@ self._write_file(self.body_path, body) if force or (not fsdiff(attach_path, attach)): self._write_file(attach_path, attach) + self.make_thumbnail() elif 'sign' in self: if force or (not fsdiff(self.body_path, body)): self._write_file(self.body_path, body) @@ -355,6 +390,9 @@ """ try: shutil.move(self.path, self.rm_path) + for path in self.allthumbnail_path(): + if path and os.path.isfile(path): + os.remove(path) for path in (self.body_path, self.attach_path()): if path and os.path.isfile(path): os.remove(path) diff -urN saku-3.7.3/shingetsu/config.py saku-3.7.3-thi/shingetsu/config.py --- saku-3.7.3/shingetsu/config.py 2010-01-01 20:44:42.000000000 +0900 +++ saku-3.7.3-thi/shingetsu/config.py 2010-06-27 16:22:55.000000000 +0900 @@ -132,6 +132,12 @@ mobile_page_size = _get_value(_extconf, 'Application Thread', 'mobile_page_size', 10, 'int') +thumbnail_size = _get_value(_extconf, + 'Application Thread', + 'thumbnail_size', None, '') +force_thumbnail = _get_value(_extconf, + 'Application Thread', + 'force_thumbnail', False, 'boolen') client_cycle = 5*60 # Seconds; Access client.cgi ping_cycle = 5*60 # Seconds; Check nodes diff -urN saku-3.7.3/shingetsu/thread_cgi.py saku-3.7.3-thi/shingetsu/thread_cgi.py --- saku-3.7.3/shingetsu/thread_cgi.py 2010-01-01 20:42:31.000000000 +0900 +++ saku-3.7.3-thi/shingetsu/thread_cgi.py 2010-06-27 16:55:32.000000000 +0900 @@ -41,6 +41,8 @@ from cache import * from tag import UserTagList +import os.path + __version__ = "$Revision: 1488 $" @@ -79,11 +81,19 @@ self.print_thread(path) return + #found = re.search(r"^(thread_[0-9A-F]+)/([0-9a-f]{32})/(\d+)\.(\d+)x(\d+)\.(.*)", + found = re.search(r"^(thread_[0-9A-F]+)/([0-9a-f]{32})/s(\d+)\.(\d+x\d+)\.(.*)", + path) + if found: + (datfile, stamp, id, thumbnail_size, suffix) = found.groups() + self.print_attach(datfile, stamp, id, suffix, thumbnail_size) + return + found = re.search(r"^(thread_[0-9A-F]+)/([0-9a-f]{32})/(\d+)\.(.*)", path) if found: (datfile, stamp, id, suffix) = found.groups() - self.print_attach(datfile, stamp, id, suffix) + self.print_attach(datfile, stamp, id, suffix, None) return form = cgi.FieldStorage(environ=self.environ, fp=self.stdin) @@ -230,12 +240,18 @@ self.footer() def print_record(self, cache, rec, path, str_path): + thumbnail_size = None if 'attach' in rec: attach_file = rec.attach_path() attach_size = rec.attach_size(attach_file) suffix = rec.get('suffix', '') if not re.search('^[0-9A-Za-z]+$', suffix): suffix = 'txt' + (type, null) = mimetypes.guess_type("test." + suffix) + if type is None: + type = "text/plain" + if attachutil.is_valid_image(type, attach_file): + thumbnail_size = config.thumbnail_size else: attach_file = None attach_size = None @@ -256,6 +272,7 @@ 'suffix': suffix, 'body': body, 'res_anchor': self.res_anchor, + 'thumbnail': thumbnail_size, } self.stdout.write(self.template('record', var)) @@ -269,7 +286,7 @@ } self.stdout.write(self.template('post_form', var)) - def print_attach(self, datfile, id, stamp, suffix): + def print_attach(self, datfile, id, stamp, suffix, thumbnail_size=None): """Print attachment.""" cache = Cache(datfile) (type, null) = mimetypes.guess_type("test." + suffix) @@ -286,12 +303,16 @@ if not rec.exists(): self.print404(cache) return - attach_file = rec.attach_path() + attach_file = rec.attach_path(suffix=suffix, thumbnail_size=thumbnail_size) + if config.thumbnail_size is not None and not os.path.isfile(attach_file): + if config.force_thumbnail or thumbnail_size == config.thumbnail_size: + rec.make_thumbnail(suffix=suffix, thumbnail_size=thumbnail_size) if attach_file is not None: + size = rec.attach_size(thumbnail_size=thumbnail_size) self.stdout.write( "Content-Type: " + type + "\n" + "Last-Modified: " + self.rfc822_time(stamp) + "\n" + - "Content-Length: " + str(rec.attach_size()) + "\n") + "Content-Length: " + str(size) + "\n") if not attachutil.is_valid_image(type, attach_file): self.stdout.write("Content-Disposition: attachment\n") self.stdout.write("\n") diff -urN saku-3.7.3/template/record.txt saku-3.7.3-thi/template/record.txt --- saku-3.7.3/template/record.txt 2009-12-13 23:18:19.000000000 +0900 +++ saku-3.7.3-thi/template/record.txt 2010-06-27 14:52:28.000000000 +0900 @@ -2,9 +2,6 @@ * Copyright (c) 2005-2008 shinGETsu Project. * $Id: record.txt 1480 2009-12-13 14:18:20Z fuktommy $ *# -#set images = ['jpg', 'gif', 'png'] -#set height = '210' -#set width = '160'
#if $isadmin @@ -32,8 +29,8 @@
[[$message['remove']: $res_anchor($rec['remove_id'][:8], $thread_cgi, $path)$rec['remove_id'][:8]]] #end if -#if ('attach' in $rec) and ($suffix in $images): +#if $thumbnail is not None:
- + #end if