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

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

Moderators: XnTriq, xnview

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

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

Postby m.Th. » Thu Feb 09, 2017 8:15 am

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


(sorry for the delay)

For Visual Basic Script the things are simple:

You need something like the Run (or Exec) method of a Shell object. See here for the syntax & all: http://ss64.com/vb/run.html

Code: Select all

Dim oShell ' declare the object (ok, under the hood it allocates a pointer which is, till now, nil
Set oShell = CreateObject("WScript.Shell") ' we actually create it

for i = 0 to 90 step 2
  cCmd="nconvert -rotate " & i & "-bgcolor 255 255 255 -out png -clevel 9 -o output\Rotated_" & i & ".png  SourceFile.png"  'here we assemble the command
  oShell.Run cCmd, 1, True '===== Here is an interesting discussion if we need True or False (True means 'wait for termination' which most probably is needed on an HDD)
next i


Disclaimer: not tested.

Note: Take care to not have spaces in paths. If they appear, then you need to enclose the paths in quotes (")
m. Th.

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

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

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

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

Postby cday » Thu Feb 09, 2017 9:11 am

Thanks m.Th., that code saved with a .vbs extension should then run [subject to any debugging required] on a Windows computer [which will have VBS and any other software required] that also has NConvert installed?

My interest is in identifying a reasonably easy-to-learn way of putting basic control structures etc. around NConvert code, where it is only necessary to learn a small number of terms, and the code is as far as possible self-explanatory, so that examples can easily be adapted to different situations: no cryptic syntax or tricks required like those often needed in cmd.exe...

Meanwhile, I've started taking a quick look at Powershell: although the applications I have in mind are far removed from almost everything I've read before about Powershell, which seems to be very much oriented at system administration, if that's the correct term, at a quick look it seems as if it might actually be a good way to go? Edit: Looking at the security provisions which complicate running scripts, possibly not...

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

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

Postby merry widow » Thu Feb 09, 2017 7:43 pm

m.Th. wrote:For Visual Basic Script the things are simple (SNIP)
cday wrote:I've developed an outline NConvert solution which I think could be developed (SNIP)
helmut wrote:Bas[ed] on cday's excellent groundwork and idea I've changed the Windows batch script a bit (SNIP)

Wow you guys are incredible, thank you so much for helping me with this! I may have to return to the thread because I'm not the greatest with command-line stuff, so what's the consensus? Proceed with cday's script? Helmut's build? Thanks guys. :mrgreen:
I may be frivolous but I am never trivial.

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

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

Postby merry widow » Thu Feb 09, 2017 7:55 pm

cday wrote:Thanks m.Th.My interest is in identifying a reasonably easy-to-learn way of putting basic control structures etc. around NConvert code, where it is only necessary to learn a small number of terms, and the code is as far as possible self-explanatory, so that examples can easily be adapted to different situations: no cryptic syntax or tricks required like those often needed in cmd.exe. (SNIP)

On behalf of the 99% of the world's population who aren't programmers I thank you cday! :mrgreen: It accrues to the continuing reputation of XnView, as well.
I may be frivolous but I am never trivial.

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

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

Postby merry widow » Thu Feb 09, 2017 8:02 pm

m.Th. wrote:after generating such a spreadsheet you can output it in a text file and change the extension to [a] .bat file.

Careful m.Th. you'll disclose your age (and mine hee hee). :twisted:
I may be frivolous but I am never trivial.

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

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

Postby merry widow » Fri Feb 10, 2017 1:17 am

cday wrote:

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

cday this is extremely important:

The background (or as you've referred, "canvas") generated needs to always be transparent or you might just as well do these rotations manually, one-at-a-time because you've corrupted the image's Alpha Channel — the core means by which your image renders background transparency & opacity — once you introduce a color. It's sort of like finding a skunk in your garage: you can get rid of the skunk but the smell will linger for weeks.

What we're discussing is RGBA (A for "Alpha"). I do not doubt ImageMagick has a script(s) for this rotation conversion, but they aren't XnView are they? Impose a DOS window on the average graphics beginner and the last thing you'll see is their shirttails flapping behind them as they disappear from view and head straight for the comforting GUI of Paint (or seriously contemplate a different profession). :mrgreen:

You can Google this issue and be introduced to the 2 million people who asked it before you. As usual the professional programming community at Stackoverflow is highly recommended, not just for the link that sent you there in the first place but to be schooled in the noun used globally to refer to what it is you need help with. I will never forget the hours I wasted hunting down a CSS script before discovering that what I had been calling a bracket was in fact a brace.

I've collected a few links that members might find useful in my/our mutual effort to preserve transparency when batch rotating an image and look forward to your advice.
I may be frivolous but I am never trivial.

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

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

Postby cday » Fri Feb 10, 2017 8:06 am

merry widow wrote:
cday wrote:

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

cday this is extremely important:

The background (or as you've referred, "canvas") generated needs to always be transparent or you might just as well do these rotations manually, one-at-a-time because you've corrupted the image's Alpha Channel — the core means by which your image renders background transparency & opacity — once you introduce a color.

Rereading your original post, you did mention that the image to be rotated was a PNG but didn't specifically mention transparency, and I'm afraid I didn't foresee that issue...

XnTriq is very much the transparency expert, so possibly he will be able to suggest a way of rotating an image with transparency while maintaining the transparency, and it will then be possible to incorporate it the NConvert code... :?:

Incidentally, the reason your attempts to obtain the result you need using batch convert failed is that however many rotation actions you applied, batch convert only generates a single output file for each input file processed...

Edit:

Transparency is not one of my special subjects and is complicated by the fact that there is more than one form, but in a test rotation of a transparent PNG file the transparency seemed to be maintained in the new canvas added... You might therefore try simply omitting the background colour term in the NConvert code above and check the result :?:

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

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

Postby helmut » Fri Feb 10, 2017 2:25 pm

m.Th. wrote:... PERL anyone? 8)

Did you perhaps mean "Python"?

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

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

Postby merry widow » Sat Feb 11, 2017 1:40 am

cday wrote:Transparency is not one of my special subjects and is complicated by the fact that there is more than one form, but in a test rotation of a transparent PNG file the transparency seemed to be maintained in the new canvas added... You might therefore try simply omitting the background colour term in the NConvert code above and check the result?

I'll see your :?: and raise you a :!:

cday I didn't originally include the need for a transparent backgroud but that's my fault not yours. Luckily a huge portion of the graphics community have trod this path before me. I have to remind myself that xnView is not a graphics program. :!: The Author's love affair with his creation is everywhere on the XnView site and I find it so touching as I'm sure everyone else does.

    <!--// MODERATOR'S NOTE: This post has been edited to meet the rules and guidelines of this message board. //-->

I don't have Photoshop but I do have Corel Draw and PaintShop Pro. Free options include GIMP and the venerable INKSCAPE. And IrfanView has an interesting thread here.

With the exception of IrfanView (which I have never tried) all four of the graphics editors I just listed are huge memory hogs. I should stop putting it off and at least start to get comfortable with ImageMagick whose greatest virtue is that it can boast the smallest footprint of any graphics tool.
Last edited by XnTriq on Sat Feb 11, 2017 10:00 am, edited 3 times in total.
Reason: Please keep your political views to yourself. Thank you.
I may be frivolous but I am never trivial.


Return to “MP - General Support”

Who is online

Users browsing this forum: No registered users and 2 guests