SCode Image Reload

Sometimes the numbers on SCodePlugin-generated CAPTCHA image are not easy to read. And rather than refreshing the whole page, it would be nice to reload only the image and generate a new / more readable code.

In order to give this a go, I modified the comment form on Melbourne photoblog and added a short Javascript code to refresh the image source. You can try it yourself on this form, just click the text “Generate another code” and wait shortly for the image to be reloaded with a new code.

I have updated the Usage sample code on SCode Plugin wiki page with this improvement.

As a side note, I found a problem where modifying img.src value via anchor tag’s onclick attribute does not work on IE 6 and the image will just disappear, while it works just fine on Firefox 2 and Opera 8.5 .

function reloadSCode() {
  var scodeImage = document.getElementById("scodeImage");
  scodeImage.src="$BLOJSOM_BLOG.getBlogBaseURL()/captcha?flavor=kink&t=" + (new Date()).getMilliseconds();
<a href="javascript: void(0);" onclick="reloadSCode();">Generate another code</a>.

After some mucking around, I found out that the function call must be made from the href attribute. This works on the browsers mentioned above.

<a href="javascript: reloadSCode();">Generate another code</a>.

Them browsers better implement proper Javascript standard before doomsday comes.

SCodePlugin v0.5

SCodePlugin v0.5 has been released, expect the jar and source downloads to be available from SourceForge mirrors in the next few days. As usual, if you want it earlier, just email me and I’ll send it to you.


  • Introduced KaptchaImageEngine using Kaptcha (was Simple Captcha) library, with 3 new flavours from KinkImageEngine, FishEyeImageEngine, and ShadowImageEngine.
  • Replaced image engine class loading in image factory with constructor injection. SCodePlugin passes the image factory to SCodeServlet, instead of passing the image engines.
  • Set ImageIO caching off during SCodeServlet initialisation. This improves performance and prevents any temporary disk-based image creation.

Upgrade instruction:

  • In WEB-INF/lib directory, replace scodeplugin-0.4.jar with scodeplugin-0.5.jar, and add kaptcha-1.1.jar .
  • On /WEB-INF/classes/blojsom-plugins.xml file, replace the scode bean declaration you have for SCodePlugin v0.4:
    <bean id="scode" class="com.mbledug.blojsom.plugin.scode.SCodePlugin" init-method="init" destroy-method="destroy">
                <entry key="simple" value="com.mbledug.blojsom.plugin.scode.engine.SimpleImageEngine"/>
                <entry key="gradient" value="com.mbledug.blojsom.plugin.scode.engine.GradientImageEngine"/>
                <entry key="funky" value="com.mbledug.blojsom.plugin.scode.engine.FunkyImageEngine"/>

    with this for SCodePlugin v0.5:

    <bean id="scodeSimpleImageEngine" class="com.mbledug.blojsom.plugin.scode.engine.SimpleImageEngine"/>
    <bean id="scodeGradientImageEngine" class="com.mbledug.blojsom.plugin.scode.engine.GradientImageEngine"/>
    <bean id="scodeFunkyImageEngine" class="com.mbledug.blojsom.plugin.scode.engine.FunkyImageEngine"/>
    <bean id="scodeKinkImageEngine" class="com.mbledug.blojsom.plugin.scode.engine.KinkImageEngine"/>
    <bean id="scodeFishEyeImageEngine" class="com.mbledug.blojsom.plugin.scode.engine.FishEyeImageEngine"/>
    <bean id="scodeShadowImageEngine" class="com.mbledug.blojsom.plugin.scode.engine.ShadowImageEngine"/>
    <bean id="scodeImageFactory" class="com.mbledug.blojsom.plugin.scode.ImageFactory">
                <entry key="simple" value-ref="scodeSimpleImageEngine"/>
                <entry key="gradient" value-ref="scodeGradientImageEngine"/>
                <entry key="funky" value-ref="scodeFunkyImageEngine"/>
                <entry key="kink" value-ref="scodeKinkImageEngine"/>
                <entry key="fisheye" value-ref="scodeFishEyeImageEngine"/>
                <entry key="shadow" value-ref="scodeShadowImageEngine"/>
    <bean id="scode" class="com.mbledug.blojsom.plugin.scode.SCodePlugin" init-method="init" destroy-method="destroy">
            <ref bean="scodeImageFactory"/>

Kink, New SCode Flavor

Jon Stevens resurrected Simple Captcha in the form of Kaptcha. The good thing about Simple Captcha / Kaptcha is that it generates an image similar to the ones used at Yahoo!. Other than that, it’s really straightforward to use.

I quickly integrated Kaptcha into SCode Plugin by introducing KinkImageEngine, exposed to Blojsom via “kink” flavor. Here’s how it looks like:

This flavor will be included in SCode Plugin 0.5 (yet to be released).

SCode On Headless Hosting And Resin Plus OS X

Tim wrote about his adventure setting up SCode Plugin on a headless hosting: blojsom, anti-splog, and captcha; while Miles wrote about using the plugin on Resin and OS X: Resin, OS X, wrappers and image-generating servlets, SCode plugin clarification, More SCode servlet, SCode servlet.

Those issues are basically related to image generation in general and not just with SCode Plugin. However, the fact that various people are using the plugin on various different environments is a definite good thing for the plugin documentation.