Screenshots
There are occasions in which I need (or want) to make screenshots when I'm watsching a movie with the 'xine' media player. Xine always makes PNG files but some of my applications require the pictures to be JPG and minimum dimensions of 400 pixels on either side. So I used to run the command:
convert -resize 150% shot-1.png AA-1.jpg
and for a few screenshots that was enough. Lster, when more screenshots were required, the command line
version was too time consuming. So I made a file called 'go' and in it were sets of lines like the one above.
That worked,, but making the batch files was a lot of work. So I decided to automate it: make the batch files
automatically, make the resultant file executable and start it. And it works!
conv: make a batchfile to convert images
Below is the source. It is an easy program. There are just a few things which are special:
The format of the input files is as follows: MyMovie-xxx.png where
| Text | Purpose |
|---|---|
| MyMovie | The name of the movie being played by Xine when the screenshot was made |
| - | Introduced by Xine to separate moviename from serial number |
| xxx | Serial number (auto incremented) by Xine |
The source
Below is the source. The InOut.WriteBf commands were needed since Linux does not print messages on screen before a LineFeed is encountered. For the rest it is all very straight forward.
MODULE conv;
IMPORT InOut, Strings, NumConv, TextIO;
TYPE Identifier = ARRAY [0..31] OF CHAR;
VAR old, new, factor : Identifier;
line : ARRAY [0..63] OF CHAR;
from, until, nr : CARDINAL;
tmp : ARRAY [0..7] OF CHAR;
ok : BOOLEAN;
file : TextIO.File;
BEGIN
InOut.WriteString ("Old prefix : "); InOut.WriteBf;
InOut.ReadString (old);
InOut.WriteString ("New prefix : "); InOut.WriteBf;
InOut.ReadString (new);
InOut.WriteString ("From nr : "); InOut.WriteBf;
InOut.ReadCard (from);
InOut.WriteString ("Until nr : "); InOut.WriteBf;
InOut.ReadCard (until);
InOut.WriteString ("Resize factor : "); InOut.WriteBf;
InOut.ReadString (factor);
nr := from;
TextIO.OpenOutput (file, "go");
LOOP
line := "convert ";
IF factor [0] # '-' THEN
Strings.Append (line, "-resize ");
Strings.Append (line, factor);
Strings.Append (line, "% ")
END;
Strings.Append (line, old); Strings.Append (line, "-");
NumConv.Num2Str (nr, 10, tmp, ok);
Strings.Append (line, tmp); Strings.Append (line, ".png ");
Strings.Append (line, new); Strings.Append (line, "-");
NumConv.AdjustWidth (tmp, 3, "0");
Strings.Append (line, tmp); Strings.Append (line, ".jpg");
TextIO.PutString (file, line); TextIO.PutLn (file);
INC (nr);
IF nr > until THEN EXIT END
END;
TextIO.PutLn (file);
TextIO.Close (file);
InOut.WriteString ("Done"); InOut.WriteLn
END conv.
What it does
Below is an example of the use of the conv program:
-$ ls GBG11-1.png GBG11-2.png GBG11-3.png GBG11-4.png GBG11-5.png GBG11-6.png -$ conv Old prefix : GBG11 New prefix : AZ From nr : 1 Until nr : 6 Resize factor : 125 Done -$ cat go convert -resize 125% GBG11-1.png AZ-001.jpg convert -resize 125% GBG11-2.png AZ-002.jpg convert -resize 125% GBG11-3.png AZ-003.jpg convert -resize 125% GBG11-4.png AZ-004.jpg convert -resize 125% GBG11-5.png AZ-005.jpg convert -resize 125% GBG11-6.png AZ-006.jpg -$ chmod 700 go -$ ./go -$ ls -lh total 3.8M -rw-r--r-- 1 jan users 57K 2007-06-12 16:54 AZ-001.jpg -rw-r--r-- 1 jan users 57K 2007-06-12 16:54 AZ-002.jpg -rw-r--r-- 1 jan users 57K 2007-06-12 16:54 AZ-003.jpg -rw-r--r-- 1 jan users 48K 2007-06-12 16:54 AZ-004.jpg -rw-r--r-- 1 jan users 42K 2007-06-12 16:54 AZ-005.jpg -rw-r--r-- 1 jan users 54K 2007-06-12 16:54 AZ-006.jpg -rw-r--r-- 1 jan users 610K 2007-06-12 16:48 GBG11-1.png -rw-r--r-- 1 jan users 612K 2007-06-12 16:48 GBG11-2.png -rw-r--r-- 1 jan users 608K 2007-06-12 16:48 GBG11-3.png -rw-r--r-- 1 jan users 519K 2007-06-12 16:48 GBG11-4.png -rw-r--r-- 1 jan users 508K 2007-06-12 16:48 GBG11-5.png -rw-r--r-- 1 jan users 601K 2007-06-12 16:48 GBG11-6.png -rwx------ 1 jan users 265 2007-06-12 16:48 goAfter the 'go' command the processor is quite busy. But it is the fastest way to do these things. See if you can use the program for your purposes, probably after you made massive changes.
Page created 12 June 2007,
Page equipped with FroogleBuster technology