Description

When a user in gui mode shrinks or inlarges an image the changes do not save. I am attempting to resize through the use of the handles on the edges of the image.

Component selection

GUI

Details

This Wiki

Workaround

Discussion

May be we can insert ImageLink with the resize parameters

The problem could be fixed by using imagelink to atleast display the resizing (not a true resize, but it will keep the formating) using ImageLink in the converter from fck

the file that contains this info is:

MoinMoin.converter.text_html_text_x_moin.py

Under def process_img (currently line 1161)

referance to the HTML DOM Image Object

http://www.w3schools.com/htmldom/dom_obj_image.asp

if the image has a non-null height or width property output with the format of

[[ImageLink(Page/Image.jpg,height=100,width=100)]]

more info on [ImageLink]

Good work :)

the gui interface may need some more extensions:

If Image is used with that patch Image may be need some small modification because of the initialisation of None for the vars.

-- ReimarBauer 2006-12-20 20:24:13

Could not test the code above but here is a changed version for "Image" which also takes "=None" as parameter values. -- OliverSiemoneit 2006-12-21 11:25:10

That patch is based on a slighly modified Image routine for 1.6 dev 1701:3c6f59cafbbe -- ReimarBauer 2006-12-22 13:20:27

   1 # HG changeset patch
   2 # User ReimarBauer <R.Bauer@fz-juelich.de>
   3 # Node ID fc8309716597121ef100418d99f9947e483bfef4
   4 # Parent  3c6f59cafbbe442f90171a8b0680be67eb320a67
   5 resizing of images from gui using Image.
   6 
   7 diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/converter/text_html_text_moin_wiki.py
   8 --- a/MoinMoin/converter/text_html_text_moin_wiki.py	Thu Dec 21 03:39:57 2006 +0100
   9 +++ b/MoinMoin/converter/text_html_text_moin_wiki.py	Fri Dec 22 14:13:46 2006 +0100
  10 @@ -1179,13 +1179,28 @@ class convert_tree(visitor):
  11          alt = None
  12          if node.attributes.has_key("alt"):
  13              alt = node.attributes.get("alt").nodeValue
  14 -
  15 +        width = None
  16 +        if node.attributes.has_key("width"):
  17 +            width = node.attributes.get("width").nodeValue
  18 +        height = None
  19 +        if node.attributes.has_key("height"):
  20 +            height = node.attributes.get("height").nodeValue
  21          # Attachment image
  22          if (title and title.startswith("attachment:") and
  23              wikiutil.isPicture(wikiutil.url_unquote(title[len("attachment:"):]))):
  24 -            self.text.extend([self.white_space,
  25 -                              wikiutil.url_unquote(title),
  26 -                              self.white_space])
  27 +            if height == None and width == None:
  28 +                self.text.extend([self.white_space,
  29 +                                  wikiutil.url_unquote(title),
  30 +                                  self.white_space])
  31 +            else:
  32 +                self.text.extend([self.white_space,
  33 +                                  "[[Image(%(file)s,width=%(width)s,height=%(height)s,alt=%(alt)s)]]" % {
  34 +                                    "file": wikiutil.url_unquote(title[len("attachment:"):]),
  35 +                                    "width": width,
  36 +                                    "height": height,
  37 +                                    "alt": alt,
  38 +                                    },
  39 +                                  self.white_space])
  40          # Drawing image
  41          elif title and title.startswith("drawing:"):
  42              self.text.extend([self.white_space,
  43 diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/formatter/text_gedit.py
  44 --- a/MoinMoin/formatter/text_gedit.py	Thu Dec 21 03:39:57 2006 +0100
  45 +++ b/MoinMoin/formatter/text_gedit.py	Fri Dec 22 14:13:46 2006 +0100
  46 @@ -93,7 +93,33 @@ class Formatter(text_html.Formatter):
  47      # Dynamic stuff / Plugins ############################################
  48  
  49      def macro(self, macro_obj, name, args):
  50 -        if args is not None:
  51 +        if name == "Image" and args is not None:
  52 +            pagename = self.page.page_name
  53 +            if args:
  54 +                args = args.split(',')
  55 +                args = [arg.strip() for arg in args]
  56 +            else:
  57 +                args = []
  58 +            url = args[0]
  59 +            keywords = {}
  60 +            width = None
  61 +            height = None
  62 +            alt = None
  63 +            for arg in args:
  64 +                if arg.find('=') > -1:
  65 +                    key, value = arg.split('=')
  66 +                    if key == 'width':
  67 +                        width = value
  68 +                    if key == 'height':
  69 +                        height = value
  70 +                    if key == 'alt':
  71 +                        alt = value
  72 +            if alt == None:
  73 +                alt = url
  74 +            return self.image(
  75 +            title="attachment:%s" % wikiutil.quoteWikinameURL(url),
  76 +            src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1), width=width, height=height, alt=alt)
  77 +        elif args is not None:
  78              result = "[[%s(%s)]]" % (name, args)
  79          else:
  80              result = "[[%s]]" % name
  81 diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/macro/Image.py
  82 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
  83 +++ b/MoinMoin/macro/Image.py	Fri Dec 22 14:13:46 2006 +0100
  84 @@ -0,0 +1,100 @@
  85 +# -*- coding: iso-8859-1 -*-
  86 +"""
  87 +    MoinMoin - Image Macro V1.1
  88 +
  89 +    This macro is used to display an image with the ability to resize 
  90 +    and/or provide an alt text for it.
  91 +
  92 +    Syntax:
  93 +        [[Image(image, [width=width, [height=height], [alt=""])]]
  94 +
  95 +    Parameters:
  96 +        image: image attachment file name or the URL of an image
  97 +        
  98 +    Keyword Parameters:
  99 +        width: rendered image width (optional)
 100 +        height: rendered image heigth (optional)
 101 +        alt: text for img tag "alt" attribute (optional)
 102 +
 103 +    Examples:
 104 +        [[Image(pic.png, height=100)]]
 105 +        [[Image(pic.png, alt=yourtext)]]
 106 +        [[Image(OtherWikiSite/pic.png, widht=50, alt=Your text here)]]
 107 +        [[Image(http://webcam.portalmuc.de/images/webcam/webcam_marienplatz.jpg, height=100)]]
 108 +
 109 +    The Image macro is a simple modification of the ImageLink macro.
 110 +    ImageLink macro copyright:
 111 +                2001 by Jeff Kunce,
 112 +                2004 by Marcin Zalewski,
 113 +                2004-2006 by Reimar Bauer (R.Bauer@fz-juelich.de),
 114 +                2006 by Thomas Waldmann
 115 +            
 116 +    @copyright: 2006 by Oliver Siemoneit
 117 +    @license: GNU GPL, see COPYING for details.
 118 +
 119 +    Changes:
 120 +    * Parameter values now also take "=None" e.g. "width=None"
 121 +    * RB bug fixed alt key for images must be defined always 
 122 +"""
 123 +
 124 +import os
 125 +from MoinMoin import wikiutil, config
 126 +from MoinMoin.action import AttachFile
 127 +
 128 +
 129 +def _is_URL(text):
 130 +    """ Answer true if text is an URL.
 131 +        The method used here is pretty dumb. Improvements are welcome.
 132 +    """
 133 +    return '://' in text
 134 +
 135 +def execute(macro, args):
 136 +    request = macro.request
 137 +    _ = request.getText
 138 +    formatter = macro.formatter
 139 +    if args:
 140 +        args = args.split(',')
 141 +        args = [arg.strip() for arg in args]
 142 +    else:
 143 +        args = []
 144 +
 145 +    argc = len(args)
 146 +    kw_count = 0
 147 +    kw = {} # create a dictionary for the formatter.image call
 148 +    for arg in args:
 149 +        if '=' in arg:
 150 +            key, value = arg.split('=', 1)
 151 +            if value != 'None':
 152 +                kw_count += 1
 153 +                kw[str(key)] = wikiutil.escape(value, quote=1)
 154 +    argc -= kw_count
 155 +    image = args[0]
 156 +    pagename, attname = AttachFile.absoluteName(image, formatter.page.page_name)
 157 +
 158 +    if not kw.has_key('alt') or kw['alt'] == 'None':
 159 +        if _is_URL(image):
 160 +            # Get image name http://here.com/dir/image.png -> image.png
 161 +            kw['alt'] = wikiutil.taintfilename(formatter.text(image.split('/')[-1]))
 162 +        else:
 163 +            kw['alt'] = attname
 164 +
 165 +    if not argc or argc and not args[0]:
 166 +        msg = 'Not enough arguments to Image macro! Calling syntax: [[Image(image, [width=width], [height=height], [alt=""])]]'
 167 +        return "%s%s%s" % (formatter.sysmsg(1), formatter.text(msg), formatter.sysmsg(0))
 168 +
 169 +    if _is_URL(image):
 170 +        kw['src'] = image
 171 +    else:
 172 +        kw['src'] = AttachFile.getAttachUrl(pagename, attname, request)
 173 +        attachment_fname = AttachFile.getFilename(request, pagename, attname)
 174 +        if not os.path.exists(attachment_fname):
 175 +            linktext = _('Upload new attachment "%(filename)s"')
 176 +            return wikiutil.link_tag(request,
 177 +                                     ('%s?action=AttachFile&rename=%s' % (
 178 +                                         wikiutil.quoteWikinameURL(pagename),
 179 +                                         wikiutil.url_quote_plus(attname))),
 180 +                                         linktext % {'filename': attname})
 181 +
 182 +    return formatter.image(**kw)
 183 +
 184 +
resizing_image_from_gui_20061222_patch.txt

And that patch is based on ImageLink -- ReimarBauer 2006-12-22 18:21:35

   1 # HG changeset patch
   2 # User ReimarBauer <R.Bauer@fz-juelich.de>
   3 # Date 1166811596 -3600
   4 # Node ID 52ef8cfb5055dce2314c6377536bfee585bb710f
   5 # Parent  e7987ee5ae5441fdea4fd7988c4754206810988b
   6 resizing of images from gui using ImageLink
   7 
   8 diff -r e7987ee5ae54 -r 52ef8cfb5055 MoinMoin/converter/text_html_text_moin_wiki.py
   9 --- a/MoinMoin/converter/text_html_text_moin_wiki.py	Fri Dec 22 18:23:50 2006 +0100
  10 +++ b/MoinMoin/converter/text_html_text_moin_wiki.py	Fri Dec 22 19:19:56 2006 +0100
  11 @@ -1185,6 +1185,10 @@ class convert_tree(visitor):
  12          height = None
  13          if node.attributes.has_key("height"):
  14              height = node.attributes.get("height").nodeValue
  15 +        target = None
  16 +        if node.attributes.has_key("target"):
  17 +            target = node.attributes.get("target").nodeValue
  18 +
  19          # Attachment image
  20          if (title and title.startswith("attachment:") and
  21              wikiutil.isPicture(wikiutil.url_unquote(title[len("attachment:"):]))):
  22 @@ -1193,9 +1197,39 @@ class convert_tree(visitor):
  23                                    wikiutil.url_unquote(title),
  24                                    self.white_space])
  25              else:
  26 -                self.text.extend([self.white_space,
  27 -                                  "[[Image(%(file)s,width=%(width)s,height=%(height)s,alt=%(alt)s)]]" % {
  28 +                if target == None:
  29 +                    if alt == None or alt == '':
  30 +                        self.text.extend([self.white_space,
  31 +                                  "[[ImageLink(%(file)s,width=%(width)s,height=%(height)s)]]" % {
  32                                      "file": wikiutil.url_unquote(title[len("attachment:"):]),
  33 +                                    "width": width,
  34 +                                    "height": height,
  35 +                                    },
  36 +                                  self.white_space])
  37 +                    else:
  38 +                        self.text.extend([self.white_space,
  39 +                                  "[[ImageLink(%(file)s,width=%(width)s,height=%(height)s,alt=%(alt)s)]]" % {
  40 +                                    "file": wikiutil.url_unquote(title[len("attachment:"):]),
  41 +                                    "width": width,
  42 +                                    "height": height,
  43 +                                    "alt": alt,
  44 +                                    },
  45 +                                  self.white_space])
  46 +                else:
  47 +                    if alt == None or alt == '':
  48 +                        self.text.extend([self.white_space,
  49 +                                  "[[ImageLink(%(file)s,%(target)s,width=%(width)s,height=%(height)s)]]" % {
  50 +                                    "file": wikiutil.url_unquote(title[len("attachment:"):]),
  51 +                                    "target": target,
  52 +                                    "width": width,
  53 +                                    "height": height,
  54 +                                    },
  55 +                                  self.white_space])
  56 +                    else:
  57 +                          self.text.extend([self.white_space,
  58 +                                  "[[ImageLink(%(file)s,%(target)s,width=%(width)s,height=%(height)s,alt=%(alt)s)]]" % {
  59 +                                    "file": wikiutil.url_unquote(title[len("attachment:"):]),
  60 +                                    "target": target,
  61                                      "width": width,
  62                                      "height": height,
  63                                      "alt": alt,
  64 diff -r e7987ee5ae54 -r 52ef8cfb5055 MoinMoin/formatter/text_gedit.py
  65 --- a/MoinMoin/formatter/text_gedit.py	Fri Dec 22 18:23:50 2006 +0100
  66 +++ b/MoinMoin/formatter/text_gedit.py	Fri Dec 22 19:19:56 2006 +0100
  67 @@ -93,13 +93,14 @@ class Formatter(text_html.Formatter):
  68      # Dynamic stuff / Plugins ############################################
  69  
  70      def macro(self, macro_obj, name, args):
  71 -        if name == "Image" and args is not None:
  72 +        if name == "ImageLink" and args is not None:
  73              pagename = self.page.page_name
  74              if args:
  75                  args = args.split(',')
  76                  args = [arg.strip() for arg in args]
  77              else:
  78                  args = []
  79 +            argc = len(args)
  80              url = args[0]
  81              keywords = {}
  82              width = None
  83 @@ -114,11 +115,14 @@ class Formatter(text_html.Formatter):
  84                          height = value
  85                      if key == 'alt':
  86                          alt = value
  87 -            if alt == None:
  88 -                alt = url
  89 +            target = None
  90 +            if argc >= 2 and args[1]:
  91 +                target = args[1]
  92 +
  93              return self.image(
  94 -            title="attachment:%s" % wikiutil.quoteWikinameURL(url),
  95 -            src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1), width=width, height=height, alt=alt)
  96 +                    title = "attachment:%s" % wikiutil.quoteWikinameURL(url),
  97 +                    src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1), width=width, height=height, alt=alt, target=target)
  98 +
  99          elif args is not None:
 100              result = "[[%s(%s)]]" % (name, args)
 101          else:
resizing_imagelink_from_gui_20061222_patch.txt

This is not a real bug it's more a missing feature of the gui.

Plan


CategoryMoinMoinBugFixed

MoinMoin: MoinMoinBugs/Gui Image Resize Not Saving (last edited 2012-02-24 04:47:42 by c-76-21-40-198)