Using Kindlegen with PHP on Linux to Create Kindle Files

I’m working on a side project at the moment that requires the conversion programatically of a page of html to something that can be consumed by an Amazon Kindle. I did a quick search to see if anything existed as a PHP class library that I could use and while there was they were either hugely bloated or too alpha for my needs.

I then stumbled upon Amazon’s command line tool KindleGen which allows conversion of HTML and ePub docs to the MOBI format that the Kindle requires. This is a multi-platform too and, crucially, a version for Linux is available.

Installation is a simple case of copying the single file to an appropriate place on your server, such as /usr/local/bin. Then create a new folder somewhere and make sure that the web process has write access to it. On Ubuntu this would be, for example, by :

sudo chown www-data:www-data /var/www/kindle

In my case I needed to convert some HTML to MOBI format and while experimenting found that it was very important to have well formed code, particularly with html and body tags. The other thing that you might like to consider is including a title tag as this is what is used as the name in the Kindle library and if this is omitted Amazon will use the name of the attached file instead.

To convert the file you simply need to pass to kindlegen the name of the html file and the output filename – note that you don’t need to give the path for the output file as it is created in the same place as the source. In PHP you can use “exec” to call a Linux command:

exec('kindlegen ' . '/var/www/kindle/input.html' . ' -c0 -o ' 
. '' );

If you were allowing a user to enter their own HTML that you were going to process this way I would highly recommend sanitizing the input first!

As a full example of this the following code stub will convert html in the $content variable and then send the resulting file to your Kindle email.


$content = "<html><head><title>Your title</title></head><body>
            <p>Your Content</p></body></html>";

// create the input file
$filename = date('Ymd_His');
$body = file_put_contents($filename.'.html',$content);

// convert to mobi format
exec('kindlegen ' . '/var/www/kindle/'.$filename.'.html' . 
     ' -c0 -o ' . $filename.'.mobi' );

// send the file as an attachment to your Kindle
$mail = new PHPMailer();
$mail->AddReplyTo('registered @'
 ,'First Last');

// this address must be registered with your Amazon account
$mail->SetFrom("registered @ domain","First Last");

// this is the email address of your Kindle
$mail->AddAddress("your_address @", "First Last");

// the next two are required by PHPMailer but not by Amazon
$mail->Subject  = "";
$mail->MsgHTML(" ");

// add the mobi file

// send the file
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
// delete the files created


Creating Good Looking Product Shots on Devices

A while back I wrote about what I described as “One of the most amazing websites” I had seen and it was great. Placeit allows you to create screen mockups by uploading a screenshot that is then rendered into a chosen device. Unfortunately when I went back recently the prices had sky rocketed. To download even the most basic image now costs $8 a pop and a “casual” plan is $29 a month. For someone that uses the service about once a year that was prohibitively expensive.

I should state at this point that I have absolutely no issue with a software developer charging for their work, in fact I would say that was pretty essential, however, the amount I am willing to pay has to be in proportion to the value that I think that I will get. In this case the service didn’t meet that threshold. So I went to look for an alternative solution.

I could learn to use Photoshop which can do these in a breeze but, of course, it costs a fortune to get. Then I discovered Insta Mockup for iOS which is a free app that has a number of templates that you can use to create good looking screen mockups, such as the one below. It is easy to use and while doesn’t have the range of device mockups that Placeit has it is cost effective. You can download a low-res version of an image for free or upgrade and get higher resolution for only £1.49. It’s a bargain and works well.

Download it here.


Happy 10th Birthday Us!

So I have been blogging on technology now for just over ten years it would seem, the first post was June 5th 2004. It’s somewhat ironic, however, that I am today writing this post in WordPress and the very first post was about Noah Grey’s excellent Greymatter another great CMS. This also means that I have been connected for about 20 years launching my first website in May 1996 – The Williams Database.

How things have change in that very short space of time. That first site was launched on the “free” 0.5 mb of space that was provided by my ISP. I fondly remember doing all my site changes off line and only dialing up to upload the changes and then immediately cutting the line to ensure that we didn’t run up great costs. Today even my thermostat is permanently connected to the Internet and dialing up is no more. As for webspace people are falling over themselves to offer me gigabytes and now it is called the cloud.

Who knows what the next ten years will bring but the rate of change is ever increasing so it will be fascinating to watch and be part of.

A Tale of Two Chromebooks

A couple of years ago I spent weeks searching high and lo for a Samsung Series 3 Chromebook which was the first of the really affordable cloud laptops. I finally found one and paid £240 – nothing compared to the price of some Windows and especially Mac laptops.

