More tools for creating QR Codes in Linux

In my previous post I showed how to install CuterCode and Qreator, two simple GUI applications for producing QR Codes, in Gentoo Linux. I have now found a couple of other GUI applications, both of which offer more features than the aforementioned two, such as allowing you to specify the amount of error correction to be incorporated into the QR Code. QR Code codewords are 8 bits long and use the Reed–Solomon error correction algorithm, with four error correction levels possible in the case of QR Codes:

Level L (Low): 7% of codewords can be restored.
Level M (Medium): 15% of codewords can be restored.
Level Q (Quartile): 25% of codewords can be restored.
Level H (High): 30% of codewords can be restored.

The higher the level of error correction, the lower the storage capacity of the QR Code.

And now to the two applications …

Portable QR-Code Generator

This is a Java application, so first make sure you have installed a Java run-time environment (or Java Development Toolkit, which will include the JRE) via Portage.

Download to your home directory the archive qrcodegen_1.14.2.zip containing the compiled Java application, not the archive qrcodegen_1.14.2_src.zip with the source code (‘quellcode’ in German), from the application’s Web site. Unzip it to the directory ~/qrcodegen_1.14.2/ then enter the directory and launch the Java application from the command line as shown below:

$ cd ~/qrcodegen_1.14.2/qrcodegen
$ java -jar QRCodeGen.jar

Alternatively you can create a Desktop Configuration file QRCodeGen.desktop containing the following (change ‘fitzcarraldo’ to your own user name, of course):

[Desktop Entry]
Categories=Graphics
Comment[en_GB]=QR Code Generator is a program that lets you generate and print QR Codes easily.
Comment=QR Code Generator is a program that lets you generate and print QR Codes easily.
Exec=java -jar /home/fitzcarraldo/qrcodegen_1.14.2/qrcodegen/QRCodeGen.jar
GenericName[en_GB]=QRCodeGen
GenericName=QRCodeGen
Icon=/home/fitzcarraldo/qrcodegen_1.14.2/qrcodegen/icon.png
MimeType=
Name[en_GB]=QRCodeGen
Name=QRCodeGen
Path=/home/fitzcarraldo/qrcodegen_1.14.2/qrcodegen/
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=

and make it executable:

$ chmod +x QRCodeGen.desktop

You can choose a nice PNG icon by using Google Images to search for ‘qr code icon png’ and save the image with the file name icon.png in the same directory. Then you can launch QR code Generator by double-clicking on the Desktop Configuration file.

QtQR – QR Code Generator

Download the tarball qr-tools-1.2.tar.gz from the application’s Web site, unpack it to the directory ~/qr-tools-1.2/ and make the Python scripts executable:

$ cd ~/qr-tools-1.2/qr-tools
$ chmod +x qtqr.py
$ chmod +x qrtools.py

Make sure you have installed the package media-gfx/zbar with the python USE flag set, so that the Python zbar module is also installed:

# USE="python" emerge zbar

(You may as well add the python USE flag in the line for media-gfx/zbar in the Portage package.use file so that ZBar’s Python module is installed if you upgrade or re-install ZBar via Portage in future).

Check if the Python Imaging Library (fork) dev-python/pillow is already installed:

# emerge --search pillow

If it is not already installed, install it:

# emerge pillow

Now you can launch QtQR from the command line as follows:

$ cd ~/qr-tools-1.2/qr-tools
$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so PYTHONPATH=/usr/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages/PIL ./qtqr.py

Alternatively, you can create a Desktop Configuration file qtqr.desktop with the following contents (change ‘fitzcarraldo’ to your own user name, of course):

[Desktop Entry]
Categories=Graphics
Comment[en_GB]=QtQR is a Qt based software that lets you generate QR Codes easily, scan an image file for a QR Code and decode it or use your webcam to scan a printed one.
Comment=QtQR is a Qt based software that lets you generate QR Codes easily, scan an image file for a QR Code and decode it or use your webcam to scan a printed one.
Exec=LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so PYTHONPATH=/usr/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages/PIL /home/fitzcarraldo/qr-tools-1.2/qr-tools/qtqr.py
GenericName[en_GB]=QtQR
GenericName=QtQR
Icon=/home/fitzcarraldo/qr-tools-1.2/qr-tools/icon.png
MimeType=
Name[en_GB]=QtQR
Name=QtQR
Path=/home/fitzcarraldo/qr-tools-1.2/qr-tools/
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=

and make it executable:

$ chmod +x qtqr.desktop

Then you can launch QtQR by double-clicking on the Desktop Configuration file.

The QtQR GUI has a feature for decoding a QR Code in an image file and for decoding a printed QR Code held in front of a Webcam. If I select ‘Decode’ > ‘Decode from Webcam’, QtQR launches ZBar and, although it is a bit fiddly, I can successfully decode a printed QR Code. However, I cannot get QtQR to decode a QR Code in an image file that QtQR itself created (or to decode a QR Code in a file created by any other application, for that matter), so there is a bug in QtQR. Looking at the application’s bug reports this appears to be Bug No. 811576. It’s not a big deal, though, because the zbarimg command provided by ZBar can be used to decode QR Codes (see my post Installing and using ZBar in Linux to scan bar codes with your Webcam).

$ cd ~/qr-tools-1.2/qr-tools
$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so PYTHONPATH=/usr/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages/PIL ./qtqr.py
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:127: RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK
  set_interactive(1)
Object::connect: No such signal org::freedesktop::UPower::DeviceAdded(QDBusObjectPath)
Object::connect: No such signal org::freedesktop::UPower::DeviceRemoved(QDBusObjectPath)
kfilemodule(32309) KSambaSharePrivate::testparmParamValue: Running testparm ("-d0", "-s", "--parameter-name", "usershare path")
Traceback (most recent call last):
  File "./qtqr.py", line 481, in decodeFile
    if qr.decode():
  File "/home/fitzcarraldo/qr-tools-1.2/qr-tools/qrtools.py", line 147, in decode
    pil = Image.open(self.filename).convert('L')
  File "/usr/lib/python2.7/site-packages/PIL/Image.py", line 2256, in open
    % (filename if filename else fp))
IOError: cannot identify image file u'/home/fitzcarraldo/qr-tools-1.2/qr-tools/test.png'

Linux Magazine has a good article on these and other QR Code tools: Generating QR Codes in Linux.

UPDATE (March 30, 2015): You can download an updated working revision (Revision 20) of the Python script qrtools.py, and an updated working revision (Revision 21) of the Python script qtqr.py, from the QtQR and QR Tools developers’ repository where they have been working on an as-yet unreleased Version 1.4 of QtQR and QR Tools:

http://bazaar.launchpad.net/~qr-tools-developers/qr-tools/trunk/files

I have briefly tested qrtools.py Revision 20 and qtqr.py Revision 21 with the other QR Tools Version 1.2 files I downloaded earlier. I simply downloaded the Revison 20 qrtools.py file and the Revision 21 qtqr.py file and overwrote the qrtools.py and qtqr.py files I had extracted earlier from qr-tools-1.2.tar.gz into the directory /home/fitzcarraldo/qr-tools-1.2/qr-tools/ (and made them executable). With the new qrtools.py and new qtqr.py it is now possible for QtQR to decode QR Codes in image files as well as QR Codes scanned via a Webcam, so the bug I mentioned above should be fixed in the next official release of QtQR/QR Tools. So you may as well skip the official Version 1.2 and download all the files from the above-mentioned developers’ repository for the future Version 1.4.

How to create QR Codes easily in Gentoo Linux

QR Codes are two-dimensional bar codes that can store a surprising amount of information. CuterCode and Qreator are two applications that are easy to install and use to produce QR Codes that can be saved as image files for use on labels, posters, Web sites, business cards, documents, etc. Here is how to install CuterCode and Qreator in Gentoo Linux.

Example of a QR Code

A QR Code created using Qreator. You can read it using the Android app Barcode Scanner by ZXing Team and several other Android apps, and also using a Linux app (see my post on ZBar).

CuterCode

This is a Python script and simple GUI.

https://github.com/mnagel/cutercode

First download the script itself:

$ wget https://raw.githubusercontent.com/mnagel/cutercode/master/cutercode
$ wget https://raw.githubusercontent.com/mnagel/cutercode/master/cutercode.ui

Make the Python script exectuable:

$ chmod +x cutercode

Then install the package media-gfx/qrencode-python (it will pull-in the package media-gfx/qrencode) on which it depends:

# emerge qrencode-python

To launch the application:

$ ./cutercode

Use the Print Scrn key on your keyboard to launch KSnapshot (or whatever screen capture tool it is you use) and capture the QR Code to a JPG or PNG file for use in you documents. That’s it!

Qreator

The UI of Qreator is more polished than CuterCode, and you have the options to save the QR Code as a PNG file, copy it to the clipboard, print it or edit its appearance.

https://launchpad.net/qreator

Either merge it from Portage overlay dev-zero using layman:

# layman -S
# layman -a dev-zero
# emerge qreator

or download the dev-zero files into your local overlay and install it from there:

# mkdir -p /usr/local/portage/app-office/qreator/files
# cd /usr/local/portage/app-office/qreator
# wget http://data.gpo.zugaina.org/dev-zero/app-office/qreator/qreator-13.05.3.ebuild
# cd files
# wget http://data.gpo.zugaina.org/dev-zero/app-office/qreator/files/13.05.3-python-imaging.patch
# cd ..
# ebuild qreator-13.05.3.ebuild manifest
# emerge qreator

If you happen to be a KDE user, you will find a menu entry for Qreator is installed under ‘Applications’ > ‘Graphics’ in the KDE launcher, or you can launch it from the command line:

$ qreator

Background reading

QR Code – Wikipedia
QRcode.com – Answers to your questions about the QR Code

Getting Google Earth in Gentoo Linux to display Panoramio photos

Well, I decided to get Panoramio photos working in Google Earth installed using the hacked ebuild I posted in April 2014 (see my post Work-around if 64-bit Google Earth crashes in Gentoo Linux).

The modification devised by user amirpli (see Comment #9 in Gentoo Bugzilla Bug Report No. 490066) does not work in my case, as explained in detail in the above-mentioned April 2014 post. I believe this is because I am using the FGLRX video driver, as I have successfully applied amirpli‘s modification in an installation on a PC that has an Intel GPU.

Here is how I got Panoramio photos to display on my main laptop running the FGLRX driver, although my fix is yet another hack: I use 32-bit libraries downloaded from the Web. It works for me, though!

Background

I am running Google Earth 7.1.2.2041 installed from a local overlay (see my above-mentioned April 2014 post) in KDE 4.14.3 under Gentoo Linux ~amd64 with the 3.17.1-gentoo-r1 kernel and FGLRX driver:

# eix ati-drivers
[I] x11-drivers/ati-drivers
     Available versions:
     (legacy) 13.1_pre897^td
     (1)    13.4^td 13.9^td 13.12^td 14.4_p1^td (~)14.6_beta2^td (~)14.9-r2^ftd (~)14.12-r2^td 14.12-r3^td
       {debug disable-watermark +modules multilib pax_kernel qt4 static-libs ABI_X86="32 64" KERNEL="linux"}
     Installed versions:  14.12-r3(1)^td(20:22:04 13/02/15)(modules qt4 -debug -pax_kernel -static-libs ABI_X86="32 64" KERNEL="linux")
     Homepage:            http://www.amd.com
     Description:         Ati precompiled drivers for Radeon Evergreen (HD5000 Series) and newer chipsets

Procedure

1. Download into ~/Downloads/ the following Ubuntu 32-bit packages from http://packages.ubuntu.com/utopic/i386/libs/

$ ls -la *.deb
-rw-r--r-- 1 fitzcarraldo users  24060 Mar  1 23:59 libecore-imf1_1.8.6-2ubuntu1_i386.deb
-rw-r--r-- 1 fitzcarraldo users 274206 Mar  1 22:59 libfreeimage3_3.15.4-3build1_i386.deb
-rw-r--r-- 1 fitzcarraldo users  52154 Mar  1 23:45 libilmbase6_1.0.1-6.1_i386.deb
-rw-r--r-- 1 fitzcarraldo users 135300 Mar  2 00:28 libjasper1_1.900.1-debian1-2ubuntu0.2_i386.deb
-rw-r--r-- 1 fitzcarraldo users 106868 Mar  1 23:00 libjpeg-turbo8_1.3.0-0ubuntu2_i386.deb
-rw-r--r-- 1 fitzcarraldo users  98500 Mar  1 23:39 libopenjpeg5_1.5.2-2_i386.deb
-rw-r--r-- 1 fitzcarraldo users 189420 Mar  2 00:21 libraw10_0.16.0-6_i386.deb

2. Download into ~/Downloads/ the following 32-bit packages from http://rpmfind.net/linux/rpm2html/search.php and http://pkgs.org/

$ ls -la *.rpm
-rw-r--r-- 1 fitzcarraldo users  57976 Mar  2 00:13 libilmbase6-1.0.2-11.1.2.i586.rpm
-rw-r--r-- 1 fitzcarraldo users 148379 Mar  2 00:03 libilmimf6-1.6.1-alt9.i586.rpm

3. Extract into ~/Downloads/ the following 32-bit libraries from the above-mentioned .deb and .rpm packages:

$ ls -la lib*.so*
-rw-r--r-- 1 fitzcarraldo users 644568 Apr 27  2014 libfreeimage-3.15.4.so
-rw-r--r-- 1 fitzcarraldo users 677340 Apr 27  2014 libfreeimageplus-3.15.4.so
-rwxr-xr-x 1 fitzcarraldo users 271780 Jul 15  2012 libHalf.so.6.0.0
-rwxr-xr-x 1 fitzcarraldo users 104044 Jul 15  2012 libIex.so.6.0.0
-rw-r--r-- 1 fitzcarraldo users 671896 Dec  3 15:06 libIlmImf.so.6.0.0
-rwxr-xr-x 1 fitzcarraldo users  22260 Jul 15  2012 libIlmThread.so.6.0.0
-rw-r--r-- 1 fitzcarraldo users 342116 Jan 22 18:46 libjasper.so.1.0.0
-rw-r--r-- 1 fitzcarraldo users 300776 Dec 19  2013 libjpeg.so.8.0.2
-rw-r--r-- 1 fitzcarraldo users 142604 Apr 26  2014 libopenjpeg.so.1.5.2
-rw-r--r-- 1 fitzcarraldo users 657336 Jul 22  2014 libraw.so.10.0.0

4. Merge the 32-bit Google Earth package from a local overlay, using the ebuild listed in my above-mentioned April 2014 post:

# emerge -C googleearth
# rm -rf /opt/googleearth/
# emerge googleearth::local_overlay

5. Delete the four bundled Qt libs, compile the shim devised by user amirpli (see Comment #9 in Gentoo Bugzilla Bug Report No. 490066) but compile it for 32 bits (‘-m32‘), and edit the googleearth script to use the 32-bit libfreeimage.so.3 that you will copy into /opt/googleearth/ later:

# cd /opt/googleearth
# rm libQt*
# touch baifaao.cpp
# nano baifaao.cpp
# cat baifaao.cpp
/* amirpli 2013/11/28 */
#include <QtCore/QAtomicInt>
extern "C" {
        int _Z34QBasicAtomicInt_fetchAndAddOrderedPVii(QAtomicInt* a, int b) {
                return a->fetchAndAddOrdered(b);
        }
}
# gcc -I/usr/include/qt4 -O3 -m32 -fPIC --shared baifaao.cpp -o baifaao.so
# nano googleearth
# tail googleearth
}

script_path=$(FindPath $0);

cd $script_path;

export LD_PRELOAD=/opt/googleearth/libfreeimage.so.3:/opt/googleearth/baifaao.so
export LC_NUMERIC=en_US.UTF-8 # Must do this if you are using non-US locale.

LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./googleearth-bin "$@"

6. Copy into the Google Earth directory all the libraries downloaded and extracted in Steps 1 to 3 above, and create the necessary symlinks and permissions:

# cd /opt/googleearth
# cp /home/fitzcarraldo/Downloads/libfreeimage-3.15.4.so .
# cp /home/fitzcarraldo/Downloads/libfreeimageplus-3.15.4.so .
# ln -s libfreeimage-3.15.4.so libfreeimage.so.3
# ln -s libfreeimage.so.3 libfreeimage.so
# ln -s libfreeimageplus-3.15.4.so libfreeimageplus.so.3
# ln -s libfreeimageplus.so.3 libfreeimageplus.so
# chmod +x libfreeimage-3.15.4.so
# chmod +x libfreeimageplus-3.15.4.so
# cp /home/fitzcarraldo/Downloads/libjpeg.so.8.0.2 .
# ln -s libjpeg.so.8.0.2 libjpeg.so
# ln -s libjpeg.so libjpeg.so.8
# chmod +x libjpeg.so.8.0.2
# cp /home/fitzcarraldo/Downloads/libopenjpeg.so.1.5.2 .
# ln -s libopenjpeg.so.1.5.2 libopenjpeg.so
# ln -s libopenjpeg.so libopenjpeg.so.5
# chmod +x libopenjpeg.so.1.5.2
# cp /home/fitzcarraldo/Downloads/libIlmImf.so.6.0.0 .
# ln -s libIlmImf.so.6.0.0 libIlmImf.so
# ln -s libIlmImf.so libIlmImf.so.6
# chmod +x libIlmImf.so.6.0.0
# cp /home/fitzcarraldo/Downloads/libHalf.so.6.0.0 .
# ln -s libHalf.so.6.0.0 libHalf.so
# ln -s libHalf.so libHalf.so.6
# chmod +x libHalf.so.6.0.0
# cp /home/fitzcarraldo/Downloads/libIex.so.6.0.0 .
# ln -s libIex.so.6.0.0 libIex.so
# ln -s libIex.so libIex.so.6
# chmod +x libIex.so.6.0.0
# cp /home/fitzcarraldo/Downloads/libraw.so.10.0.0 .
# ln -s libraw.so.10.0.0 libraw.so
# ln -s libraw.so libraw.so.10
# chmod +x libraw.so.10.0.0
# cp /home/fitzcarraldo/Downloads/libIlmThread.so.6.0.0 .
# ln -s libIlmThread.so.6.0.0 libIlmThread.so
# ln -s libIlmThread.so libIlmThread.so.6
# chmod +x libIlmThread.so.6.0.0
# cp /home/fitzcarraldo/Downloads/libjasper.so.1.0.0 .
# ln -s libjasper.so.1.0.0 libjasper.so
# ln -s libjasper.so libjasper.so.1
# chmod +x libjasper.so.1.0.0

Finally, launch Google Earth from your user account, not the root user’s account:

$ googleearth

Clicking on any photo icon in Google Earth should now display Panoramio photos.

If you click on a photo icon and the frame that opens displays several thumbnails, clicking on a thumbnail may result in a white Panoramio frame without any photo and thumbnails displayed. According to user amirpli this problem occurs in KDE but not GNOME. If it does happen in your case, to view the other photos right-click on a thumbnail and select ‘Open in New Window’. This way you will be able to view any of the photos.

It’s nice to be able to see the Panoramio photos again in Linux with the FGLRX driver.

Installing and configuring the CUPS-PDF virtual printer driver

Some applications, such as LibreOffice, have built-in support for exporting their output to PDF files. For applications without built-in support for creating PDF files there may already be an installed ‘Print to File (PDF)’ driver in your installation that you can use. However, the Print to File (PDF) option does not appear in the list of available printers in all applications. Fortunately, CUPS has a driver named CUPS-PDF which you can install to create a virtual printer that will produce PDF files.

I install the package net-print/cups-pdf and use the CUPS Printer Manager in a browser to set up a virtual printer to ‘print’ PDF files. I use the driver in conjunction with a shell script that calls a utility to display a ‘Save As’ dialogue box so the user can specify the directory and name of the PDF file.

KDialog (KDE/Qt) and Zenity (GTK+) are two well-known dialogue box tools for use in shell scripts (see, for example, the Linux Magazine article Adding graphic elements to your scripts with Zenity and KDialog). However, although I use KDE on my main laptop, I was unable to get KDialog working properly in a shell script launched by the CUPS PDF driver, so I resorted to using Zenity, which I found simple to use and reliable. My shell script using Zenity is listed further down.

Although Zenity has performed this job perfectly for me in all releases of KDE since 2007, it rankled that I could not get KDialog to do the job. However, a couple of Gentoo users were able to use KDialog successfully with the CUPS PDF driver, each with a different approach to the other, but their approaches both consisted of two shell scripts. In contrast, a solution using Zenity uses only one shell script. You can see the KDialog solutions by the two users (Havin_it and sicvolo) in Gentoo Forums thread [TIP] CUPS-PDF “Save As” with kdialog. I was determined to have a single shell script using KDialog, and was able to conflate sicvolo‘s two-script solution. My thanks go to him for his clever code in his two shell scripts, as I would never have worked it out myself. My single shell script using KDialog is listed further down.

First I will explain how to install the CUPS PDF driver package, then how to use the CUPS Printer Manager to install the virtual printer, and finally how to use a shell script with either Zenity or KDialog in order to display a graphical dialogue box prompting you to specify the directory and file name for the PDF file to be created. I use Gentoo Linux, but the procedure will be similar in other distributions (package manager commands excepted).

1.0  Installation of the cups-pdf driver and virtual printer

1.1  Install the cups-pdf package:

# emerge cups-pdf

1.2  Launch a Web browser and enter http://localhost:631/ in the Address bar to display the CUPS Printer Manager.

1.3  Click on ‘Administration’ to call up the Administration page, then click ‘Add Printer’. If prompted, enter the username ‘root’ (without the quotes) and the root user’s password.

1.4  Select ‘CUPS-PDF (Virtual PDF Printer)’ in the list of local printers, and click ‘Continue’.

1.5  Enter a name, decription and location for the virtual printer. For example, I entered ‘Virtual_PDF_Printer’, ‘Virtual PDF Printer’ and ‘Mesh Edge DX’ (without the quotes), respectively. Then click ‘Continue’.

1.6  Select ‘Generic’ in the ‘Make:’ box, and click ‘Continue’.

1.7  Select ‘Generic CUPS-PDF Printer (w/ options) (en)’ in the ‘Model:’ box, and click ‘Add Printer’. The virtual printer should now be available for you to use.

1.8  When you come to print from an application, if you select Virtual_PDF_Printer from the list of available printers the PDF file will be saved in the directory /var/spool/cups-pdf/<your username>/. Note that the directory will be created automatically the first time you ‘print’ to PDF.

1.9  Optionally, you could create a shortcut (Desktop Config File) on your Desktop to open the directory mentioned in Step 1.8 above.

1.10 Optionally, instead of Step 1.9 you could edit the file /etc/cups/cups-pdf.conf as root user to get cups-pdf to ‘print’ PDF documents to your Desktop instead of in /var/spool/cups-pdf/<your username>/, by changing the line:

#Out /var/spool/cups-pdf/${USER}

to:

Out ${HOME}/Desktop


2.0  How to display a dialog box prompting for the directory and file name of the PDF file

If you prefer to be prompted for a file name so that you can save the PDF file wherever you want and give it any name you want, perform the steps below instead of Steps 1.9 or 1.10 above. Either perform the steps in 2.1 (Zenity) or the steps in 2.2 (KDialog). Then perform the steps in 2.3, which apply in both cases.

2.1   Zenity (GTK+)

2.1.1   Install Zenity:

# emerge zenity

2.1.2   Check it is installed:

# eix -I zenity
[I] gnome-extra/zenity
Available versions: 3.12.1 {debug libnotify test +webkit}
Installed versions: 3.12.1(13:49:47 04/12/14)(libnotify webkit -debug -test)
Homepage: https://wiki.gnome.org/Projects/Zenity
Description: Tool to display dialogs from the commandline and shell scripts

2.1.3   Using a text editor, create the following shell script in your home directory and give it a meaningful name, such as cups-pdf_script.sh:

#!/bin/bash
CURRENT_PDF="${1}"
CURRENT_USER="${2}"
DISPLAY=:0.0
export DISPLAY
XAUTHORITY=/home/${CURRENT_USER}/.Xauthority
export XAUTHORITY
PDFNAME=$(zenity --file-selection --save --confirm-overwrite)
mv "$CURRENT_PDF" "$PDFNAME"

2.2   KDialog (KDE/Qt)

2.2.1   Install KDialog:

# emerge kde-base/kdialog

2.2.2   Check it is installed:

# eix -I kde-base/kdialog
[I] kde-base/kdialog
Available versions: (4) 4.12.5(4/4.12) (~)4.14.2(4/4.14) (~)4.14.3(4/4.14)
{aqua debug}
Installed versions: 4.14.3(4)(00:56:36 04/12/14)(-aqua -debug)
Homepage: http://www.kde.org/
Description: KDialog can be used to show nice dialog boxes from shell scripts

2.2.3   Using a text editor, create the following shell script in your home directory and give it a meaningful name such as cups-pdf_script.sh:

#!/bin/bash

get_dbus()
{
if [ -z $1 ]; then
    echo "specify user" >> $HOME/cups-pdf_script.log
    return 1
fi
# Search these processes for the session variable (they are run as the current user and have the DBUS session variable set)
compatiblePrograms=( kdeinit kded4 pulseaudio trackerd )

# Attempt to get a program pid
for index in ${compatiblePrograms[@]}; do
   PID=$(ps -ef | grep $1 | grep ${index} | head -1 | awk '{print $2}')
   if [[ "${PID}" != "" ]]; then
      break
   fi
done
if [[ "${PID}" == "" ]]; then
   echo "Could not detect active login session" >> $HOME/cups-pdf_script.log
   return 1
fi
QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [[ "${QUERY_ENVIRON}" != "" ]]; then
#   echo ${QUERY_ENVIRON} >> $HOME/cups-pdf_script.log
   return 0
else
   echo "Could not find dbus session ID in user environment." >> $HOME/cups-pdf_script.log
   return 1
fi
}

CURRENT_PDF="$1"
CURRENT_USER="$2"

export DISPLAY=:0
export XAUTHORITY=/home/${CURRENT_USER}/.Xauthority
export HOME=/home/${CURRENT_USER}/
CONFIG_FILE="/home/${CURRENT_USER}/.pdf-writer.conf"
CANCELLED="No"

date > $HOME/cups-pdf_script.log

get_dbus ${CURRENT_USER}
if [ $? -eq 0 ]; then
   export DBUS_SESSION_BUS_ADDRESS=${QUERY_ENVIRON}
   while [ True ]; do
      CURDATE=$(/bin/date +%Y%m%d)
      CURNAME=$(/bin/cat "$CONFIG_FILE")
      BASENAME=$(basename $CURRENT_PDF)
      FILENAME=$(/usr/bin/kdialog --getsavefilename "$CURNAME$CURDATE-" "*.pdf" --title="Save PDF")
      if [ $? -eq 1 ]; then
         CANCELLED="Yes"
         break
      fi
      echo $FILENAME
      if [ ! "$FILENAME" = "" ]; then
         if [ -e "$FILENAME" ]; then
            /usr/bin/kdialog --warningcontinuecancel "File already exists"
            if [ $? -eq 1 ]; then
               continue;
            fi
         fi
         FILENAME=$(echo $FILENAME.pdf | sed -re "s/(\.pdf)+$/.pdf/g")
         break;
      else
         /usr/bin/kdialog --error "You must select a file or hit Cancel."
      fi
      break
   done
   if [ "${CANCELLED}" == "No" ]; then
      /bin/cp "${CURRENT_PDF}" "${FILENAME}"
      okular "${FILENAME}" &
   fi
   /bin/rm "${CURRENT_PDF}"
   echo "No errors encountered." >> $HOME/cups-pdf_script.log
   exit 0
else
   /bin/rm "${CURRENT_PDF}"
   echo "Errors encountered." >> $HOME/cups-pdf_script.log
   exit 1
fi

2.3   Whichever of the above two options (Zenity or KDialog) you chose, do the following:

2.3.1   Make the shell script file executable:

# chmod +x /home/<your username>/cups-pdf_script.sh

2.3.2   Edit the file /etc/cups/cups-pdf.conf, find the line starting with ‘#PostProcessing‘, and change it to:

PostProcessing /home/<your username>/cups-pdf_script.sh

2.3.3   Restart CUPS:

# /etc/init.d/cupsd restart # If your installation uses OpenRC.

# systemctl restart cups.service # If your installation uses systemd.

Now, when you select Virtual_PDF_Printer from your applications’ list of available printers and click ‘Print’, a pop-up window should appear, allowing you to select the target directory for the PDF file and enter a file name of your choice.

Work-around if 64-bit Google Earth crashes in Gentoo Linux

Google Earth 5.2.1.1588 was the last version of Google Earth for Linux that worked on my main laptop running 64-bit Gentoo Linux. Even the Panoramio photos were displayed (a common complaint amongst users of Google Earth for Linux). But every subsequent version crashed when I launched it. The latest version, 7.1.2.2041, is no exception:

$ googleearth
[0403/012031:ERROR:net_util.cc(2195)] Not implemented reached in bool net::HaveOnlyLoopbackAddresses()
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:WARNING:backend_impl.cc(1875)] Destroying invalid entry.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
[0403/012033:ERROR:nss_ocsp.cc(581)] No URLRequestContext for OCSP handler.
Google Earth has caught signal 11.



We apologize for the inconvenience, but Google Earth has crashed.
This is a bug in the program, and should never happen under normal
circumstances. A bug report and debugging data have been written
to this text file:

/home/fitzcarraldo/.googleearth/crashlogs/crashlog-533ca953.txt

Please include this file if you submit a bug report to Google.

Now, the Google Earth installation package bundles the libraries it needs, so they are used instead of the ‘native’ libraries installed on your machine. A Linux user going by the moniker amirpli worked out how to enable Google Earth for Linux to use the native Qt libraries rather than the Qt libraries bundled with Google Earth, and posted instructions for a number of distributions (see, for example, Comment 9 in Gentoo Bugzilla Bug Report No. 490066). However, even if I apply amirpli‘s fix, Google Earth on my main laptop crashed with almost the same error message as above. Looking through the crash log file that Google Earth generates, I see the following line, which makes me suspect that Google Earth cannot work with the closed-source AMD ATI Catalyst driver (a.k.a. FGLRX):

./libbase.so(_ZN5earth15GfxCardInfoUnix25GetGraphicsCardMemoryInMBERi+0xe)[0x7f011b3e654e]

I noticed a few posts by users of other distributions in various forums saying that they had installed the 32-bit version of Google Earth in their 64-bit (multilib) installations, so I decided to try that in Gentoo. I hacked the ebuild of version 7.1.2.2041 to force it to install the 32-bit version of Google Earth on my 64-bit multilib installation, and installed it via a local overlay.

The hacked ebuild has the following changes from the stock 7.1.2.2041 ebuild:

a) Replace:

SRC_URI="x86? ( http://dl.google.com/dl/earth/client/current/google-earth-stable_current_i386.deb
                       -> GoogleEarthLinux-${PV}_i386.deb )
       amd64? ( http://dl.google.com/dl/earth/client/current/google-earth-stable_current_amd64.deb
                       -> GoogleEarthLinux-${PV}_amd64.deb )"

with:

SRC_URI="http://dl.google.com/dl/earth/client/current/google-earth-stable_current_i386.deb
                       -> GoogleEarthLinux-${PV}_i386.deb"


b) Replace:

unpack_deb GoogleEarthLinux-${PV}_$(usex amd64 "amd64" "i386").deb

with:

unpack_deb GoogleEarthLinux-${PV}_i386.deb


c) Replace:

patchelf --set-interpreter /lib/ld-linux$(usex amd64 "-x86-64" "").so.2 ${PN}-bin || die "patchelf failed"

with:

patchelf --set-interpreter /lib/ld-linux.so.2 ${PN}-bin || die "patchelf failed"


If you have not used a local overlay before, it is not difficult — just follow the steps given below.

1. If you have not done it before, tell Portage the location of the local overlay:

# echo 'PORTDIR_OVERLAY="${PORTDIR_OVERLAY} /usr/local/portage/"' >> /etc/make.conf

2. If you have not done it before, give your local overlay a name:

# mkdir /usr/local/portage/profiles
# echo "local_overlay" > /usr/local/portage/profiles/repo_name

3. Create the directories for the local overlay’s Google Earth ebuild and its associated files:

# mkdir -p /usr/local/portage/sci-geosciences/googleearth/files

4. Uninstall the non-functioning 64-bit version of Google Earth that you installed from the Portage main tree:

# emerge -C googleearth

5. Copy the main tree’s ebuild and associated files to the local overlay and edit the ebuild as per the changes I listed above:

# cp /usr/portage/sci-geosciences/googleearth/googleearth-7.1.2.2041.ebuild /usr/local/portage/sci-geosciences/googleearth/
# cp /usr/portage/sci-geosciences/googleearth/files/* /usr/local/portage/sci-geosciences/googleearth/files/
# cd /usr/local/portage/sci-geosciences/googleearth/
# nano googleearth-7.1.2.2041.ebuild

6. Create the manifest for the ebuild and associated files:

# ebuild googleearth-7.1.2.2041.ebuild manifest

7. Finally, install the package:

# emerge googleearth::local_overlay

The 32-bit version of Google Earth works fine in my 64-bit multilib installation, although the Panoramio photos are not displayed, but then Linux users are used to that :-/. Come on Google, you can do better than this!

Update (March 2, 2015): See my post Getting Google Earth in Gentoo Linux to display Panoramio photos for a way to get Google Earth in Gentoo Linux to display the Panoramio photos.

Installing the Windows version of Google Earth in WINE

Some Gentoo Linux users have reported that, although the native Linux release of Google Earth crashes, they can run the Windows version successfully under WINE. However, those users have also reported that the Windows installer for Google Earth did not work under WINE and so they copied the C:\Program Files\Google\Google Earth\ directory from a Windows PC to the virtual C:\ drive in their .wine directory (it would be ‘Program Files (x86)‘ in a 64-bit Windows installation, as Google Earth is a 32-bit application).

Now, if you download the Windows Google Earth installer from the Google Web site, what you get is a file GoogleEarthWin.exe that is 534.6 KiB in size (the size may vary depending on the release). However, you can instead download the Offline Installer using the following URL:

http://dl.google.com/earth/client/advanced/current/GoogleEarthWin.exe

and then you get a file GoogleEarthWin.exe that is 24.3 MiB in size (the size will vary depending on the release), which does run in WINE and does install the Windows version of Google Earth in WINE.

So, you might like to try that if you cannot run Google Earth in Linux but you have WINE installed. However, note that you will be wasting your time if the native Linux version of Google Earth crashes because of its incompatibility with the closed-source ATI or NVIDIA video driver. For example, Google Earth 7.1.2.2041 for Linux crashes on my main laptop using the 14.3_beta version of ati-drivers (AMD ATI Catalyst driver, a.k.a. FGLRX).

Anyway, if you want to install the Windows release of Google Earth under WINE here’s how to do it in a Konsole/Terminal window:

$ cd
$ export WINEPREFIX=$HOME/.wine-googleearth
$ export WINEARCH="win32"
$ winecfg
$ cd ./.wine-googleearth/drive_c/
$ wget http://dl.google.com/earth/client/advanced/current/GoogleEarthWin.exe
$ wine GoogleEarthWin.exe

And, to run it later:

$ env WINEPREFIX="/home/fitzcarraldo/.wine-googleearth" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix /home/fitzcarraldo/.wine-googleearth/dosdevices/c:/users/fitzcarraldo/Start\ Menu/Programs/Google\ Earth/Google\ Earth.lnk

(Of course replace “fitzcarraldo” with your user name.)

But, as I wrote above, if the native Linux version of Google Earth crashes due to its incompatibility with the closed-source video driver (ATI or NVIDIA), it is highly unlikely the native Windows version will work under WINE.

Split an A4 PDF file into two A5 PDF files

This week I scanned a couple of receipts in order to submit them to a client with an expenses claim. The two receipts were physically small enough to both fit on an A4 page, so I lay them both on the bed of a scanner and produced a PDF file with the two receipts on one A4 page. The resulting scan looked rather like the sketch in Figure 1. However, a couple of days later I remembered that the client wanted copies of receipts to be submitted individually, but the office scanner had stopped working and so I needed to split the original PDF file into two PDF files containing images rather like the sketches in Figures 2 and 3.

Figure 1 - original A4 image

Figure 1 - original A4 image

Figure 2 - A5 bottom half of original A4 image

Figure 2 - A5 bottom half of original A4 image

Figure 3 - A5 top half of original A4 image

Figure 3 - A5 top half of original A4 image

I was surprised to find little information on the Web about how to do such a thing. I did come across three applications that looked like they probably could do the job: jPdf Tweak, BRISS and krop. jPdf Tweak is in the Portage main tree (app-text/jpdftweak). BRISS isn’t. The krop Web page does have a link to an ebuild which could be downloaded and installed via a local overlay. I did have a brief play with jPdf Tweak and it looks powerful, but I did not find it particularly intuitive and I would need to study the manual in detail. Anyway, I thought I would try a command line approach for the fun of it.

Searching the Web I came across a site with a Perl script that looked promising: Split (crop) double page PDFs in two posted by someone called iblis (to whom I’m grateful). It uses a Perl module PDF:API2 which does exist in the Portage main tree (dev-perl/PDF-API2) and which I already had installed. I modified the last couple of lines of the script very slightly, so it now looks like this:

#!/usr/bin/env perl
use strict; use warnings;
use PDF::API2;
     
my $filename = shift || 'test.pdf';
my $oldpdf = PDF::API2->open($filename);
my $newpdf = PDF::API2->new;
     
