Creating Mobile Codes locally - no web service needed

A long while ago I wrote about the advantages of Mobile Codes, 2D barcodes that can contain text snippets or URLs that can be interpreted by a camera phone to save the user having to input lots of text on their mobile device. I'm using the term Mobile Codes here to mean both Datamatrix and QR format barcodes. Generating mobile codes is easy, many people will use a service that will be provided on a third party website to input a few details on a web form and have the code generated for them, a good example of such a website is Nokia Mobile Codes. This is great for experimentation, however there might be a slight problem when you come to work on providing a service of your own where you need to generate mobile codes, the terms and conditions of that third party service might rule out using that site. For example, the Nokia site has a list of terms and conditions that say, amoungst other things that "The Service ... may be used solely for private, non-commercial purposes" and "No person under the age of 16...is eligible to use the Service", so if you are a fifteen year old entrepreneur you'll have to get your mobile codes from somewhere else! Fortunately, you can create mobile codes without leaving the comfort of your command line.

An example of a 2D barcode produced with iec16022 and imagemagickThese instructions are for Ubuntu systems, but should also work on Debian. Creating an image file containing a mobile code can be done in just two commands, but first we need to install two packages iec16022 and imagemagick to give us the required software, this can be done with this command in a shell:

sudo apt-get install iec16022 imagemagick

The iec16022 package provides a program to generate the mobile code, it is open source software originally written by Andrews and Arnold Ltd. and now maintained by Stefan Schmidt. When you look at the man page (enter man iec16022)  for this program you'll see it has various options including one for size, but there is something here that might trip you up; you might want to nice large mobile code to put on your size, maybe 300x300 pixels in size, but if you try to specify this here you will get an error message. This is because most mobile codes are actually scaled up in size from their default size. The program is using one pixel for each piece of information, but mobile codes used on websites or on printed materials might actually use several pixels for that one pixel, you have to specify quite a small size for the option to iec16022 and then use another program to do the scaling.

Generating a mobile code is easy, here is one that will embed the text "Mobile Codes are fun!" into a barcode and output this to an image file called "mymobilecode.png", you can also use an input file to pass the input text if you want, if you use the command line be careful with your quotes to avoid the shell trying to interpret your text:

iec16022 --size=32x32  --barcode='Mobile codes are fun!' --format=PNG --outfile mymobilecode.png

If you want to embed a link instead of text, just speciy a full web address (including the "http://" part) and the reader software should pick it up. The image file you are left with is rather small, too small for most mobile reader software to deal with, so you'll need to scale it up using the mogrify command from the Imagemagick suite of image manipulation tools we installed earlier. This command scales up an image, and modifies the original file. A good size might be 300x300 pixels, big enough for a lot of mobile reader software to pick up. You can use a command like this:

mogrify -scale 300x300 mymobilecode.png

Generating a mobile code this way is very quick and could easily be scripted and might be a useful option if you want to make more use of mobile codes in your developments.

Trackback URL for this post:

http://www.greenhughes.com/trackback/4949

Comments

Re: Creating Mobile Codes locally - no web service needed

I cannot read your code. I use a barcode reader on my android phone and your code is not in the list of code types that it reads. It seems the QR CODE format is *much* more popular, in many countries. I'd repost your codes in QR CODE format.

Re: Creating Mobile Codes locally - no web service needed

It's in Datamatrix/ISO 16022 format. should be supported by most bar code readers. Interesting what you say about QR code popularity though, I'll have to look into how to generate those locally.

Re: Creating Mobile Codes locally - no web service needed

I really don't think people have thought through this whole concept of mobile codes that are not human readale but can be used to bring up (say) a website.

What happens when somebody starts spreading a goatse mobile code around? How could you possibly respond to that? To prevent that?

Re: Creating Mobile Codes locally - no web service needed

Hi Stephen, the reader software I have used in the past shows you the URL that is embedded in the mobile code and asks your permission before visiting it. Of course this will be meaningless if the URL is very obscure or uses one of the URL shortener services. So possibly meaningful URLs again prove their usefulness in helping people understand what will happen if they follow that link.

Post new comment

Comments are always very welcome, but please note the following:
  • Comments on this web site are monitored for spam using Mollom. By posting a comment, you accept that your message and other personal details about you will be analysed and stored for anti-spam and quality monitoring purposes, in accordance with Mollom's privacy policy.
  • Please use your own name not a company or website name to submit comments. Your comment will be removed if you don't do this.
  • All links in comments will be marked with a no follow attribute. That means posting a link to your site here won't help your search engine rankings.
  • By submitting a comment you agree that your comment can be reproduced under the same licensing terms as the rest of the content on the site.
  • Comments can be removed at any time without explanation, but won't be removed just because you disagreed with something I said.
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <q> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6>
  • Lines and paragraphs break automatically.

More information about formatting options

Back to top