Initially I was amazed at the start-up time of seconds and the fantastic battery life. I found that I could access my email and calendar through the browser (as I had been for a while since ditching Outlook) and do all my general web-browsing. I was hooked and decided that, away from the office, this was going to be me goto machine. And then reality started to sink in. No Skype, No Microsoft Office and the machine was so underpowered that it struggled with only a few tabs open and Evernote in a browser just killed it. The machine was quietly shelved.

Then, a couple of weeks ago, I attended an event sponsored by Google where we were all given a brand new Acer c720 Chromebook (thanks Google and Twilio!). The cloud landscape has changed considerably in the last couple of years so I was keen to check out the device to see whether it was now more suitable for my work purposes.

The first thing to note was that the devices are very similar in size and weight but the build quality on the Samsung is much better as there are a few literal rough edges on the Acer but I guess that to hit a certain price (£180 at the time of writing and £60 less than the Samsung) some compromises had to be made.

The feel of the Acer in use is exactly the same as using Google Chrome on any other machine and it is cleverly integrated with all of Goggle’s properties, such as Calendar and Drive. The question is what is it like when trying to use it for work?

I have a particular use case that is fairly demanding and likely to be more than most need and this includes being able to remotely manage our servers and do some light development work. Two years ago this would have been a complete no no but I was pleasantly surprised to find that Chrome now has a fully functional SSH client with support for keys meaning I could easily access my servers. Issue number one sorted. Development I knew would be no problem as I already use ShiftEdit for accessing the servers and doing PHP changes as necessary. So that was a check too.

Skype is the primary way I communicate with others in the organisation and so is key to the smooth running of our business. Last time I tried to use a Chromebook there was no way to use Skype and this put me off completely. Now though Skype is available through Microsoft’s portal, offering Outlook (nee Hotmail) email, cloud storage etc. It’s surprising just how useable Skype in a browser is – it appears as a side bar and offers IM, voice and video calling. I don’t miss the desktop client at all and, I think, that looks great and is better integrated than the Google equivalents. also proved to be the solution to dealing to Microsoft Office documents too as you can now open to view them in the browser. You are also offered the option to either download the file and edit it in the desktop Office apps or edit in the browser to make what Microsoft calls “quick changes” although it seems to have all the functionality I need. I’m not sure if this editing ability needs an Office 365 subscription though as I have one.

So that just leaves Evernote, my digital brain. As I said opening Evernote in the browser on the Samsung was just a nightmare making the machine pretty much unusable. I am guessing that a combination of the more powerful machine and optimisation on the part of Evernote has transformed it into something that is really quite workable, although still a little clunky but at least now you can continue to do other things too.

So in the space of two years it seems that things have progressed sufficiently to make the Chromebook a realistic working proposition, at least for the things that I need.


A Potentially Dangerous Experiment

Being mobile means I have to work in a number of different places on a number of different machines. The one constant is that no matter where I am I want and need to have my files with me. While I have Dropbox and Google Drive and and iCloud and Box and OneDrive and OwnCloud accounts I found that files that were in the Documents and Downloads folders on my iMac weren’t available to me on the move.

This led to a light bulb moment. What if I could store my Documents and Downloads folders in cloud storage? And so that is exactly what I have done.

Despite having accounts with most cloud providers I decided to move the folders to Microsoft’s OneDrive. There were a number of reasons for this: I have plenty of space there, I like the user interface and I can open the documents directly in Office for iPad, to name a few. These are the steps I too:

1. I copied the content of Document and Downloads from my iMac to OneDrive and waited for them to fully sync.

2. Next I renamed the folders. To do this you need to go into Terminal and type the following commands (you may be prompted to enter your password)

sudo mv ~/Documents ~/Documents_old
sudo mv ~/Downloads ~/Downloads_old

3. Now you need to create what is called a symbolic link between the real location of the folders (on OneDrive in my case) and their original location (so the OS can find them). You can do this from Terminal as follows (you will need to change the OneDrive location to where you copied the folders to)

ln -s ~/OneDrive/Documents ~/Documents
ln -s ~/OneDrive/Downloads ~/Downloads

4. Now do the same on your other machines. I turned off OneDrive while moving the folders on the second machine to stop it syncing before I was ready.

So what I have I learnt so far?

Firstly, it works!

You do have to ensure that things have fully synchronised before starting to edit a document that you might have also edited on another machine. This does mean that if you have updated a document on the first machine that you cannot edit it on the second until you are online, which could be a problem in some circumstances.

I have also had problems with OneDrive trying to sync hidden folders (those starting with a full stop) and with file names that are too long (a hangover from Windows I suspect).

