PHP Semacode Encoder

This post's URL encoded as Semacode A few days ago Gina Haeussge (aka. foosel) blogged about QR Codes which are currently used by the State Theater of Darmstadt to advertise their mobile services.

QR Codes and the similar Datamatrix are so called 2D barcodes. They are different from the traditional barcodes in that they store data in two dimensions and thus can hold much more information. The ones mentioned here can store up to 3kb of data.

As already said, there are two different patent free 2D standards in the wild1). The QR code which Gina talked about is very popular in Japan, Semacode is the second one and based on a US created standard called Datamatrix. Both codes have similar capabilities. Nokia seems to favor the Semacode one, while the Wikipedia related project Semapedia uses QR code (despite the name).

So what's so special about those codes? The cool thing is that you may already have a barcode reader for them. If your cell phone has a camera you most probably can use it to decode these codes. Nokia even preinstalls such a reader software on some of their newer phones. If you need such a software I can really recommend the Kaywa Reader. It's free but you need to register at their site2).

A Semapedia Tag So these codes make it simple to transfer data to your mobile phone. This data could be an URL, a phone number or even a VCard. The afore mentioned Semapedia uses it to “link” real world places to Wikipedia articles for example.

I was more interested in Semacode, because it looks somehow cooler than QR in my opinion. Unfortunately I wasn't able to find any free (beer and speech) PHP library to create these codes. But I did find a JavaScript port of a C library, used in the SemaFox Firefox extension. What I did in the last two evenings, was porting the JavaScript code to PHP. The library can create a simple HTML table, an SVG or a PNG image of the code.

Unfortunately the source code is very complicated and parts of it seem to be broken in the JavaScript port. I was able to get it running and it seems to produce correct codes, but there are probably still some bugs left. There also seem to be some unused code parts left in it. You have been warned ;-).

The code is available from a darcs repository or you can just get the library directly. If you squash any bugs, please send a patch.

If you like to try it first, use the following form:

Embedded graphic One nice thing about those 2d barcodes is the built in error correction which makes the code still decodable when part of it are missing. This makes it possible to embed small graphics into the code (See smiley image to the right). Of course you shouldn't overdo it ;-). It is also recommended to keep the stored data small, because the more data you store, the more complex the code gets and the harder it is to decode. I also found 2D barcodes better working on a white background, so if you have trouble decoding the codes in this blog entry, open the images in a separate window.

photo by akaalias

Tags:
semacode,
php,
cellphone
Similar posts:
1) I'm no pro on this topic I may be wrong or imprecise here
2) yeah that sucks, but the software is great

 
Posted on Tuesday June the 12th, 2007 (11 months ago).

Comments

1
Yay =) I'll try to make some nice DW-Plugin soonish :)

I stumbled over a bug though. The lib refuses to encode stuff with a length of 6, 8, 13, 14, 15 characters, and prolly some more wordlengths (try http://www.splitbrain.org/_sta … ext=aaaaaa for example). I have yet to take a look at the source, but maybe you already have an idea what could go wrong there. :)
2007-06-13 10:26:16
2
Ah, see? That's the kind of bugs I talked about :-/ I will have a look at it, but if you would take a look at the sources as well it would be great.
2007-06-13 10:53:04
3
It works quite well after reenabling line 414 in semacode.php (the one with the big fat "FIXME" above it). Some quick tests showed no problems, but that might not mean that I haven't broken something else now, as I guess you had your reasons to comment that one out...
2007-06-13 20:22:45
4
Yeah... try encoding a longer URL with underscores in it. The encoder will change from ASCII to Text on the first special char (like a slash) and then newer changes back to ASCII with the effect of underscores being decoded as ^ chars. Unfortunately I don't understand half of the magic that is done in the encoding process :-/

I just noticed underscores to be handled correct when staying in ASCII always, so I disabled the use of the encoding array (which is said to be optional in the comment). But this introduced the other problem :-/
2007-06-13 20:52:15
5
This is amazing. Thanks for carrying it on so far.
The problem imo is not the encoding but the decoding. Public codes suffer from the lack of readability because many cameraphones stil do not allow the software to access the cam's pictures. Motorola's API is just bugged in many phones.
Still it's great fun seeing codes tagged over the city.
2007-07-01 10:40:52
Philipp
6
guys,i m from russsia and so forgive me for my bad english.I need help.I cant use that code with my language.that code take only data written on english.what i should to do?
2007-10-06 00:15:02
sasha
7
not support international charset (russian)?
2008-01-11 09:40:28
almir
8
OK, I am a PHP newbie trying to do this. Sorry for the really dumb question. I need to generate a datamatrix barcode from a webpage. How would I call this function? Parameters? Thanks and sorry for the question.
2008-02-05 22:57:06
Bailey Kessing
9
Thank you very much. I was in a period when I needed a lot of support to make insect label, it is a much help to me.
2008-05-03 16:01:30
seok Kim
CAPTCHA

No HTML allowed. URLs will be linked with nofollow attribute. Whitespace is preserved.

 
 

Blog

Older Weblog articles are available in the Archive, subscribe to the
Full Content RSS Feed
to stay tuned. (learn more)

Subscribe to the Feed

Recent Blog Entries

 

This is the personal web site of Andreas Gohr - human being, blogger and web geek from Berlin, Germany.

This page was last updated at 2007/06/12 23:58.
Imprint/Impressum

Tagged at del.icio.us:

Bookmarks: 14

View blog reactions

Elsewhere:


Recent readers: