Batch processing: Rotate-Save-Rotate-Save...

Ask for help and post your question on how to use XnView MP.

Moderators: XnTriq, helmut, xnview

User avatar
merry widow
Posts: 34
Joined: Wed Jul 30, 2014 4:53 pm

Batch processing: Rotate-Save-Rotate-Save...

Postby merry widow » Mon Feb 06, 2017 12:40 am

I have one PNG graphic that I want to generate 44 additional versions of.

The conversion is a CW ROTATION increasing every 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. :mrgreen:
I may be frivolous but I am never trivial.

User avatar
m.Th.
XnThusiast
Posts: 1331
Joined: Wed Aug 16, 2006 6:31 am
Contact:

Re: Please recommend how I should proceed with this batch .

Postby m.Th. » Mon Feb 06, 2017 10:39 am

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!
m. Th.

The Ascetic Experience - The best photos and texts from Holy Mountain (Athos)

- Dark Themed XnViewMP 0.84 64bit & XnView 2.00 x64 on Win7 x64 -

cday
XnThusiast
Posts: 1357
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Please recommend how I should proceed with this batch .

Postby cday » Mon Feb 06, 2017 11:39 am

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.

Yes, using NConvert looks like the solution, the exact code to be confirmed, but:

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...

User avatar
m.Th.
XnThusiast
Posts: 1331
Joined: Wed Aug 16, 2006 6:31 am
Contact:

Re: Please recommend how I should proceed with this batch .

Postby m.Th. » Mon Feb 06, 2017 3:37 pm

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...


Or Visual Basic Script for example...
m. Th.

The Ascetic Experience - The best photos and texts from Holy Mountain (Athos)

- Dark Themed XnViewMP 0.84 64bit & XnView 2.00 x64 on Win7 x64 -

cday
XnThusiast
Posts: 1357
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby cday » Mon Feb 06, 2017 4:13 pm

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:

Code: Select all

nconvert -rotate 02 -o Output\%%.png *.png

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):

Code: Select all

-bgcolor 255 255 255

To following code is also included to set the compression used in the output PNG (9, the maximum value):

Code: Select all

-out png -clevel 9


The full code for the first four rotations is therefore:

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


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.

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 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 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...

Rotate_utility.zip
(883.16 KiB) Downloaded 13 times

User avatar
helmut
Moderator
Posts: 8080
Joined: Sun Oct 12, 2003 6:47 pm
Location: Frankfurt, Germany

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby helmut » Mon Feb 06, 2017 9:25 pm

Basing on cday's excellent groundwork and idea I've changed the Windows batch script a bit:

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)

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.

cday
XnThusiast
Posts: 1357
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby cday » Mon Feb 06, 2017 9:44 pm

helmut wrote:Basing on cday's excellent groundwork and idea I've changed the Windows batch script a bit...

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!

User avatar
helmut
Moderator
Posts: 8080
Joined: Sun Oct 12, 2003 6:47 pm
Location: Frankfurt, Germany

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby helmut » Mon Feb 06, 2017 9:46 pm

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!
:)

User avatar
m.Th.
XnThusiast
Posts: 1331
Joined: Wed Aug 16, 2006 6:31 am
Contact:

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby m.Th. » Tue Feb 07, 2017 9:02 am

cday wrote:
helmut wrote:Basing on cday's excellent groundwork and idea I've changed the Windows batch script a bit...

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!


PERL anyone? 8)
m. Th.

The Ascetic Experience - The best photos and texts from Holy Mountain (Athos)

- Dark Themed XnViewMP 0.84 64bit & XnView 2.00 x64 on Win7 x64 -

cday
XnThusiast
Posts: 1357
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby cday » Tue Feb 07, 2017 9:19 am

m.Th. wrote:
cday wrote:
helmut wrote:Basing on cday's excellent groundwork and idea I've changed the Windows batch script a bit...

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!


PERL anyone? 8)

A language like PERL, included in Windows, woud certainly be useful to sidestep the severe practical limitations of cmd.exe... :wink:

Do you have a PERL solution?

User avatar
helmut
Moderator
Posts: 8080
Joined: Sun Oct 12, 2003 6:47 pm
Location: Frankfurt, Germany

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby helmut » Tue Feb 07, 2017 10:18 am

cday wrote:... A language like PERL, included in Windows, woud certainly be useful to sidestep the severe practical limitations of cmd.exe... :wink:

Do you have a PERL solution?
I'd say: If you want a flexible and compact but really cryptic solution then go for Perl. :wink:

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”

User avatar
m.Th.
XnThusiast
Posts: 1331
Joined: Wed Aug 16, 2006 6:31 am
Contact:

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby m.Th. » Tue Feb 07, 2017 11:16 am

cday wrote:
m.Th. wrote:
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!


PERL anyone? 8)

A language like PERL, included in Windows, woud certainly be useful to sidestep the severe practical limitations of cmd.exe... :wink:

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: Write once – never understand again”


"Perl - the only write-only language" :)
m. Th.

The Ascetic Experience - The best photos and texts from Holy Mountain (Athos)

- Dark Themed XnViewMP 0.84 64bit & XnView 2.00 x64 on Win7 x64 -

cday
XnThusiast
Posts: 1357
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby cday » Tue Feb 07, 2017 11:38 am

@m.Th.

I meant, do you have a Perl solution to Merry Widows' problem you could post?

User avatar
m.Th.
XnThusiast
Posts: 1331
Joined: Wed Aug 16, 2006 6:31 am
Contact:

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby m.Th. » Tue Feb 07, 2017 1:27 pm

cday wrote:@m.Th.

I meant, do you have a Perl solution to Merry Widows' problem you could post?


Yes - I know. :)

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.

The Ascetic Experience - The best photos and texts from Holy Mountain (Athos)

- Dark Themed XnViewMP 0.84 64bit & XnView 2.00 x64 on Win7 x64 -

cday
XnThusiast
Posts: 1357
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch processing: Rotate-Save-Rotate-Save...

Postby cday » Tue Feb 07, 2017 2:18 pm

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.

I would be very interested in seeing solutions using any of the above thanks, particularly perhaps VBS or JavaScript examples... :D

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.


Return to “MP - General Support”

Who is online

Users browsing this forum: No registered users and 3 guests