I also found that the icons on the folders in Finder were lost but you can restore them by dragging them from here:


Although I have yet to work out how to do that on the sidebar.

So far I have been pleased with the change but I will report back after a few weeks of running like this to see whether anything else comes out of the woodwork!

Cocoon SLIM vs Wenger SwissGear Synergy Backpack Review

For years I have been lugging my kit around in a Wenger Swiss gear backpack, which has been a real rugged workhorse. The thing though is massive and even after years of use I still don’t think I have found all the pockets!

The problem is that because it could carry so much there has always been a temptation to overfill it – you never know when you might need that widget and so in the bag it goes. This became an issue for me because the Wenger is heavy when it is empty let alone when full. So began the search for something that might allow me to carry what I needed without breaking my back.

At the same time as I realised that I needed an alternative Cocoon released their SLIM backpack. I have been using their Grid-It organisers for a while helping to bring some order to the larger pockets on the Wenger and so when I saw the SLIM included a massive grid I was sold.

Frustratingly the pack is only available in the US and then only in Apple stores. So when I was on holiday there earlier this year I hunted one down.

As you can see from the picture above it is thin, almost so that you might not believe that it can actually hold that much but looks can be deceptive. There is a large padded pocket at the back for your laptop with a smaller pocket in front for an iPad/Kindle etc. There is also a pocket for papers but don’t expect to get more than a few sheets in there and your certainly will have to choose between your iPad and a notebook – a good time to go paper free?

Up front there is another zipped cover which opens to reveal a massive Grid-It organiser which allows you to stow pretty much any thing you can think of in a convenient and easy to reach way. As you can see from the images below from mine and a colleagues bag you really can store all manner of things here. Including, in my case, an umbrella.

IMG_8472 IMG_8572

The thing I have always liked about about the Wenger is that it has a massive amount of padding which probably accounts for why it is 1.8kg vs 1.14kg for the Cocoon. The result of all this padding is that the Wenger is really comfortable when being carried for long periods. Given the thin nature of the SLIM I was concerned that there wouldn’t be much protection and it would be uncomfortable but I was wrong on both counts. The lighter weight helps and what padding there is seems to do a good job of fitting comfortably to my back.

If you are looking for a smart and compact way of carrying all you need for a business day then the Cocoon is the pack for you. You won’t be able to carry as much as the Wenger but in my case I consider that to be a good thing and my back agrees!

Acompli Email Client for iPhone Review

Almost since the day I got my first iPhone I have been looking for a better email client and preferably one that also worked on the iPad too. I think I have tried pretty much all of them and the only one that has stuck is Sparrow which is sadly no longer maintain since Google bought it, grr.

A few weeks ago I was introduced to Acompli which merges email with the calendar, something that is so blindingly obviously that it is a surprise it hasn’t been done before. While the jury is still out on whether it stays or Sparrow makes a return it has lasted longer than all the others I have tried.

The app has four main tabs: Mail, Calendar, Files and People which pretty much do what they say on the tin. Files is an interesting one as it allows you to access all attachments you have sent or received on your accounts and then forward them onto a new recipient, which is neat, although I find it more likely that you would just forward the original email.

The email client is nicely done with a pretty intuitive interface and a easy swipe to Archive and Delete option, very similar to Mailbox. It also has a unified inbox, an absolute must for me. As I work for several organisations I have multiple email accounts and so switching between them all would be a pain. Seeing them all in one list is essential and because I practice inbox zero I never get swamped.

Unfortunately the calendar is nowhere near as polished as the email and has numerous “issues”:

  • doesn’t show events any further than about 10 weeks in advance
  • every event has an alarm whether set or not, which is very irritating
  • when scheduling events Acompli shows a conflict with all day events even if they are marked as not busy
  • days that have no events aren’t shown at all in the list view which I find confusing.

The People tab is nicely done allowing you to see the people you contact the most at the top. Clicking their name takes you to a list of your recent interactions with them and also has the option to call or email them, not not text which would be nice.

However, in order to pull together all this functionality all your email goes via Acompli’s servers.While the developers are up front about this in their privacy policy this will scare off a few.


Acompli is an interesting idea and I like having the calendar and email in one app but the calendar needs some work. Of course this is a first release and it is free so it’s seems a little churlish to grip. It’s certainly worth a look and right now I am persisting with it but I’ve not yet deleted Sparrow and Sunrise.


  • Slick email implementation
  • Useful to have email, calendar and people all in the same app
  • Unified inbox (a must for me which is why have rejected so many others)
  • Free


  • Calendar is nowhere near as polished as email
  • Can be slow in retrieving emails and updating but then nothing seems as quick as Sparrow