for my $page_nb (1..$oldpdf->pages) {
my ($page, @cropdata);
     
$page = $newpdf->importpage($oldpdf, $page_nb);
@cropdata = $page->get_mediabox;
$cropdata[2] /= 2;
$page->cropbox(@cropdata);
$page->trimbox(@cropdata);
$page->mediabox(@cropdata);
     
$page = $newpdf->importpage($oldpdf, $page_nb);
@cropdata = $page->get_mediabox;
$cropdata[0] = $cropdata[2] / 2;
$page->cropbox(@cropdata);
$page->trimbox(@cropdata);
$page->mediabox(@cropdata);
}
     
(my $newfilename = $filename) =~ s/(.*)\.(\w+)$/$1.split.$2/;
$newpdf->saveas($newfilename);
     
__END__

I saved it with the file name split_pdf_A4_to_A5.pl and made it executable:

$ chmod +x split_pdf_A4_to_A5.pl

Then I used the following procedure to split the original PDF file:

1. I used the excellent command line utility pdftk (the package app-text/pdftk in Gentoo), which I had already installed, to rotate the A4 page clockwise and save it in a file named rotated.pdf:

$ pdftk original.pdf rotate 1-1right output rotated.pdf

Now the A4 page looked similar to the sketch in Figure 4.

Figure 4 - original A4 image, rotated clockwise by 90 degrees

Figure 4 - original A4 image, rotated clockwise by 90 degrees

2. I used the Perl script to split the A4 page into two A5 pages within one PDF file:

$ ./split_pdf_A4_to_A5.pl rotated.pdf

The above command created a file rotated.split.pdf containing two A5 pages.

3. Finally, I split the two-page PDF file into two separate single-page files:

$ pdftk rotated.split.pdf burst

which left me with two A5 PDF files named page_0001.pdf and page_0002.pdf similar to the sketches in Figures 2 and 3 above.

Mission accomplished. :-)

Installing and using ZBar in Linux to scan bar codes with your Webcam

ZBar is an application that can scan and decode several bar code symbologies (including QR Code) from sources such as a Webcam or an image file. I had been wanting to install it for some time and was finally spurred on to do it by a request for help to get it working in the Sabayon Linux forums. Here are the steps I used.

1. I installed the package media-gfx/zbar-0.10-r1.
Note for Gentoo users: I merged the package with the imagemagick and v4l USE flags set, so that both zbarimg and zbarcam would be installed. If you only want to use ZBar with a Webcam then turn off the imagemagick flag and zbarimg will not be installed.
Note for Sabayon Linux users: The Entropy package was built with both the above-mentioned USE flags set, so zbarimg and zbarcam will be installed.

2. Then I checked the status of the installed package by using the Portage eix command:

$ eix -I zbar
[I] media-gfx/zbar
Available versions: (~)0.10-r1 {{X gtk imagemagick jpeg python qt4 static-libs +threads v4l xv}}
Installed versions: 0.10-r1(03:56:14 05/10/12)(X gtk imagemagick jpeg qt4 threads v4l xv -python -static-libs)
Homepage: http://zbar.sourceforge.net/
Description: Library and tools for reading barcodes from images or video

Sabayon Linux users could instead use the following command:

$ equo search --verbose zbar

3. Then I checked which video device my laptop’s inbuilt Webcam is:

$ ls /dev/video*
/dev/video0

4. As it is /dev/video0, I launched zbarcam as follows:

$ zbarcam --raw /dev/video0
WARNING: no compatible input to output format
...trying again with output disabled
ERROR: zbar processor in zbar_processor_init():
unsupported request: no compatible image format

Clearly zbarcam was not recognising the Webcam.

5. As I had installed the package with the Video4Linux USE flag set, I then launched zbarcam with the following prefix:

$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam --raw /dev/video0

The ZBar GUI window popped up and I could see myself in the window. So far, so good.

6. I held a QR Code 2D bar code in front of the Webcam, then held a 1D Interleaved 2 of 5 bar code in front of the Webcam. The following was displayed:

$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam --raw /dev/video0
http://roho.it/mryt
0161223563

Both the QR Code and the I2of5 bar code were read correctly. If the --raw parameter is omitted then zbarcam displays the symbology of the bar code too:

$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam /dev/video0
QR-Code:http://roho.it/mryt
I2/5:0161223563

7. Then I tried using ZBar to read a bar code which I had previously saved as a .jpg file:

$ zbarimg --raw ~/zebra04.jpg
01234565
scanned 1 barcode symbols from 1 images in 0.04 seconds

$ zbarimg ~/zebra04.jpg
EAN-8:01234565
scanned 1 barcode symbols from 1 images in 0.04 seconds

To find out the other parameters available, use the commands:

$ man zbarcam
$ zbarcam --help
$ man zbarimg
$ zbarimg --help

ZBar is a nice tool. 8-)

ExifTool comes to the rescue when I need to fix the date and time in a batch of photo files

Before departing on an overseas trip recently I configured my camera to have the correct date and time at home (BST time zone). Of course I forgot to reconfigure the camera to the local time at my destination. On top of that, for some reason I still do not know, the date in the camera got changed. Anyway, I ended up with a large number of photos with EXIF data containing the wrong date and time. For example, I took one photo on 2011:08:04 at 09:19:03 local time but the EXIF data in the JPEG file was 2011:07:25 02:19:03.

So I needed to find a way to correct the date and time in all the photos in one fell swoop. Enter ExifTool, an excellent command line tool written in Perl. See ExifTool by Phil Harvey for full details and the download page.

To install it, I downloaded Image-ExifTool-8.61.tar.gz and followed the instructions on Installing ExifTool on Unix Platforms.

I’m going to show you how I fixed my photos. There is a lot of console output in this article because I want to give you actual examples of how to use the ExifTool commands, as it took me a while to understand the detailed documentation for the tool.

In order to fix my photos, I first copied into the ExifTool directory the directory containing the photos.

Then I used ExifTool to check the EXIF data in one of the photos, to see which tags needed to be corrected:

fitzcarraldo@meshedgedx ~ $ cd ExifTool/Image-ExifTool-8.61
fitzcarraldo@meshedgedx ~/ExifTool/Image-ExifTool-8.61 $ ./exiftool Photos_04_08_2011/DSC00006.JPG
ExifTool Version Number : 8.61
File Name : DSC00006.JPG
Directory : Photos_04_08_2011
File Size : 1405 kB
File Modification Date/Time : 2011:08:10 09:44:27+01:00 <------- This was the date and time that I last modified this file.
File Permissions : rwxrwxrwx
File Type : JPEG
MIME Type : image/jpeg
Exif Byte Order : Little-endian (Intel, II)
Image Description :
Make : SONY
Camera Model Name : DSC-WX7
Orientation : Horizontal (normal)
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Modify Date : 2011:07:25 02:19:03 <------- This is the wrong date and time. It should be 2011:08:04 09:19:03.
Y Cb Cr Positioning : Co-sited
Exposure Time : 1/250
F Number : 8.0
Exposure Program : Landscape
ISO : 100
Sensitivity Type : Recommended Exposure Index
Recommended Exposure Index : 100
Exif Version : 0230
Date/Time Original : 2011:07:25 02:19:03 <------- This is the wrong date and time. It should be 2011:08:04 09:19:03.
Create Date : 2011:07:25 02:19:03 <------- This is the wrong date and time. It should be 2011:08:04 09:19:03.
Components Configuration : Y, Cb, Cr, -
Compressed Bits Per Pixel : 2
Brightness Value : 10.15390625
Exposure Compensation : 0
Max Aperture Value : 2.6
Metering Mode : Multi-segment
Light Source : Unknown
Flash : Auto, Did not fire
Focal Length : 4.5 mm
Panorama Full Width : 0
Panorama Full Height : 0
Panorama Direction : Right to Left
Panorama Crop Left : 0
Panorama Crop Top : 0
Panorama Crop Right : 0
Panorama Crop Bottom : 0
Panorama Frame Width : 0
Panorama Frame Height : 0
Panorama Source Width : 0
Panorama Source Height : 0
Brightness : 0
High ISO Noise Reduction : n/a
HDR : Off
Face Info Offset : 94
Sony Date Time : 2011:07:25 02:19:03 <------- This is the wrong date and time. It should be 2011:08:04 09:19:03.
Faces Detected : 0
Face Info Length : 37
Color Reproduction : Standard
Color Temperature : 4294967295
Color Compensation Filter : -1
Scene Mode : n/a
Zone Matching : ISO Setting Used
Image Stabilization : On
Color Mode : n/a
Macro : Off
Focus Mode : Permanent-AF
AF Mode : Default
AF Illuminator : Auto
Quality : Normal
Flash Level : Unknown (128)
Release Mode : Normal
Sequence Number : Single
Anti-Blur : On (Shooting)
Long Exposure Noise Reduction : Unknown (2)
Dynamic Range Optimizer : Standard
Intelligent Auto : On
White Balance : Auto
User Comment :
Flashpix Version : 0100
Color Space : sRGB
Exif Image Width : 2592
Exif Image Height : 1944
Interoperability Index : R98 - DCF basic file (sRGB)
Interoperability Version : 0100
File Source : Digital Camera
Scene Type : Directly photographed
Custom Rendered : Normal
Exposure Mode : Auto
Digital Zoom Ratio : 1
Scene Capture Type : Landscape
Contrast : Normal
Saturation : Normal
Sharpness : Normal
Lens Info : 4.5-22.5mm f/2.6-6.3
PrintIM Version : 0300
Compression : JPEG (old-style)
Thumbnail Offset : 13588
Thumbnail Length : 8277
MPF Version : 0100
Number Of Images : 2
MP Image Flags : Dependent child image
MP Image Format : JPEG
MP Image Type : Large Thumbnail (full HD equivalent)
MP Image Length : 343933
MP Image Start : 1095165
Dependent Image 1 Entry Number : 0
Dependent Image 2 Entry Number : 0
Image Width : 2592
Image Height : 1944
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:2 (2 1)
Aperture : 8.0
Image Size : 2592x1944
Preview Image : (Binary data 343933 bytes, use -b option to extract)
Shutter Speed : 1/250
Thumbnail Image : (Binary data 8277 bytes, use -b option to extract)
Focal Length : 4.5 mm
Light Value : 14.0

