📜 ⬆️ ⬇️

Batch Image Processing in Picasa with ImageMagick

image In our office, we use Picasa to process many scans and photos. We have been using Picasa for several years now and are very satisfied. However, Picasa does not provide all the features we need, and some are too difficult to use with our scope of work. To make it easier for our employees, I decided to automate some processes using two main components: the ImageMagick console toolkit, and the rather obscure Picasa Button API .

As an example, I will describe a small application that we use to combine several images into one, with one click directly from the Picasa interface. Having a little understanding with ImageMagick, you can easily modify this code for other tasks.

Part 1: Button in Picasa


First we need a button in the Picasa interface that will run our ImageMagick script. To create such a button using the Button API, do the following steps:
')
1. Write a PBF file.

PBF is essentially a simple XML file that describes our button. Here is the code for my PBF file:
<?xml version="1.0" encoding="utf-8" ?> <buttons format="1" version="1"> <button id="{ca234ae3-6340-40c3-a46b-51a126bb887c}" type="dynamic"> <label>Combine</label> <tooltip>Combine images vertically and save as a new image</tooltip> <action verb="trayexec"> <param name="exe_name" value="stitch.cmd" /> <param name="exe_path" value="S:\Tools\" /> </action> </button> </buttons> 

Although the whole code is enclosed in a buttons container, only one button can be described in one file.

Note the GUID in the button / id attribute. For each button you need to generate your GUID. Also the name of the PBF file includes this GUID, {ca234ae3-6340-40c3-a46b-51a126bb887c} .pbf in my example.

The label and tooltip elements do not require any special explanation. The next important element is action ; it describes what happens when you press our button. The Picasa Button API provides several different button functions; we use the simple launch of the executable file, which will run a script named stitch.cmd , located in S: \ Tools \ ( S: \ is a shared folder on the office server). I will explain the script in the future.

2. Draw an icon (optional) .

You can enable your own icon for our button. The icon should be in the PSD file named after the GUID ( {ca234ae3-6340-40c3-a46b-51a126bb887c} .psd in my example) in one layer. When using the icon, you need to include an additional line in the PBF, inside the button element:
 <icon name="{ca234ae3-6340-40c3-a46b-51a126bb887c}.psd/layer" src="pbz"/> 

3. We pack the button in PBZ.

PBZ is nothing more than a regular ZIP archive containing our PBF (and PSD with an icon, if we use it), with the extension .pbz . This file is the installation package for our Picasa button, so it’s necessary to name it meaningfully: Picasa distinguishes the installed buttons by the name of their PBZ package. One PBZ can contain several PBF files for several buttons, with different GUIDs.

Part 2: ImageMagick Script


Since ImageMagick provides console utilities for image processing, the easiest way to automate it is bat-scripts. Here is the code for my script stitch.cmd , which combines several images vertically into one:
 @echo off cd /D "C:\Program Files\ImageMagick-6.7.1-Q16" rem --- Output filename set OUTFOLDER=%~dp1 set OUTFILENAME="%OUTFOLDER%Collage.jpg" rem --- Imagemagick for /f "delims=" %%a in ('identify -format "%%[fx:w]" %1') do @set WIDTH=%%a montage -mode concatenate -resize %WIDTH% -tile 1x %* %OUTFILENAME% 

When the script is invoked by clicking a button from Picasa, the full file names of all the selected pictures are passed as arguments to it.

First, go to the folder where our ImageMagick is installed to avoid possible problems with PATH. Then we will generate the name of the finished image, taking the full path from the first file (the first argument) and adding our own file name.

Now let's use a small bat-hack: using the for loop, we count the output of the command ( identify from the ImageMagick package) to a variable. This gives us the width of the first image. Finally, we call montage and use it to combine all the images into one, passing all the image names and the output file name to the command.

Part 3: Installation


Installing a button in Picasa is somewhat nontrivial. Picasa does not allow you to install PBZ directly, only through a special URL from the browser. We need to arrange our PBZ so that it is accessible via the link via http: // ; I have a development server installed on my system, so I used it. Here is the link code for installing the button:

 <a href="picasa://importbutton/?url=http://localhost/olex-stitcher.pbz">Install</a> 

Open the file with a link in any browser and click. Picasa opens and asks which buttons to install (there is only one choice, if there is one button in our PBZ), and how to place them on the button bar. Make a choice and confirm. Is done.

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


All Articles