Editing WordPress QuickTags to automatically create captioned images

Web Programming 9 Comments
Filler Bunny: He takes up space
Filler Bunny

One of the best ways to add life to your blog posts is to include images with the text–your reader’s eye is naturally drawn to the large visual well before the text itself, and the addition of a picture can bring an element or realism to your post that would normally be missed. Many templates available on the web, however, fail to include a simple way to add captions to your images, limiting what you can do with them. For example, anyone posting a picture of, say, two dogs would be hard-pressed to indicate which was Rover and which Fido without the aid of a caption. The easiest solution is to place the image in a table with a caption, of course, but this adds several ungainly lines of code which you must type in by hand in order to add a single captioned image. Even copying and pasting, this method of posting captioned images is a serious pain at best.

Thanks to WordPressQuickTags (the row of buttons directly above the post content itself on the Write page), however, it’s relatively simple to edit the ‘img’ button to create custom captioned images.

First, replace the function edInsertImage in /wp-includes/js/quicktags.js with the following javascript:

function edInsertImage(myField) {
var myValue = prompt(’Enter the URL of the image’, ‘http://’);
if (myValue) {
myValue = ‘<img src="’
+ myValue
+ ‘" alt="’ + prompt(’Enter a description of the image’, ”)
+ ‘" />’;
myValue = ‘<table class="alignright" width="’
+ prompt(’Enter the image width’, ‘250′)
+ ‘" border="’
+ prompt(’Border size:’, ‘0′)
+ ‘" cellspacing="0" cellpadding="0">’
+ ‘<caption align="bottom"><b>’
+ prompt(’Caption:’, ”)
+ ‘</b></caption><tr><td>’
+ myValue
+ ‘</tr></td></table>’;
edInsertContent(myField, myValue);
}
}

Now, at this point, once you’ve replaced your current quicktags.js, the ‘img’ button on the write page may or may not do what you want it to do. Chances are that you’ll have to add to your CSS as well before you can reap the benefits of the modified ‘img’ button, though. If so, place the following in your template’s CSS sheet:

table.alignright {
padding: 4px;
margin: 0 0 2px 7px;
display: inline;
}

table.alignleft {
padding: 4px;
margin: 0 7px 2px 0;
display: inline;
}

That should do it. Now whenever you go to add an image with the quicktags img button, it will prompt you for all the appropriate parameters to create a nicely captioned image like the one above. Should you wish, you can add other elements to the javascript, such as the ability to choose the color of the photo’s border.

UPDATE: Make sure you refresh the ‘Write Post’ page of WordPress after you modifiy your quicktags.js file. Otherwise, the cached (unmodified) version will continue to be used.


Creating lighting effects quickly and easily with Macromedia Fireworks

Web Programming No Comments

Creating the effect of light can be useful in designing web graphics with Macromedia Fireworks, and can quickly and easily add interactivity to your images that will enliven the page viewing experience for your users. Adding simple mouse-over lighting effects is much easier than you might think, allowing you to create complex images in almost no time. The following example uses the lighting effect to indicate to the user which buildings are wireless-enabled when he or she mouses over them. If a building is enabled, it lights up when the cursor is placed on it:

In this example we have chosen to ‘illuminate’ the whole building, but this effect can be used to create the effect of light through a window, a keyhole, or almost anything. Here’s how it’s done:

  1. Using the Polygon Slice tool, trace around the area you want to lighten (you don’t have to be perfect - it will become obvious why in a couple of steps). This will create polygonal slices in the shape of the objects you will be lightening.
  2. Copy the selection you have traced to another file. In the case of our example, this file contains all the buildings that can be lighted, in a file called buildings.png:

    The image “http://vaskenhauri.com/blog/stuff/buildings.jpg” cannot be displayed, because it contains errors.

  3. Next, simply select all of your objects from the buildings (or equivalent) file, choose ‘Filters,’ ‘Adjust Color,’ ‘Brightness/Contrast’ and up the brightness setting between 25 and 50, depending on your preference.
  4. Now, begin pasting the brightened objects back into your image’s ‘Frame 2,’ which you can create by selecting ‘New/Duplicate Frame’ from the ‘Frames and History’ window. When you get near where they ‘belong,’ they should snap back into place.
  5. Back on Frame 1, right-click on each lighting object and choose ‘Add Swap Image Behavior.’ By default, Fireworks will swap with the same area in Frame 2, meaning you don’t have to map anything at the next menu. Since the rest of your image exists in both Frames 1 and 2, your sloppy job of cutting earlier simply appears as a charming ‘diffuse glow’ effect on whatever you’ve chosen to illuminate.

Now, when your visitors decide to visit a link, you’ll always be able to leave the light on for them.