Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Fu - Math operations failing
#3
(01-31-2023, 09:56 AM)Kevin Wrote: scaleFactor = int(maxSize) / int(currentWidth) is returning zero because you're doing integer arithmetic. You need to make one or both into float values to get a fractional scaleFactor

Code:
> > > int(512) / int(258)
1
> > > int(512) / float(258)
1.9844961240310077

The int() was something that I added later as an attempt to fix the issue, in case the original values were being output as strings. When I first posted my message, I had int() around those values, but later edited it out because the original code just said scaleFactor = maxSize / currentWidth

I did test with one of the values defined as a float() instead, and it worked. So are the values produced by image.width/image.height strings? Is that why it was originally failing?

Edit: I realized that I can check the documentation for this question, and that that operation produces an integer.
Modder/Skinner at MarvelMods.com using GIMP to create, edit, and export textures and previews more efficiently.

My GIMP scripts hosted on GitHub
Reply


Messages In This Thread
RE: Python Fu - Math operations failing - by BaconWizard17 - 02-01-2023, 12:19 AM

Forum Jump: