Patrick Burt - A Blog for Web People

Auto-Generating ALT Tags with Dreamweaver

December 24th, 2008
AddThis Social Bookmark Button

What I had on my hands were a bunch of HTML files. Each of these HTML files had pictures, and I’m damn sure a lot of them didn’t have ALT tags, something essential for accessibility (and also helps with SEO). Using Adobe Dreamweaver (and possibly Macromedia versions of Dreamweaver), you can do searches and find and replaces with regular expression (regex). What you do is throw open Dreamweaver, hit Ctrl-F. At the bottom of the search window, there’s a checkbox for Use regular expression, check that and we’re ready to go.

Finding Images Without Alt Tags

I did some internet sleuthing and found the following code to search for images without ALT tags:

<img((?:(?!alt)[^<>])*)>

What it does is search for “<img”, and then the next “>” that occurs, hopefully the end of your image tag. it then checks for the phrase “alt” anywhere in there to find an alt tag. The downside, is that if you’re image HTML looks like this:

<img src=”malt.jpg” />

Dreamweaver won’t pick up on it. That’s something I’ll look into if I revise the code, but I wasn’t working on a beer website so I didn’t think it was going to be a problem.

Auto-Generating ALT Tags

Because it’s impossible to give an accurate description of each of the 400 images without consuming a lot of time, what we’re going to do is base the ALT tag on the file name.

Here is the FIND field:
<img src=”(.*?)(.gif|.jpg|.jpeg|.png|.GIF|.JPG|.JPEG|.PNG)((?:(?!alt)[^<>])*)>

Here is the REPLACE WITH field:
<img src=”$1$2″ alt=”$1$3>

What’s happening here? You’ll seethat we’re checking for the existence of the “alt” tag once again, but we’re also breaking down the image tag down. Each section to be broken down is within parentheses. The first chunk is the image’s source, then the image’s extension and then the last chunk before the end (that doesn’t contain an alt tag). For example:

<img src=”myDogShelby.jpg” border=”0″ height=”300″ />
becomes
<img src=”||||PART 1: myDogShelby||||PART 2: .jpg||||PART 3: border=”0″ height=”300″ /||||>

Then what we’re doing is reconstructing the image link as follows:

<img src=”myDogShelby.jpg” alt=”myDogShelby”  border=”0″ height=”300″ />

Simple? I thought so.

Finishing Touches

What happens when using this technique is that you’re also throwing the path into the ALT tag:

<img src=”images/shelby.jpg” />
becomes
<img src=”images/shelby.jpg” alt=”images/shelby.jpg” />

This is an easy fix, simply do a global search and replace. Replace:

alt=”images/
with
alt=”

Easy peasy, japaneasy. This is pretty straight-forward, hope that helps and saves you oodles of time.

Bookmark this blog using any bookmark manager!

Graphic Design and the Economy - An Interview

November 26th, 2008
AddThis Social Bookmark Button

Rob Brown recently threw me a few questions on Graphic Design and how it’s being affected by the downturn in the economy. Here’s what i had to say.

RB  What is your job in the industry?
I work as a Web Developer/Designer for an ad agency in Canada’s capital. I also do freelance.
RB  How long […]

Read the full article »

Interviewed By An Upcoming Graphic Designer

August 18th, 2008
AddThis Social Bookmark Button

I was contacted by an up and coming Graphic Designer, Luke Cosgrove, to get interviewed about what it is that I do. I thought he asked particularly good questions and it does share quite a bit of background information about me. What a great fit for this blog.

LC Is this what you wanted to […]

Read the full article »

Some Suggestions for Writer’s Block

June 24th, 2008
AddThis Social Bookmark Button

It happens, it happens to everyone. If it hasn’t happened to you, you’re lucky and it may happen soon. And when it does, here are a few tips:

Step Away From the Computer
Do something, anything, just make sure it’s stimulating. If your solution is to watch TV, what if you watched shows that dealt with […]

Read the full article »

SWFObject 2.0 and New Website

June 19th, 2008
AddThis Social Bookmark Button

Although I’ve been using SWFObject almost daily, I’ve always recycled the version I used on a previous project. Little did I know that a new version was released by Geoff Sterns (who know works for Google in the YouTube division) and is posted on Google’s codebase.
A new version means a new syntax, new file and […]

Read the full article »

Would You Rather Be Right or Happy?

June 10th, 2008
AddThis Social Bookmark Button

A question you should often ask yourself over the course of your life is, believe it or not, entirely relevant to web design, web development, dealing with clients, etc.

Let’s take for example the following situation. The client supplied a photograph for a web design that needs to be enlarged to abnormally large proportions. The upsampled […]

Read the full article »

The Sarcastic Guide To Web Design and Development - Part 1

June 4th, 2008
AddThis Social Bookmark Button

***This article is sarcastic***
There are a handful of rules that will automatically place in the rungs of “All-Star Web Designer and Developer”. It is my objective to share these with you.

1 - You Are Always Right
The client never knows what the client wants. It’s up to you to tell them. If they disagree with you, […]

Read the full article »

What You Need To Know About SQL Injection

June 2nd, 2008
AddThis Social Bookmark Button

Having seeing the effects of an SQL Injection attack, I thought I’d be able to tackle some tips on preventing SQL Injections in the first place.

All it takes is one vulnerability to affect your entire software application. If the vulnerability is general enough, you could be the target of scripts that scour the web […]

Read the full article »

Busy Person’s Guide To Getting Work Done

May 29th, 2008
AddThis Social Bookmark Button

I apologize for not posting in a while, life has been hectic. That being said, how about a post on getting work done.

We’ve all been in the position, whether it’s at work, in school, where there was just so much work to do, that you had a hard time getting around all of […]

Read the full article »

Follow-Up - TNX.net Thoughts

May 14th, 2008
AddThis Social Bookmark Button

I’ve had the chance to use TNX.net now for a few months, so I can give a better opinion on it. For the original review, you can check it out here.

TNX.net is pretty close to being a fire and forget income generator. Although you can make enough of an income stream without ever having […]

Read the full article »