From 6609c852d4137a364523681aa6ca77c881a07780 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Tue, 29 Jul 2008 10:33:00 +0545 Subject: [PATCH] Implement image scaling --- geekigeeki.conf.py | 1 + geekigeeki.py | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/geekigeeki.conf.py b/geekigeeki.conf.py index 2b00389..eba3843 100644 --- a/geekigeeki.conf.py +++ b/geekigeeki.conf.py @@ -16,4 +16,5 @@ datetime_fmt = '%a %d %b %Y %I:%M %p' allow_edit = True # Is it possible to edit pages? show_hosts = True # show hostnames? nonexist_pfx = '' # prefix before nonexistent link (usually '?') +image_maxwidth = 800 # maximum image width in pixels debug_cgi = False # Set to True for CGI var dump diff --git a/geekigeeki.py b/geekigeeki.py index dba75a2..f704da5 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -361,11 +361,18 @@ class WikiFormatter: name = m.group(1) descr = m.group(2) or name name = relative_url(name) + argv = descr.split('|') + descr = argv.pop(0) + if argv: + args = '?' + '&'.join(argv) + else: + args = '' if descr: # The "extthumb" nonsense works around a limitation of the HTML block model - return '
%s
%s
' % (name, name, descr, descr) + return '
%s
%s
' \ + % (name, name + args, descr, descr) else: - return '' % (name, name) + return '' % (name, name + args) def _email_repl(self, word): return '%s' % (word, word) @@ -571,10 +578,18 @@ class Page: raise er def format_dir(self): - out = '' + out = '== ' + path = '' + for dir in self.page_name.split('/'): + path = (path + '/' + dir) if path else dir + out += '[[' + path + '|' + dir + ']]/' + out += ' ==\n' + for file in page_list(self._filename(), file_re): if img_re.match(file): - out += ' * {{' + self.page_name + '/' + file + '}}\n' + if image_maxwidth: + maxwidth_arg = '|maxwidth=' + str(image_maxwidth) + out += '{{' + self.page_name + '/' + file + '|' + file + maxwidth_arg + '}}\n' else: out += ' * [[' + self.page_name + '/' + file + ']]\n' return out @@ -690,6 +705,16 @@ class Page: else: send_title(None, msg_text='Read access denied by ACLs', msg_type='notice') + def send_image(self, mimetype, args=[]): + if 'maxwidth' in args: + import subprocess + emit_header(mimetype) + sys.stdout.flush() + subprocess.check_call(['gm', 'convert', self._filename(), + '-scale', args['maxwidth'].value + ' >', '-']) + else: + self.send_raw(mimetype) + def _write_file(self, data): tmp_filename = self._tmp_filename() open(tmp_filename, 'wb').write(data) @@ -752,8 +777,15 @@ try: else: from mimetypes import MimeTypes type, encoding = MimeTypes().guess_type(query) - type = type or 'text/plain' - Page(query).send_raw(mimetype=type) + #type = type or 'text/plain' + #Page(query).send_raw(mimetype=type) + if type: + if type.startswith('image/'): + Page(query).send_image(mimetype=type,args=form) + else: + Page(query).send_raw(mimetype=type) + else: + Page(query).format() else: print "Status: 404 Not Found" send_title(None, msg_text='Can\'t work out query: ' + query) -- 2.25.1