I found four tags were incorrect in the file: ‘Modify Date’, ‘Date/Time Original’, ‘Create Date’ and ‘Sony Date Time’. However, before using ExifTool on all four tags and on the whole batch of photos, I first tried fixing only the tag ‘Sony Date Time’ in this single photo, to see if that would work:

fitzcarraldo@meshedgedx ~/ExifTool/Image-ExifTool-8.61 $ ./exiftool "-SonyDateTime+=0:00:10 07:00:0" Photos_04_08_2011/DSC00006.JPG

and then I checked the photo’s meta data again to see if the tag had been changed correctly:

fitzcarraldo@meshedgedx ~/ExifTool/Image-ExifTool-8.61 $ ./exiftool Photos_04_08_2011/DSC00006.JPG
ExifTool Version Number : 8.61
File Name : DSC00006.JPG
Directory : Photos_04_08_2011
File Size : 1405 kB
File Modification Date/Time : 2011:08:10 09:45:16+01:00 <------- This was the date and time when I ran ExifTool to change 'Sony Date Time' in this file.
File Permissions : rwxrwxrwx
File Type : JPEG
MIME Type : image/jpeg
Exif Byte Order : Little-endian (Intel, II)
Image Description :
Make : SONY
Camera Model Name : DSC-WX7
Orientation : Horizontal (normal)
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Modify Date : 2011:07:25 02:19:03 <------- Notice it is still wrong, as I didn't try to change it.
Y Cb Cr Positioning : Co-sited
Exposure Time : 1/250
F Number : 8.0
Exposure Program : Landscape
ISO : 100
Sensitivity Type : Recommended Exposure Index
Recommended Exposure Index : 100
Exif Version : 0230
Date/Time Original : 2011:07:25 02:19:03 <------- Notice it is still wrong, as I didn't try to change it.
Create Date : 2011:07:25 02:19:03 <------- Notice it is still wrong, as I didn't try to change it.
Components Configuration : Y, Cb, Cr, -
Compressed Bits Per Pixel : 2
Brightness Value : 10.15390625
Exposure Compensation : 0
Max Aperture Value : 2.6
Metering Mode : Multi-segment
Light Source : Unknown
Flash : Auto, Did not fire
Focal Length : 4.5 mm
Panorama Full Width : 0
Panorama Full Height : 0
Panorama Direction : Right to Left
Panorama Crop Left : 0
Panorama Crop Top : 0
Panorama Crop Right : 0
Panorama Crop Bottom : 0
Panorama Frame Width : 0
Panorama Frame Height : 0
Panorama Source Width : 0
Panorama Source Height : 0
Brightness : 0
High ISO Noise Reduction : n/a
HDR : Off
Face Info Offset : 94
Sony Date Time : 2011:08:04 09:19:03 <------- Notice it is now correct.
Faces Detected : 0
Face Info Length : 37
Color Reproduction : Standard
Color Temperature : 4294967295
Color Compensation Filter : -1
Scene Mode : n/a
Zone Matching : ISO Setting Used
Image Stabilization : On
Color Mode : n/a
Macro : Off
Focus Mode : Permanent-AF
AF Mode : Default
AF Illuminator : Auto
Quality : Normal
Flash Level : Unknown (128)
Release Mode : Normal
Sequence Number : Single
Anti-Blur : On (Shooting)
Long Exposure Noise Reduction : Unknown (2)
Dynamic Range Optimizer : Standard
Intelligent Auto : On
White Balance : Auto
User Comment :
Flashpix Version : 0100
Color Space : sRGB
Exif Image Width : 2592
Exif Image Height : 1944
Interoperability Index : R98 - DCF basic file (sRGB)
Interoperability Version : 0100
File Source : Digital Camera
Scene Type : Directly photographed
Custom Rendered : Normal
Exposure Mode : Auto
Digital Zoom Ratio : 1
Scene Capture Type : Landscape
Contrast : Normal
Saturation : Normal
Sharpness : Normal
Lens Info : 4.5-22.5mm f/2.6-6.3
PrintIM Version : 0300
Compression : JPEG (old-style)
Thumbnail Offset : 13588
Thumbnail Length : 8277
MPF Version : 0100
Number Of Images : 2
MP Image Flags : Dependent child image
MP Image Format : JPEG
MP Image Type : Large Thumbnail (full HD equivalent)
MP Image Length : 343933
MP Image Start : 1095165
Dependent Image 1 Entry Number : 0
Dependent Image 2 Entry Number : 0
Image Width : 2592
Image Height : 1944
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:2 (2 1)
Aperture : 8.0
Image Size : 2592x1944
Preview Image : (Binary data 343933 bytes, use -b option to extract)
Shutter Speed : 1/250
Thumbnail Image : (Binary data 8277 bytes, use -b option to extract)
Focal Length : 4.5 mm
Light Value : 14.0

So it looked like ExifTool would do the job. But I was still cautious, so I then used ExifTool to change the tags ‘Modify Date’, ‘Date/Time Original’, ‘Create Date’ and ‘Sony Date Time’ in another photo, just to check they would all be changed correctly, and I doublechecked the dates and times in the EXIF data, this time by using the ExifTool command switches -a -u and -g1 to group the meta data:

fitzcarraldo@meshedgedx ~/ExifTool/Image-ExifTool-8.61 $ ./exiftool -a -u -g1 Photos_04_08_2011/DSC00168.JPG
---- ExifTool ----
ExifTool Version Number : 8.61
---- System ----
File Name : DSC00168.JPG
Directory : .
File Size : 1854 kB
File Modification Date/Time : 2011:08:11 06:30:30+01:00
File Permissions : rwxrwxrwx
---- File ----
File Type : JPEG
MIME Type : image/jpeg
Exif Byte Order : Little-endian (Intel, II)
Image Width : 2592
Image Height : 1944
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:2 (2 1)
---- IFD0 ----
Image Description :
Make : SONY
Camera Model Name : DSC-WX7
Orientation : Horizontal (normal)
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Modify Date : 2011:08:04 15:30:20 <------- Fixed.
Y Cb Cr Positioning : Co-sited
---- ExifIFD ----
Exposure Time : 1/30
F Number : 2.6
Exposure Program : Program AE
ISO : 400
Sensitivity Type : Recommended Exposure Index
Recommended Exposure Index : 400
Exif Version : 0230
Date/Time Original : 2011:08:04 15:30:20 <------- Fixed.
Create Date : 2011:08:04 15:30:20 <------- Fixed.
Components Configuration : Y, Cb, Cr, -
Compressed Bits Per Pixel : 2
Brightness Value : 1.17734375
Exposure Compensation : 0
Max Aperture Value : 2.6
Metering Mode : Multi-segment
Light Source : Unknown
Flash : Off, Did not fire
Focal Length : 4.5 mm
User Comment :
Flashpix Version : 0100
Color Space : sRGB
Exif Image Width : 2592
Exif Image Height : 1944
File Source : Digital Camera
Scene Type : Directly photographed
Custom Rendered : Normal
Exposure Mode : Auto
White Balance : Auto
Digital Zoom Ratio : 1
Scene Capture Type : Standard
Contrast : Normal
Saturation : Normal
Sharpness : Normal
Lens Info : 4.5-22.5mm f/2.6-6.3
---- Sony ----
Panorama Full Width : 0
Panorama Full Height : 0
Panorama Direction : Right to Left
Panorama Crop Left : 0
Panorama Crop Top : 0
Panorama Crop Right : 0
Panorama Crop Bottom : 0
Panorama Frame Width : 0
Panorama Frame Height : 0
Panorama Source Width : 0
Panorama Source Height : 0
Sony 0x2000 : 0
Sony 0x2002 : 0
Sony 0x2003 : �������������������������������������������������������[...]
Contrast : 0
Saturation : -1
Sharpness : -1
Brightness : 0
Long Exposure Noise Reduction : n/a
High ISO Noise Reduction : n/a
HDR : Off
Sony 0x200c : 0 0 0
Sony 0x200d : 1
Face Info Offset : 94
Sony Date Time : 2011:08:04 15:30:20 <------- Fixed.
Faces Detected : 0
Face Info Length : 37
Color Reproduction : Standard
Color Temperature : 4294967295
Color Compensation Filter : -1
Scene Mode : n/a
Zone Matching : ISO Setting Used
Dynamic Range Optimizer : Standard
Image Stabilization : On
Color Mode : n/a
Macro : Off
Exposure Mode : Program
Focus Mode : Permanent-AF
AF Mode : Default
AF Illuminator : Auto
Sony 0xb045 : 0
Sony 0xb046 : 0
Quality : Normal
Flash Level : Unknown (128)
Release Mode : Normal
Sequence Number : Single
Anti-Blur : On (Shooting)
Sony 0xb04c : 1
Sony 0xb04d : 0
Long Exposure Noise Reduction : Unknown (2)
Dynamic Range Optimizer : Standard
Sony 0xb050 : 2
Sony 0xb051 : 0
Intelligent Auto : On
Sony 0xb053 : 0
White Balance : Auto
Sony 0x9400 : ...........��[...]
Sony 0x9401 : c���....��.����.�D��..�.0b0.L��e�e0E0.L��.[...]
Sony 0x9402 : .l���i.p!�!�����i���V�ie�Pp_��}@i�[...]
Sony 0x9403 : .��.i.��.榚~W��...���[...]
Sony 0x9404 : @�..�.�@}.��.�.0�K��pl.�V���.�..͵�QV..MV[...]
Sony 0x9405 : ..��.��Ģ�E5�..�..[...]
Sony 0x9406 : �������������������������������������������������������[...]
Sony 0x9407 : �������������������������������������������������������[...]
Sony 0x9408 : .#?A??AA��...�[...]
Sony 0x9409 : .[...]
Sony 0x940a : ��.��[...]
Sony 0x940b : �.�@�@�}�}t}.@�@PpFpNp�p��.�Ҋ_�9�~���v͔� ͸����^�.�[...]
Sony 0x940c : ������[...]
Sony 0x940d : �������������������������������������������������������[...]
Sony 0x940e : �������������������������������������������������������[...]
Sony 0xa100 : [...]
---- InteropIFD ----
Interoperability Index : R98 - DCF basic file (sRGB)
Interoperability Version : 0100
---- PrintIM ----
PrintIM Version : 0300
Print IM 0x0002 : 0x00000001
Print IM 0x0101 : 0x00000001
---- IFD1 ----
Compression : JPEG (old-style)
Image Description :
Make : SONY
Camera Model Name : DSC-WX7
Orientation : Horizontal (normal)
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Modify Date : 2011:07:25 08:30:20 <------- Whoops, this one is still incorrect.
Thumbnail Offset : 13588
Thumbnail Length : 12400
Y Cb Cr Positioning : Co-sited
---- MPF0 ----
MPF Version : 0100
Number Of Images : 2
---- MPImage1 ----
MP Image Flags : Representative image, Dependent parent image
MP Image Format : JPEG
MP Image Type : Baseline MP Primary Image
MP Image Length : 1399500
MP Image Start : 0
Dependent Image 1 Entry Number : 2
Dependent Image 2 Entry Number : 0
---- MPImage2 ----
MP Image Flags : Dependent child image
MP Image Format : JPEG
MP Image Type : Large Thumbnail (full HD equivalent)
MP Image Length : 496491
MP Image Start : 1402364
Dependent Image 1 Entry Number : 0
Dependent Image 2 Entry Number : 0
---- Composite ----
Aperture : 2.6
Image Size : 2592x1944
Preview Image : (Binary data 496491 bytes, use -b option to extract)
Shutter Speed : 1/30
Thumbnail Image : (Binary data 12400 bytes, use -b option to extract)
Focal Length : 4.5 mm
Light Value : 5.7

