povray

Calculate image height based on image width in Povray?


To render an image that is 1000px wide and 1500px high, I have to pass both variables from the command line:

povray scene.pov Width=1000 Height=1500      (or povray scene.pov +W1000 +H1500)

It would be much more practical to just write

povray scene.pov Width=1000      (or povray scene.pov +W1000)

and to have the height calculated based on the width in the script.

One might expect that the solution should look like this: #declare Height = 1.5 * Width;

But that does not work. (Povray does not know the variable Width.)
And defining Width and Height in the script does not change the output size. (Or anything else.)

(Using image_width and image_height does other terrible things, but does not change the render size either.)

Is there some way to achieve in the script what can be achieved from the command line?

(The point here is that I want to avoid the extra step of adding the correct size for a particular scene to the console command. Anything else that I would also have to copy to the console would not solve this initial problem. Having to copy the correct size or the correct factor is basically the same.)


Solution

  • You can read the values set for output width and height from inside the script: those are in the pre-set variables image_width and image_height. Docs: https://www.povray.org/documentation/view/3.6.1/228/

    Unfortunately, there is no way to set any of them from within the script - you can just check their value, and use them to set up camera parameters (for example, to get the correct aspect-ratio of the final image).

    Also, check related question: POV-Ray: Setting output resolution or width/heigh ratio within the script \

    (As it asks about the aspect ratio, this one is not a duplicate).

    That said, the only way out seems to be to wrap the call to povray in another script that would calculate the parameters for you. Artisan's answer has asimple way to do that using Bash. A more sophisticated script could add more parameters, like one "aspect-ratio" that could improve what you can do.