Command line in the service of Linux photographer

Hello habra

I consider myself a lazy photographer. That is, I do not like to scrupulously process the captured material, but at the same time I periodically feel the desire to post a packet or two of photos on the Internet, preferably quickly.

For Linux, which I use almost 100% of the time, there are many different graphical tools for working with photos. But sometimes it happens that there is no necessary function in the program used.
Or she is, but you could not find her. What to do? Of course, use bash.

Consider two typical situations.

1) The shooting was carried out on several cameras at the same time, while each of them saves files under different names. For example, one creates files with names of the form DSCFxxxx.jpg, the other - Pxxxxxxxx.jpg.
For the convenience of sorting, I would like to have such names that, on the one hand, will be more or less unified, on the other hand, contain the date and time of the image, so that you can arrange the pictures in order in those environments where sorting by date and time is not supported. For this, the exiv2 program is useful to us.

In this case, I do so. I go to each of the photos directory to be processed and set a single time zone for the pictures. First you need to look: which of the many cameras this directory created, and which was set on it a time zone. For example, if the camera was shot in Moscow time, and you need to set GMT, which is 3 hours behind it in the summer, then we give the following command:

exiv2 -a -3 *.JPG

You can check the correct time setting by displaying new data from EXIF:

exiv2 *.JPG | grep 'Отметка времени'

If everything is in order, you can rename all the files in the directory with this command:

exiv2 -t -r'%Y%m%d-%H%M%S-:basename:' *.JPG

After that, the file names will have a unified view, which makes it easy to sort them, and also see by the file name when the photo was taken.

Then we go to the next directory, and after processing all the planned directories, we merge the result into one common one. It turns out very clearly: the following is an excerpt from the list of pictures taken in the morning of January 6, 2011 with two different cameras: 2) Let's say you uploaded your photos to Picasa. And now you want to publish them, for example, in your blog. Picasa2html.com will help you quickly generate the necessary HTML code . But the problem is that it does not insert templates for photo captions! The correct approach is to write your own similar service. But this is a long time, and chronically not enough time. We will take a quick approach. Take the text generated by the site and write it to a file called photos1.txt.

20110106-094958-DSCF2173.JPG
20110106-101332-P1250178.JPG
20110106-101410-P1250180.JPG
20110106-122204-DSCF2188.JPG
20110106-122216-DSCF2190.JPG








Then we give the team

sed '/<p.*p>/d' photos1.txt | sed 's/<\/a>/<\/a>\n00. xxx\n\n/gpw photos2.txt'

What does she do? The first sed call cuts out the picasa2html logo, designed as a separate paragraph.
The second sed call takes from the pipeline the result of the first (clean links to the photo), and inserts a template for each signature after each photo (if you put the signature on top, the script is easy to redo).

Thus, the source code blocks of the form

<ahref="https://picasaweb.google.com/111237353143627593504/201103#5651154095475647410"><imgsrc="1450822379562064245147"border="0"></a><br><ahref="https://picasaweb.google.com/111237353143627593504/201103#5651154138485468866"><imgsrc="1450822379849647876873"border="0"></a><br><ahref="https://picasaweb.google.com/111237353143627593504/201103#5651154208871818754"><imgsrc="http://lh6.ggpht.com/-DxT6hGi6-QQ/Tmzuz9bCJgI/AAAAAAAACD0/uqoRVuuFqCs/s720/DSCF7467.JPG"border="0"></a><br>


turn into blocks of the form

<ahref="https://picasaweb.google.com/111237353143627593504/201103#5651154095475647410"><imgsrc="1450822379562064245147"border="0"></a><br>
00. xxx
<br><br><ahref="https://picasaweb.google.com/111237353143627593504/201103#5651154095475647410"><imgsrc="1450822379562064245147"border="0"></a><br>
00. xxx
<br><br><ahref="https://picasaweb.google.com/111237353143627593504/201103#5651154138485468866"><imgsrc="1450822379849647876873"border="0"></a><br>
00. xxx
<br><br>


We take the result from the photos2.txt file, insert it into the blog, and edit the signatures locally, replacing the zeros with meaningful numbers, and “xxx” with meaningful signatures.
Why didn’t I do auto numbering? Yes, because in my opinion, rearranging photographs is most convenient already in the post, and therefore the numbering will be final only immediately before publication.

My post is far from exhaustive, and he invites to a dialogue.
It would be interesting to listen to like-minded people. Do you often write scripts to process photos instead of using graphical tools? Perhaps there is something to share?

Also popular now: