program anim01; uses dos; function parameter( n : longint; promptstring : string ) : string; var out : string; begin if ( (n > 0) and (n <= paramcount) ) then out:= paramstr(n) else begin write( promptstring, ': '); readln(out); end; parameter:= out; end; // end function parameter function max( a, b : integer ) : integer; begin if ( a>b ) then max:= a else max:= b; end; // end function max function min( a, b : integer ) : integer; begin if ( a=0) then outx:= '+' + outx; if (geomy>=0) then outy:= '+' + outy; calcGeom:= outx+outy; end; // end function calcGeom var background, sub, img_, varin, batchfilename, tempfilename, imgfilename, lastfilename, basefilename, strTotalFrames, geom, geomy : string; x, y, dx, dy, maxx, maxy, minx, miny, duration, bgw, bgh, imgw, imgh, maximgw, maximgh, images, totalFrames, delay, i, currentLineNo, nextImage : integer; fps, dimgpf, imgindex : real; batchin, batchout, IMreport : text; srec : SearchRec; BEGIN whitespace:= [ #9, #10 , #13, #32]; current_char:= #32; currentLineNo:= -1; maximgw:= 0; maximgh:= 0; images:= 0; dy:=0; background:= parameter(1, 'background file name'); sub:= parameter(2, 'subdirectory for moving images'); img_:= parameter(3, 'filename pattern for moving images'); val( parameter(4, 'horizontal distance traveled by image each frame(pixels)'), dx); val( parameter(5, 'fps (.01 - 100)'), fps); delay:= trunc(100/fps); // create a batch file to run ImageMagick to extract information about // the entered files assign( batchin, 'deleteme.bat'); rewrite(batchin); writeln(batchin, 'echo off' ); writeln(batchin, 'identify ', background, '>deleteme.txt'); writeln(batchin, 'identify ', sub + '\' + img_, '>>deleteme.txt'); close(batchin); exec('deleteme.bat', ''); if (DosExitCode() > 0) then begin writeln( 'Error attempting to identify the input files specified.'); writeln( 'The files may not exist, or you may not have ImageMagick'); writeln( 'installed on your system.'); end else begin assign(IMreport, 'deleteme.txt'); reset(IMreport); varin:= next_token(IMreport); if (varin <> background) then begin writeln('Error attempting to identify the background file.'); writeln('expected: ', background); writeln('found: ', varin); end else begin varin:= next_token(IMreport); writeln('background file type: ', varin); varin:= next_token(IMreport); writeln('background w x h: ', varin); val(copy(varin, 1, pos('x', varin)-1), bgw); val(copy(varin, pos('x',varin)+1, length(varin)), bgh); readln(IMreport, varin); while not eof(IMreport) do begin varin:= next_token(IMreport); varin:= next_token(IMreport); varin:= next_token(IMreport); val(copy(varin, 1, pos('x', varin)-1), imgw); val(copy(varin, pos('x',varin)+1, length(varin)), imgh); maximgh:= max(imgh, maximgh); maximgw:= max(imgw, maximgw); readln(IMreport, varin); images:= images + 1; end; reset(IMreport); totalFrames:= (bgw+maximgw) div dx; dimgpf:= images / totalFrames; str(totalFrames, strTotalFrames); batchfilename:= copy(background, 1, pos('.',background)-1) + '-' + copy(sub, 1, pos('-',sub)) + strTotalFrames + '.bat'; assign(batchout, batchfilename); writeln('batch file name: ', batchfilename); rewrite(batchout); writeln(batchout); writeln(batchout,'rem This batch file was generated by a Free Pascal Program'); writeln(batchout,'rem from the parameters listed below:'); writeln(batchout); writeln(batchout,'rem background file name: ', background); writeln(batchout,'rem subdirectory containing moving images: ', sub); writeln(batchout,'rem filename pattern for moving images: ', img_); writeln(batchout,'rem horizontal distance traveled each frame by moving images: ', dx); writeln(batchout,'rem frames per second (.01 - 100): ', fps:5:2); writeln(batchout,'rem A few of the values generated from this input:'); writeln(batchout,'rem width of background file: ', bgw); writeln(batchout,'rem total frames in animation: ', totalFrames); writeln(batchout,'rem total images available in subdirectory: ', images); writeln(batchout,'rem images skipped between frames: ', dimgpf:3:1); writeln(batchout,'rem 0=one image is used over and over'); writeln(batchout,'rem 1=each frame uses the next image in line'); writeln(batchout,'rem 2=each frame uses every other image'); writeln(batchout); writeln(batchout, 'del temp*.png'); dy:= round(sqrt(dx)); maxx:= bgw + maximgw div 2; maxy:= (bgh div 4) + round(sqrt(maximgh)); minx:= -maximgw; miny:= (bgh div 4) - round(sqrt(maximgh)); x:= minx; y:= miny; readln(IMreport, varin); currentLineNo:= 0; imgindex:= 1; for i:= 1 to totalFrames do begin x:= x + dx; y:= y + dy; if ((x>=maxx) or (x<=minx)) then dx:= -dx; if ((y>=maxy) or (y<=miny)) then dy:= -dy; imgindex:= imgindex + dimgpf; nextimage:= round(imgindex); while currentLineNo < nextimage do begin lastfilename:= imgfilename; imgfilename:= next_token(IMreport); if (imgfilename = '') then imgfilename:= lastfilename; if (pos('[',imgfilename)>0) then imgfilename:= copy(imgfilename, 1, pos('[',imgfilename)-1); val(copy(varin, 1, pos('x', varin)-1), imgw); val(copy(varin, pos('x',varin)+1, length(varin)), imgh); readln(IMreport); currentLineNo:= currentLineNo + 1; end; tempfilename:= 'temp' + strz(i,4) + '.png'; writeln(batchout,'composite -geometry ', calcGeom(x,y,imgw,imgh), ' ',imgfilename, ' ', background, ' ', tempfilename); end; writeln(batchout,'for %%f in (temp*.png) do mogrify +raise 12x12 %%f'); writeln(batchout,'for %%f in (temp*.png) do mogrify -bordercolor "#805B31" -border 8 %%f'); writeln(batchout,'for %%f in (temp*.png) do convert %%f -resize 50%% m%%f'); writeln(batchout,'for %%f in (temp*.png) do convert %%f -resize 25%% s%%f'); writeln(batchout); basefilename:= copy(batchfilename, 1, pos('.',batchfilename)-1); writeln(batchout,'convert -delay ', delay, ' -deconstruct temp*.png ', basefilename + 'b.gif'); writeln(batchout,'convert -delay ', delay, ' -deconstruct mtemp*.png ', basefilename + 'm.gif'); writeln(batchout,'convert -delay ', delay, ' -deconstruct stemp*.png ', basefilename + 's.gif'); writeln(batchout,'copy mtemp', strz(min(images,totalFrames) div 2, 4), '.png ', basefilename, 'ptr.png'); writeln(batchout,'convert temp', strz(min(images,totalFrames) div 2, 4), '.png -resize 10%% ', basefilename, 'ptr2.png'); writeln(batchout, 'del mtemp*.png'); writeln(batchout, 'del stemp*.png'); end; end; close(batchout); END.