Batch processing: Rotate-Save-Rotate-Save...
Moderators: XnTriq, helmut, xnview
- merry widow
- Posts: 36
- Joined: Wed Jul 30, 2014 4:53 pm
Batch processing: Rotate-Save-Rotate-Save...
I have one PNG graphic that I want to generate 44 additional versions of.
The conversion is a CW ROTATION increasing every 2° up until I reach 90°. What I'd really prefer is to save the batch in a text-editable file that I can run, as opposed to using the GUI. Much easier for me to copy/paste eh? (2° 4° 6° 8° 10 °12° 14° etc.)
I did attempt to do this through Xn's GUI (very straightforward feature, I thank you!) alas, it didn't work. I presume I was structuring the batch correctly (?) — 44 double clicks of Rotate, starting with 2° and painstakingly edited by me in the little box — but I confess I did accidentally move/touch my mouse a particular way and the batch launched before I could even save it.
Appreciate any advice, thanks everyone.
The conversion is a CW ROTATION increasing every 2° up until I reach 90°. What I'd really prefer is to save the batch in a text-editable file that I can run, as opposed to using the GUI. Much easier for me to copy/paste eh? (2° 4° 6° 8° 10 °12° 14° etc.)
I did attempt to do this through Xn's GUI (very straightforward feature, I thank you!) alas, it didn't work. I presume I was structuring the batch correctly (?) — 44 double clicks of Rotate, starting with 2° and painstakingly edited by me in the little box — but I confess I did accidentally move/touch my mouse a particular way and the batch launched before I could even save it.
Appreciate any advice, thanks everyone.
I may be frivolous but I am never trivial.
Re: Please recommend how I should proceed with this batch .
Do you know to use Microsoft Excel or any other advanced spreadsheet? (eg. Libre/OpenOffice etc.)
If yes, you can fill a spreadsheet with commands by using nconvert (the command line variant of XnView MP's convert engine) something like (I write the syntax from my head - most probably it is wrong):
nconvert file01.png rotate 2 -out file02.png
nconvert file02.png rotate 2 -out file03.png
...
after generating such a spreadsheet you can output it in a text file and change the extension to .bat.
Run it.
Enjoy!
If yes, you can fill a spreadsheet with commands by using nconvert (the command line variant of XnView MP's convert engine) something like (I write the syntax from my head - most probably it is wrong):
nconvert file01.png rotate 2 -out file02.png
nconvert file02.png rotate 2 -out file03.png
...
after generating such a spreadsheet you can output it in a text file and change the extension to .bat.
Run it.
Enjoy!
m. Th.
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
Re: Please recommend how I should proceed with this batch .
Yes, using NConvert looks like the solution, the exact code to be confirmed, but:m.Th. wrote:Do you know to use Microsoft Excel or any other advanced spreadsheet? (eg. Libre/OpenOffice etc.)
If yes, you can fill a spreadsheet with commands by using nconvert (the command line variant of XnView MP's convert engine) something like (I write the syntax from my head - most probably it is wrong):
nconvert file01.png rotate 2 -out file02.png
nconvert file02.png rotate 2 -out file03.png
...
after generating such a spreadsheet you can output it in a text file and change the extension to .bat.
o Using the output of each 2º rotation step as the input for the next rotation risks building up a cumulative error in successive outputs, it would therefore be better to rotate the original input file n (44) times so that the output rotations are accurate.
o Usings a spreadsheet program to generate the lines of a batch file .bat might save time if you're familiar with the program, but for a one-off solution simply editing copies of the first command wouldn't be too tedious, and would be simplified if the input file is the same and only the rotation value has to be edited, as suggested above.
o There may well also be a much simpler (fewer lines of code) solution using a cmd.exe ('DOS') loop in the batch file...
Re: Please recommend how I should proceed with this batch .
Or Visual Basic Script for example...cday wrote:m.Th. wrote:Do you know to use Microsoft Excel or any other advanced spreadsheet? (eg. Libre/OpenOffice etc.)
o There may well also be a much simpler (fewer lines of code) solution using a cmd.exe ('DOS') loop in the batch file...
m. Th.
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
Re: Batch processing: Rotate-Save-Rotate-Save...
Continued...
I've developed an outline NConvert solution which I think could be developed reasonably practically to do what you need, and in case you're not very familiar with using the command line, I've created a stand-alone utility which is attached in a ZIP archive.
The utility consists of a copy of a Windows batch file script Rotate_utility.bat, an Output folder and a copy of NConvert.exe (not the current version). To use the script, place the PNG file (or files) to be rotated in the folder containing the script, and then run the utility (by double-clicking, for example). You should then find in the Output folder a copy of the original PNG and successive rotations (four in the script supplied).
The basic code used to perform each rotation (in the example 2º) is:
As a rotation adds canvas, the background colour to be used normally needs to be specified which adds this term (for white, the red. green and blue values for which are all 255):
To following code is also included to set the compression used in the output PNG (9, the maximum value):
The full code for the first four rotations is therefore:
To test the utility, download the attached ZIP and extract the contents to any convenient location; note that as the script uses relative addressing the contents must remain in the same position relative to each other.
I've developed an outline NConvert solution which I think could be developed reasonably practically to do what you need, and in case you're not very familiar with using the command line, I've created a stand-alone utility which is attached in a ZIP archive.
The utility consists of a copy of a Windows batch file script Rotate_utility.bat, an Output folder and a copy of NConvert.exe (not the current version). To use the script, place the PNG file (or files) to be rotated in the folder containing the script, and then run the utility (by double-clicking, for example). You should then find in the Output folder a copy of the original PNG and successive rotations (four in the script supplied).
The basic code used to perform each rotation (in the example 2º) is:
Code: Select all
nconvert -rotate 02 -o Output\%%.png *.png
Code: Select all
-bgcolor 255 255 255
Code: Select all
-out png -clevel 9
Code: Select all
nconvert -rotate 00 -bgcolor 255 255 255 -out png -clevel 9 -o Output\%%.png *.png
nconvert -rotate 02 -bgcolor 255 255 255 -out png -clevel 9 -o Output\%%.png *.png
nconvert -rotate 04 -bgcolor 255 255 255 -out png -clevel 9 -o Output\%%.png *.png
nconvert -rotate 06 -bgcolor 255 255 255 -out png -clevel 9 -o Output\%%.png *.png
nconvert -rotate 08 -bgcolor 255 255 255 -out png -clevel 9 -o Output\%%.png *.png
I think the attached script if it runs for you could fairly easily, if slightly tediously, be extended to all the rotations you need using copy and paste and simple editing, be sure to maintain the .bat extension though...merry widow wrote:I have one PNG graphic that I want to generate 44 additional versions of.
The conversion is a CW ROTATION increasing every 2° up until I reach 90°. What I'd really prefer is to save the batch in a text-editable file that I can run, as opposed to using the GUI. Much easier for me to copy/paste eh? (2° 4° 6° 8° 10 °12° 14° etc.)
Re: Batch processing: Rotate-Save-Rotate-Save...
Basing on cday's excellent groundwork and idea I've changed the Windows batch script a bit:
Notes:
• (0,2,90) are the loop parameters: (<start>,<step>,<end>)
• SUFFIX is the loop variable as two digit number (00, 02, 04, ...). Thus filenames looks more consistent.
• Input file is Test_A.png in current directory
• Output files are written to the sub-directory "Output" and have naming "Test_A<nn>.png"
• Change "echo off" to "echo on" to see better what the script does.
• Change "nconvert -rotate..." to "nconvert -quiet -rotate..." to have no output from NConvert at all.
Code: Select all
@echo off
setlocal enableDelayedExpansion
for /L %%N IN (0,2,90) do (
if %%N lss 10 (set SUFFIX=0%%N) else set SUFFIX=%%N
nconvert -rotate %%N -bgcolor 255 255 255 -out png -clevel 9 -o Output\Test_A!SUFFIX!.png Test_A.png
)
REM -- Background colour: -bgcolor red green blue
REM -- Compression... -clevel value : PNG Compression level (default : 6)
• (0,2,90) are the loop parameters: (<start>,<step>,<end>)
• SUFFIX is the loop variable as two digit number (00, 02, 04, ...). Thus filenames looks more consistent.
• Input file is Test_A.png in current directory
• Output files are written to the sub-directory "Output" and have naming "Test_A<nn>.png"
• Change "echo off" to "echo on" to see better what the script does.
• Change "nconvert -rotate..." to "nconvert -quiet -rotate..." to have no output from NConvert at all.
Re: Batch processing: Rotate-Save-Rotate-Save...
Thanks, I thought there would be a solution something like that, but it is even more cryptic than I imagined and something of a dying art now!helmut wrote:Basing on cday's excellent groundwork and idea I've changed the Windows batch script a bit...
Re: Batch processing: Rotate-Save-Rotate-Save...
cday wrote:Thanks, I thought there would be a solution something like that, but it is even more cryptic than I imagined and something of a dying art now!
Re: Batch processing: Rotate-Save-Rotate-Save...
PERL anyone?cday wrote:Thanks, I thought there would be a solution something like that, but it is even more cryptic than I imagined and something of a dying art now!helmut wrote:Basing on cday's excellent groundwork and idea I've changed the Windows batch script a bit...
m. Th.
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
Re: Batch processing: Rotate-Save-Rotate-Save...
A language like PERL, included in Windows, woud certainly be useful to sidestep the severe practical limitations of cmd.exe...m.Th. wrote:PERL anyone?cday wrote:Thanks, I thought there would be a solution something like that, but it is even more cryptic than I imagined and something of a dying art now!helmut wrote:Basing on cday's excellent groundwork and idea I've changed the Windows batch script a bit...
Do you have a PERL solution?
Re: Batch processing: Rotate-Save-Rotate-Save...
I'd say: If you want a flexible and compact but really cryptic solution then go for Perl.cday wrote:... A language like PERL, included in Windows, woud certainly be useful to sidestep the severe practical limitations of cmd.exe...
Do you have a PERL solution?
I just found two interesting sayings at Wikipedia (German):
“Perl is the only language that looks the same before and after RSA encryption.” (Keith Bostic)
“Perl: Write once – never understand again”
Re: Batch processing: Rotate-Save-Rotate-Save...
cday wrote:A language like PERL, included in Windows, woud certainly be useful to sidestep the severe practical limitations of cmd.exe...m.Th. wrote:PERL anyone?cday wrote: Thanks, I thought there would be a solution something like that, but it is even more cryptic than I imagined and something of a dying art now!
Do you have a PERL solution?
A bunch of them:
http://www.perlmonks.org/?node=Obfuscated%20Code
https://en.wikipedia.org/wiki/Just_another_Perl_hacker
https://www.foo.be/docs/tpj/issues/vol5 ... -0014.html
And of course: http://www.perlmonks.org/index.pl?node_id=45213
Also, WRT
"Perl - the only write-only language"“Perl: Write once – never understand again”
m. Th.
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
Re: Batch processing: Rotate-Save-Rotate-Save...
@m.Th.
I meant, do you have a Perl solution to Merry Widows' problem you could post?
I meant, do you have a Perl solution to Merry Widows' problem you could post?
Re: Batch processing: Rotate-Save-Rotate-Save...
Yes - I know.cday wrote:@m.Th.
I meant, do you have a Perl solution to Merry Widows' problem you could post?
However, a Perl solution isn't interesting. From WinXP ages Windows has Visual Basic Script embedded (perhaps I can write something if you wish) and Java Script.
From Win7 onward it has PowerShell - a much more powerful scripting engine.
m. Th.
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
- Dark Themed XnViewMP 1.6 64bit on Win11 x64 -
Re: Batch processing: Rotate-Save-Rotate-Save...
I would be very interested in seeing solutions using any of the above thanks, particularly perhaps VBS or JavaScript examples...m.Th. wrote:From WinXP ages Windows has Visual Basic Script embedded (perhaps I can write something if you wish) and Java Script.
From Win7 onward it has PowerShell - a much more powerful scripting engine.
A need for basic program control actions arises fairly often when using NConvert, and cmd.exe only really seems a good solution if you are already familiar with its criptic notation.
BTW, Windows 10 now has option to install Bash, which is probably a significant improvement on cmd.exe but still probably not a readily accessable way of adding basic control actions without significant prior experience, and in any case it will be a long time before everyone is using Windows 10.