Android: 9 patching a family of images the easy way

9 patch images in Android are great but if you happen to have a family of graphics to convert, it can get pretty tedious. I had a collection of button graphics that needed converting to 9 patches using the same stretchable regions.

Rather than do it all by hand with Photoshop or GIMP (and inevitably need to redo them all again later when something needed changing) I wrote a small BASH script to do it.

To use the script, first use the draw9patch tool to create the 9 patch info for one of your graphics – this will become the template. Once you’re done, go:

./9batch.sh template.9.png button2.png button3.png ...

to copy the 1 pixel border from the template to your remaining graphics and save a .9.png version of each of them.

Note that you’ll need to install ImageMagick to use the 9batch script:

sudo apt-get install imagemagick

Apparently WordPress won’t let me upload the script itself so here’s the source code:

#!/bin/bash

if [ "$#" -lt 2 ]; then
echo "Usage: 9batch.sh template image1 image2 ..." >&2
echo
echo "Applies 9 patch info to a family of images using one image as the template" >&2
echo "Template image should be 2 pixels wider and higher than source images" >&2
exit 1
fi

# 9 patch image to use as template
src=$1

for i in ${@:2}
do
# use sed to change extension from .png to .9.png and assign result to 'out'
out=`echo $i | sed -e 's:\(....\)$:.9\1:'`
composite -gravity center $i $src $out
done
Advertisements

Linux: Fixing an unreliable network connection with ASUS P8Z 68-V onboard LAN

Recently I got a new ASUS P8Z 68-V motherboard and CPU, and had been having some strange network issues with it when running Gentoo Linux. The problems included connection failures after random periods of time and generally slow download speeds. The only way to get the connection running again after it failed (which was every few minutes at times) was to run:

ifconfig eth0 down
ifconfig eth0 up

On top of that, running ifconfig (with no args) was reporting 100% RX packets dropped for the interface.

This is the info on the network adapter:

$ lspci
...
07:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express
Gigabit Ethernet controller (rev 06)

At first I suspected there may have been something wrong with my (relatively new) Gentoo setup, so I did some testing running off an Ubuntu 11.10 live CD.  Interestingly this gave the same unreliable behaviour that wasn’t present when running Windows 7.

After further digging it turned out the problem was that the Linux kernel was loading the wrong module for the network adapter. This was confirmed by the presence of “r8169” in the output of lsmod.

The solution was to remove and blacklist the r8169 module and install Realtek’s official r8168 Linux kernel module from their website. On Gentoo I had compiled the kernel with the r8169 module built-in, so this meant first deselecting it and recompiling the kernel. After that, all that was left was to extract Realtek’s driver package and run ./autorun.sh as root.

Solution source: http://askubuntu.com/questions/46942/how-do-i-stop-my-ethernet-network-connection-from-dropping

Update:
In Linux Mint 12, you first need to run sudo apt-get install build-essential linux-headers-3.0.0-12-generic before running autorun.sh.

Ubuntu/Debian: see files installed by package

Checking the files installed by a package is easy enough with the Synaptic package manager (Right-click package > properties > installed files tab).

Here’s how to get that information without leaving the comfort (cough) of your bash terminal:

$ dpkg-query -L package_name

For example:

$dpkg-query -L flashplugin-installer
/.
/usr
/usr/lib
/usr/lib/xulrunner
/usr/lib/xulrunner/plugins
/usr/lib/mozilla
/usr/lib/mozilla/plugins
/usr/lib/iceape
/usr/lib/iceape/plugins
...