As you can see from the output above, I found another tag that was also incorrect: ‘Modify Date’ in Group IFD1. So I tried to fix that:

fitzcarraldo@meshedgedx ~/ExifTool/Image-ExifTool-8.61 $ ./exiftool "-IFD1:ModifyDate+=0:00:10 07:00:0" Photos_04_08_2011/DSC00168.JPG
1 image files updated

Notice in the command that I prefixed the tag (ModifyDate) with the group (IFD1).

and I checked the photo’s meta data again:

fitzcarraldo@meshedgedx ~/ExifTool/Image-ExifTool-8.61 $ ./exiftool -a -u -g1 Photos_04_08_2011/DSC00168.JPG
---- ExifTool ----
ExifTool Version Number : 8.61
---- System ----
File Name : DSC00168.JPG
Directory : .
File Size : 1854 kB
File Modification Date/Time : 2011:08:11 06:33:50+01:00
File Permissions : rwxrwxrwx
---- File ----
File Type : JPEG
MIME Type : image/jpeg
Exif Byte Order : Little-endian (Intel, II)
Image Width : 2592
Image Height : 1944
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:2 (2 1)
---- IFD0 ----
Image Description :
Make : SONY
Camera Model Name : DSC-WX7
Orientation : Horizontal (normal)
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Modify Date : 2011:08:04 15:30:20
Y Cb Cr Positioning : Co-sited
---- ExifIFD ----
Exposure Time : 1/30
F Number : 2.6
Exposure Program : Program AE
ISO : 400
Sensitivity Type : Recommended Exposure Index
Recommended Exposure Index : 400
Exif Version : 0230
Date/Time Original : 2011:08:04 15:30:20
Create Date : 2011:08:04 15:30:20
Components Configuration : Y, Cb, Cr, -
Compressed Bits Per Pixel : 2
Brightness Value : 1.17734375
Exposure Compensation : 0
Max Aperture Value : 2.6
Metering Mode : Multi-segment
Light Source : Unknown
Flash : Off, Did not fire
Focal Length : 4.5 mm
User Comment :
Flashpix Version : 0100
Color Space : sRGB
Exif Image Width : 2592
Exif Image Height : 1944
File Source : Digital Camera
Scene Type : Directly photographed
Custom Rendered : Normal
Exposure Mode : Auto
White Balance : Auto
Digital Zoom Ratio : 1
Scene Capture Type : Standard
Contrast : Normal
Saturation : Normal
Sharpness : Normal
Lens Info : 4.5-22.5mm f/2.6-6.3
---- Sony ----
Panorama Full Width : 0
Panorama Full Height : 0
Panorama Direction : Right to Left
Panorama Crop Left : 0
Panorama Crop Top : 0
Panorama Crop Right : 0
Panorama Crop Bottom : 0
Panorama Frame Width : 0
Panorama Frame Height : 0
Panorama Source Width : 0
Panorama Source Height : 0
Sony 0x2000 : 0
Sony 0x2002 : 0
Sony 0x2003 : �������������������������������������������������������[...]
Contrast : 0
Saturation : -1
Sharpness : -1
Brightness : 0
Long Exposure Noise Reduction : n/a
High ISO Noise Reduction : n/a
HDR : Off
Sony 0x200c : 0 0 0
Sony 0x200d : 1
Face Info Offset : 94
Sony Date Time : 2011:08:04 15:30:20
Faces Detected : 0
Face Info Length : 37
Color Reproduction : Standard
Color Temperature : 4294967295
Color Compensation Filter : -1
Scene Mode : n/a
Zone Matching : ISO Setting Used
Dynamic Range Optimizer : Standard
Image Stabilization : On
Color Mode : n/a
Macro : Off
Exposure Mode : Program
Focus Mode : Permanent-AF
AF Mode : Default
AF Illuminator : Auto
Sony 0xb045 : 0
Sony 0xb046 : 0
Quality : Normal
Flash Level : Unknown (128)
Release Mode : Normal
Sequence Number : Single
Anti-Blur : On (Shooting)
Sony 0xb04c : 1
Sony 0xb04d : 0
Long Exposure Noise Reduction : Unknown (2)
Dynamic Range Optimizer : Standard
Sony 0xb050 : 2
Sony 0xb051 : 0
Intelligent Auto : On
Sony 0xb053 : 0
White Balance : Auto
Sony 0x9400 : ...........��[...]
Sony 0x9401 : c���....��.����.�D��..�.0b0.L��e�e0E0.L��.[...]
Sony 0x9402 : .l���i.p!�!�����i���V�ie�Pp_��}@i�[...]
Sony 0x9403 : .��.i.��.榚~W��...���[...]
Sony 0x9404 : @�..�.�@}.��.�.0�K��pl.�V���.�..͵�QV..MV[...]
Sony 0x9405 : ..��.��Ģ�E5�..�..[...]
Sony 0x9406 : �������������������������������������������������������[...]
Sony 0x9407 : �������������������������������������������������������[...]
Sony 0x9408 : .#?A??AA��...�[...]
Sony 0x9409 : .[...]
Sony 0x940a : ��.��[...]
Sony 0x940b : �.�@�@�}�}t}.@�@PpFpNp�p��.�Ҋ_�9�~���v͔� ͸����^�.�[...]
Sony 0x940c : ������[...]
Sony 0x940d : �������������������������������������������������������[...]
Sony 0x940e : �������������������������������������������������������[...]
Sony 0xa100 : [...]
---- InteropIFD ----
Interoperability Index : R98 - DCF basic file (sRGB)
Interoperability Version : 0100
---- PrintIM ----
PrintIM Version : 0300
Print IM 0x0002 : 0x00000001
Print IM 0x0101 : 0x00000001
---- IFD1 ----
Compression : JPEG (old-style)
Image Description :
Make : SONY
Camera Model Name : DSC-WX7
Orientation : Horizontal (normal)
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Modify Date : 2011:08:04 15:30:20 <------- Notice it is now correct.
Thumbnail Offset : 13588
Thumbnail Length : 12400
Y Cb Cr Positioning : Co-sited
---- MPF0 ----
MPF Version : 0100
Number Of Images : 2
---- MPImage1 ----
MP Image Flags : Representative image, Dependent parent image
MP Image Format : JPEG
MP Image Type : Baseline MP Primary Image
MP Image Length : 1399500
MP Image Start : 0
Dependent Image 1 Entry Number : 2
Dependent Image 2 Entry Number : 0
---- MPImage2 ----
MP Image Flags : Dependent child image
MP Image Format : JPEG
MP Image Type : Large Thumbnail (full HD equivalent)
MP Image Length : 496491
MP Image Start : 1402364
Dependent Image 1 Entry Number : 0
Dependent Image 2 Entry Number : 0
---- Composite ----
Aperture : 2.6
Image Size : 2592x1944
Preview Image : (Binary data 496491 bytes, use -b option to extract)
Shutter Speed : 1/30
Thumbnail Image : (Binary data 12400 bytes, use -b option to extract)
Focal Length : 4.5 mm
Light Value : 5.7

Now I was confident that I could fix all the incorrect tags, so I again copied the directory containing the original files into the ExifTool directory and used the commands below to change the date and time from e.g. 2011:07:25 02:19:03 to 2011:08:04 09:19:03, i.e. I wanted to: a) add 7 hours to the EXIF times to make them correct for the city I was in instead of UK BST; b) add 10 days to the EXIF dates to fix the incorrect date (2011:07:25) that was set in my camera to the correct date (2011:08:04).

$ cd ~/ExifTool/Image-ExifTool-8.61
$ ./exiftool "-SonyDateTime+=0:00:10 07:00:0" Photos_04_08_2011/
$ ./exiftool "-DateTimeOriginal+=0:00:10 07:00:0" Photos_04_08_2011/
$ ./exiftool "-CreateDate+=0:00:10 07:00:0" Photos_04_08_2011/
$ ./exiftool "-IFD0:ModifyDate+=0:00:10 07:00:0" Photos_04_08_2011/
$ ./exiftool "-IFD1:ModifyDate+=0:00:10 07:00:0" Photos_04_08_2011/

Finally, as ExifTool automatically creates a back up file before changing EXIF data in a photo file, I deleted the back up files after I had checked that the EXIF data in the new files contained the correct dates and times:

$ rm ./Photos_04_08_2011/*_original

Yet another great tool to add to my toolbox.

Converseen, a GUI batch image converter and resizer using Qt4 and ImageMagick

I normally use ImageMagick on the command line to convert and/or resize my photographs, and the two commands I use are convert and mogrify. However, I learned recently of Converseen, a GUI tool for batch conversion and resizing of image files which is a front-end for ImageMagick. Although it’s easy enough to use the command line, a GUI tool does save having to remember the command syntax each time, so I thought I’d install Converseen in Gentoo. Converseen is not in the main Portage tree, but I found an ebuild for version 0.2 from the qting-edge overlay. However, rather than add the overlay I decided instead to use a local overlay to install Converseen, which is currently at version 0.4.1, and the procedure I used is given below.

1. I downloaded to ~/Desktop/ the ebuild file from http://gitorious.org/gentoo-qt/qting-edge/blobs/master/media-gfx/converseen/converseen-0.2.ebuild and renamed it as converseen-0.4.1.ebuild, which contains the following:

# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"

LANGSLONG="it_IT pl_PL"

inherit qt4-edge

MY_P=${PN}-${PV}

DESCRIPTION="GUI image conversion tool based on imagemagick"
HOMEPAGE="http://converseen.sourceforge.net"
SRC_URI="mirror://sourceforge/${PN}/${MY_P}.tar.bz2"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="debug"

DEPEND="x11-libs/qt-gui:4
        || ( media-gfx/graphicsmagick[imagemagick] media-gfx/imagemagick )"
RDEPEND="${DEPEND}"

S="${WORKDIR}/${MY_P}"

#PATCHES=( "${FILESDIR}/${P}-cflags.patch" )
DOCS="README"

src_prepare() {
        qt4-edge_src_prepare

        sed -i -e "s!/usr/lib!/usr/$(get_libdir)!" ${PN}.pro \
                || die "sed libdir failed"

        local ts_files=
        for lingua in ${LINGUAS}; do
                for a in ${LANGSLONG}; do
                        if [[ ${lingua} == ${a%_*} ]]; then
                                ts_files="${ts_files} loc/${PN}_${a}.ts"
                        fi
                done
        done
        local qm_files="${ts_files/.ts/.qm}"

        sed -e '/^ loc/d' \
                -e "s!\(TRANSLATIONS += \).*!\1${ts_files}!" \
                -e "s!\(translations\.files = \).*!\1${qm_files}!" \
                -i ${PN}.pro || die "sed translations failed"
}

2. I downloaded to ~/Desktop/ the file qt4-edge.eclass, which contains the following:

# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: qt4-edge.eclass
# @MAINTAINER:
# Ben de Groot <yngwin@gentoo.org>,
# Markos Chandras <hwoarang@gentoo.org>,
# Davide Pesavento <davidepesa@gmail.com>,
# Dominik Kapusta <ayoy@gentoo.org>
# @BLURB: Experimental eclass for Qt4 packages
# @DESCRIPTION:
# This eclass contains various functions that may be useful when
# dealing with packages using Qt4 libraries. Requires EAPI=2.

inherit base eutils multilib qt4-r2 toolchain-funcs

export XDG_CONFIG_HOME="${T}"

qt4-edge_pkg_setup() {
        if [[ -z ${I_KNOW_WHAT_I_AM_DOING} ]]; then
                ewarn
                ewarn "Please file bugs on bugs.gentoo.org and prepend the summary with"
                ewarn "[qting-edge]. Alternatively, contact qt@gentoo.org."
                ewarn "Thank you for using qting-edge overlay."
                ewarn
                ebeep 5
        fi
}

qt4-edge_src_unpack() {
        debug-print-function $FUNCNAME "$@"

        qt4-r2_src_unpack "$@"
}

# @FUNCTION: qt4-edge_src_prepare
# @DESCRIPTION:
# Default src_prepare function for packages that depend on qt4. If you have to
# override src_prepare in your ebuild, you should call qt4-edge_src_prepare in it,
# otherwise autopatcher will not work!
qt4-edge_src_prepare() {
        debug-print-function $FUNCNAME "$@"

        qt4-r2_src_prepare
}

# @FUNCTION: qt4-edge_src_configure
# @DESCRIPTION:
# Default src_configure function for packages that depends on qt4. If you have to
# override src_configure in your ebuild, call qt4-edge_src_configure in it.
qt4-edge_src_configure() {
        debug-print-function $FUNCNAME "$@"

        qt4-r2_src_configure
}

# @FUNCTION: qt4-edge_src_compile
# @DESCRIPTION:
# Default src_compile function for packages that depends on qt4. If you have to
# override src_compile in your ebuild (probably you don't need to), call
# qt4-edge_src_compile in it.
qt4-edge_src_compile() {
        debug-print-function $FUNCNAME "$@"

        qt4-r2_src_compile
}

# @FUNCTION: qt4-edge_src_install
# @DESCRIPTION:
# Default src_install function for qt4-based packages. Installs compiled code,
# documentation (via DOCS variable) and translations (via LANGS and
# LANGSLONG variables).
qt4-edge_src_install() {
        debug-print-function $FUNCNAME "$@"

        qt4-r2_src_install

        # install translations # hwoarang: Is this valid for every package???
        # need to have specified LANGS or LANGSLONG for this to work
        [[ -n "${LANGS}" || -n "${LANGSLONG}" ]] && prepare_translations
}

# Internal function
_do_qm() {
        debug-print-function $FUNCNAME "$@"
        [[ $# -ne 2 ]] && die "$FUNCNAME requires exactly 2 arguments!"

        local transfile="$(find "${1}" -type f -name "*${2}".qm)"
        if [[ -e ${transfile} ]]; then
                INSDESTTREE="/usr/share/${PN}/${1#${S}}" \
                        doins "${transfile}" \
                        || die "failed to install ${2} translation"
        else
                eerror
                eerror "Failed to install ${2} translation. Contact eclass maintainer."
                eerror
                die "Failed to install translations"
        fi
}

# @VARIABLE: TRANSLATIONSDIR
# @DESCRIPTION: Translations directory. If not set, ${S} will be used

# @FUNCTION: prepare_translations
# @DESCRIPTION:
# Choose and install translation files. Normally you don't need to call
# this function directly as it is called from qt4-edge_src_install.
prepare_translations() {
        debug-print-function $FUNCNAME "$@"

        # Find translations directory
        # Changed default to . - crazy upstreams
        local roottrdir="${TRANSLATIONSDIR:-${S}}" trdir=.
        for dir in lang langs translations; do
                [[ -d ${roottrdir}/${dir} ]] && trdir="${roottrdir}/${dir}"
        done

        local lang=
        for lang in ${LINGUAS}; do
                for x in ${LANGS}; do
                        [[ ${lang} == ${x%_*} ]] && _do_qm "${trdir}" ${x}
                done
                for x in ${LANGSLONG}; do
                        [[ ${lang} == ${x} ]] && _do_qm "${trdir}" ${x}
                done
        done
}

EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_install

3. I synchronised the Portage main tree’s ebuilds on my PC with those in the repositories:

# emerge --sync

4. I made sure that /etc/make.conf has the following lines at the end of the file:

PORTDIR_OVERLAY="${PORTDIR_OVERLAY} /usr/local/portage/"
ACCEPT_LICENSE="*"

5. I created the necessary directories in the local overlay:

# mkdir -p /usr/local/portage/media-gfx/converseen
# mkdir -p /usr/local/portage/eclass

6. I made sure Portage would not nag me about a missing name for my local overlay:

# mkdir /usr/local/portage/profiles
# echo "local_overlay" > /usr/local/portage/profiles/repo_name

7. I copied the converseen ebuild and eclass file into the relevant directories:

# cp /home/fitzcarraldo/Desktop/converseen-0.4.1.ebuild /usr/local/portage/media-gfx/converseen/
# cp /home/fitzcarraldo/Desktop/qt4-edge.eclass /usr/local/portage/eclass/

8. I generated the manifest for the package:

# cd /usr/local/portage/media-gfx/converseen/
# ebuild converseen-0.4.1.ebuild manifest

9. I merged the package:

# emerge -1v converseen

An entry for Converseen was added to Kickoff > Applications > Graphics, and I can either use that to launch it or I can launch it from the command line by entering the command converseen. The user interface is easy to master, and I’ve already put Converseen to use at work and at home. Overall, then, a useful addition to my KDE toolkit.

EDIT (July 23, 2012}: There is an ebuild for Converseen in Portage these days, so use that instead to install Converseen.

Follow

Get every new post delivered to your Inbox.

Join 56 other followers