📜 ⬆️ ⬇️

Command line in the service of a Linux photographer

Hello, hello!

I consider myself a lazy photographer. That is, I do not like to scrupulously process the footage, but at the same time, I occasionally feel a 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 it is, but you could not find it. What to do? Of course, use bash.
')
Consider two typical situations.

1) The shooting was carried out on several cameras at the same time, with each of them saves files under different names. For example, one creates files with names like DSCFxxxx.jpg, the other - Pxxxxxxxx.jpg.
For ease 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 images in order in those environments where sorting by date and time is not supported. For this we need the program exiv2.

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

exiv2 -a -3 *.JPG

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

exiv2 *.JPG | grep ' '

If everything is in order, you can rename all 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 look, allowing them to be easily sorted, and also see by the file name when the photo was taken.

Then go to the next directory, and after processing all the planned directories - merge the result into one common. It turns out very clearly: below is an excerpt from the list of images taken in the morning of January 6, 2011 with two different cameras:

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


2) Let's say you uploaded your photos to Picas. And now you want to publish them, for example, in your blog. Quickly generate the necessary HTML-code will help you picasa2html.com site
But bad luck - he does not insert templates for photo captions!
The correct approach is to write your own similar service.
But it is a long time, and chronically not enough time. We take a quick approach.

Take the text generated by the site, and write it to a file named photos1.txt.
Then we give the command

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

What she does? The first sed call cuts out the picasa2html logo, designed as a separate paragraph.
The second call to sed takes from the conveyor the result of the first (clean links to the photo), and inserts a template after it to sign it (if you put the captions on top - the script is easy to remake).

Thus, the source code blocks of the form

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


turn into blocks of the form

 <a href="https://picasaweb.google.com/111237353143627593504/201103#5651154095475647410"><img src="1450822379562064245147" border="0"></a><br> 00. xxx <br> <br> <a href="https://picasaweb.google.com/111237353143627593504/201103#5651154095475647410"><img src="1450822379562064245147" border="0"></a><br> 00. xxx <br> <br> <a href="https://picasaweb.google.com/111237353143627593504/201103#5651154138485468866"><img src="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 already in place, replacing the zeroes with meaningful numbers, and “xxx” - with meaningful signatures.
Why didn't I do auto-numbering? Yes, because in my opinion it is more convenient to rearrange the photos already in the post, and therefore the numbering will be final only immediately before publication.

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

Source: https://habr.com/ru/post/128493/


All Articles