How can I use the Image plugin and get the image to be placed inline with the text around it? When I use Image it seems to force a linefeed before and after the image.

I get ...

text [{Image src=''e}] text
I want ...

text (image here on same line) text


Try

This is my text here [{Image src='myimage.png' align=right}] and see 
how my text flows around it?

Nope. It still does not do what I am looking for. I ended up writing my own plugin that placed the image in a <span> rather than a <table>. It does not support captions. I just wanted to see (after the fact) if I had wasted my time doing my own plugin.

Then why not just simply inline the image by just saying

This is my text here, and I wish to [myimage.png] inline my image...

Because I want the image to be a link.

Then [http://my.link.com|Pic/java.png] should be what you want =).


This is unnecessary - there is already an Image plugin in 2.1.5. --JanneJalkanen

But I need <img> support now (in a stable wiki version) - so don't worry, it was an effort of a few minutes only --AndreasRozek

I will add the Image plugin to the next stable release. In the mean time, you can download the latest nightly build and use the image plugin from there with the current stable build. It has some cool stuff like captions, etc. --JanneJalkanen

Thanks for the note - and the upcoming new version --AndreasRozek


JSPWiki markup does not have a special notion for image inlining - instead, wiki links referring to images of an explicitly configured set of types will result in the display of the referred pictures.

This approach has two disadvantages:

  1. when configured for automatic inlining, it is impossible to insert a link to such a picture which shall not be inlined automatically
  2. inlined images will always be shown in a predefined way - without the possibility to specify explicit scaling, or similar

The "img" plugin has been written to overcome this problem by explicitly inserting an <img> directive with a given set of parameters into the running text.

Compilation#

Save the source code shown at the bottom of this page into a file called img.java. Then invoke the Java compiler as follows

  javac img.java
(or similar - depending on the development environment you are using)

Installation#

Create a JAR archive containing the Java class file for the plugin. You may use the command

  jar cvf img.jar img.class
for that purpose.

Then move that file into any directory within your wiki's class path - preferrably into the WEB-INF/lib/ folder within your web server's web application directory for the JSPWiki.

Finally restart the Wiki for the plugin to be recognized.

Usage#

Within wiki markup, invoke the plugin as follows

  [{img src='...'}]
As the class resides in the default directory, there is no need neither to prefix the plugin name with a package path nor to modify the plugin search path within the JSPWiki configuration file.

The "img" plugin supports the following set of parameters - every value given will be directly used for an <img> directive parameter of the same name:

src (mandatory)
specifies the URL of the image to be shown in the document
alt (optional)
may contain an alternative text to be shown if a browser is unable to display images (or has been configured not to do so)
width (optional)
may specify the foreseen width of the image
height (optional)
may specify the foreseen height of the image
border (optional)
may define what kind of border (if any) should be shown around the image
align (optional)
may specify the position of the image with respect to the surrounding text
hspace (optional)
may request an additional gap between the image itself and the text to its left and right
vspace (optional)
may request an additional gap between the image itself and the text above and below
name (optional)
may define a HTML "name" for the image
longdesc (optional)
may contain the URL of a web document with a detailled description of the image

Please consider any HTML documentation (such as SelfHTML) for a detailled description of the HTML parameters shown above.

Source Code#

import java.util.*;                  // Java utility classes and data structures

import com.ecyrd.jspwiki.*;
import com.ecyrd.jspwiki.plugin.*;

public class img implements WikiPlugin {
  public String execute (WikiContext Context, Map ParameterMap) throws PluginException {
    String src      = null;                                         // image url
    String alt      = null;                           // alternative description
    String width    = null;                             // requested image width
    String height   = null;                            // requested image height
    String border   = null;                            // requested image border
    String align    = null;                         // requested image alignment
    String hspace   = null;    // extra space to the left and right of the image
    String vspace   = null;             // extra space above and below the image
    String name     = null;                              // requested image name
    String longdesc = null;               // url with a description of the image

  /**** look for any supported parameter ****/

    src      = getParameter("src",      ParameterMap);
    alt      = getParameter("alt",      ParameterMap);
    width    = getParameter("width",    ParameterMap);
    height   = getParameter("height",   ParameterMap);
    border   = getParameter("border",   ParameterMap);
    align    = getParameter("align",    ParameterMap);
    hspace   = getParameter("hspace",   ParameterMap);
    vspace   = getParameter("vspace",   ParameterMap);
    name     = getParameter("name",     ParameterMap);
    longdesc = getParameter("longdesc", ParameterMap);

  /**** perform some parameter checks ****/

    if (src == null) throw new PluginException("img-PlugIn: no \"src\" given");

// room for more checks

  /**** now construct the "img" directive ****/

    String Result = "<img src=\"" + src + "\"";
      if (alt      != null) Result += " alt=\""      + alt      + "\"";
      if (width    != null) Result += " width=\""    + width    + "\"";
      if (height   != null) Result += " height=\""   + height   + "\"";
      if (border   != null) Result += " border=\""   + border   + "\"";
      if (align    != null) Result += " align=\""    + align    + "\"";
      if (hspace   != null) Result += " hspace=\""   + hspace   + "\"";
      if (vspace   != null) Result += " vspace=\""   + vspace   + "\"";
      if (name     != null) Result += " name=\""     + name     + "\"";
      if (longdesc != null) Result += " longdesc=\"" + longdesc + "\"";
    return Result + ">";
  };


  public String getParameter (String Name, Map ParameterMap) {
    String Result = (String) ParameterMap.get(Name);
      if (Result != null) {
        Result = Result.trim();
        if (Result.equals("")) Result = null;
      };
    return Result;
  };
};

Andreas Rozek (EMail: Andreas.Rozek@GMX.De)


IMHO, Image should support the title attribute of the img tag as well.

Thank you for your consideration!

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-35) was last changed on 05-Mar-2009 12:17 by 62.154.199.179