Produce batch file for convert

For my mother, who is rather disabled, I bought an 8" Kodak digital photo frame (DFF). It has a good resolution: 800 x 480 pixels. Yet, all my camera's have much more pixels: 6 MP or better. So it doesn't make sense to feed the DFF with these 1.5 MB files. So I convert all pictures by 75% (height and width are halved) with a command line like this:

	convert -resize 50% p6070081.jpg F-AF251.jpg
   
The Olympus camera has a highly tructured way of naming the pictures. They all start with a lower case 'p'. The second letter is the number of the month, in hexadecimal. Then the number of the day in that month (two decimal digits), plus a serial number for the picure. The serial number is reset each time the battery was removed (for charging) or when the pictures were USB-ed to a computer.

Yet, why send a 3000 x 2400 pixel to a 1 GB SD card when a 1500 x 1200 image also still is mighty overkill? Plus: there will fit approximately 600 unprocessed files on the 1 GB SD card. Yet there will be room for something like 2000 downscaled pictures.

DFFR: the source

The source code for this file is short and simple. DFFR reads the filenames from STDIN and writes a conversion command to file, if the filename contains the magic letters 'jpg'. The program is invoked as follows:

	ls -1 | DFFR AG
   
Here, the 'ls -1' command outputs a single column directory listing which is piped into DFFR. DFFR on the other hand, produces pictures that all start with the sequence 'F-' followed by a datecode plus a 3 digit serialnumber. The datecode is specified by and retrieved from its command tail, in this case 'AG'.

Here is the program:

MODULE DFFR;

IMPORT  InOut, Strings, NumConv, TextIO, Arguments;

TYPE 	Identifier		= ARRAY [0..31] OF CHAR;

VAR	old, new		: Identifier;
	nr			: CARDINAL;
	line 			: ARRAY [0..81] OF CHAR;
	tmp   			: ARRAY [0..7] OF CHAR;
	ok			: BOOLEAN;
	file			: TextIO.File;
	buffer			: Arguments.ArgTable;
	count			: SHORTCARD;


BEGIN
   nr := 1;
   Arguments.GetArgs (count, buffer);
   Strings.Assign (new, buffer^[1]^);

   TextIO.OpenOutput (file, "go");
   
   LOOP
      InOut.ReadString (old);
      IF  Strings.pos ('jpg', old) < HIGH (old)  THEN
	 line := "convert -resize 50% ";
	 Strings.Append (line, old);
	 Strings.Append (line, " F-");
	 Strings.Append (line, new);
	 NumConv.Num2Str (nr, 10, tmp, ok);
	 NumConv.AdjustWidth (tmp, 3, "0");
	 Strings.Append (line, tmp);	Strings.Append (line, ".jpg");
	 TextIO.PutString (file, line);	TextIO.PutLn (file);
	 INC (nr);
      END;
      IF  InOut.EOF () = TRUE  THEN  EXIT  END;
   END;
   TextIO.PutLn (file);
   TextIO.Close (file);
   InOut.WriteString ("Done");		InOut.WriteLn
END DFFR.
   
Next you only need to give execute permission to the file and start it:
	jan@beryllium:~/Keep/Jpg/Olympus/07$ ls -1 | DFFR AG
	Done
	jan@beryllium:~/Keep/Jpg/Olympus/07$ ./go
	bash: ./go: Permission denied
	jan@beryllium:~/Keep/Jpg/Olympus/07$ chmod 755 go
	jan@beryllium:~/Keep/Jpg/Olympus/07$ ./go
   
This is a hell of a job! So give the machine some time. It will take approximately 5 seconds to convert one file on a 3 GHz Pentium IV (Beryllium).

Page created 16 November 2007,

Page equipped with googleBuster technology