Bulk conversion of webp files to png format

Google has come up with a nice new image format called webp. Currently support for this format is fairly limited, so if you need to use webp images else where it might be nice to convert them to a more widely supported format. To do the conversion, Google has made a small tool available called dwebp. The tool however does only seem to support conversion of a single image, not a batch of images.

Using regular command line magic it’s easy though. Download the tool a pair it with the find and xargs command and you should quickly be on you way. If all the webp files needing conversion to png is in a single directory, simply do this:

find . -name "*.webp" | xargs -I {} dwebp {} -o {}.png

It findes all webp files, and converts them one by one. If the initial files name was image.webp the resulting file will be called image.webp.png (as the command above doesn’t remove the .webp but only appends .png at the end.

The command assumes the dwebp program is available in you include path. If this isn’t the case, you need to specify the complete path to the program.

Syntax checking PHP on the commandline

I’m sure most people only thing of PHP as a Weblanguage due to be called through a browser. It has however since version 4.3.0 also been possible to use PHP on the commandline – as you do with Perl, Shell scripts and likewise. If you’re using Linux (or an other Unix-like operating system – including Mac OSX) you probably have a few small programs available which can make it a breeze to check if the syntax in all you PHP scripts is correct.

Here’s how. On the commandline type:

find *.php |xargs -I {} php -l {}

… and here’s an explaination of what it does:

  • “find *.php” findes all files with a dot php ending.
  • the pipe-character “|” sends the result to a command called xargs.
  • “xargs -I {} php -l {}” takes the lines one by one password from the find and call “php -l <line input>”.
  • “php -l <line input>” (where line input would be the php-files found in bullit one) runs php with the “lint” parameter which does the syntax checking.