Rotate an Image Around its Center


Tip by Smurfier and JSMorley

There may be a time when you want to rotate an image around its own center, as demonstrated below:

Probably the easiest approach is to use a Rotator meter. What you will need to do is set the OffsetX and OffsetY to the middle of the image based on the width and height of the original. Then you will need to find the total width and height of the container needed to rotate the image, which will be the length of a line from the upper left to the bottom right corners. These will be used to set the W and H of the Rotator meter.

Then you can use any measure that returns a value between 0% and 100% (with any number of "steps") as the MeasureName of the meter, and the image will rotate around its own center based on the current value of that measure.

[Rainmeter]
Update=50
DynamicWindowSize=1
[Variables]
ImageW=128
ImageH=64
[MeasureRotate]
Measure=Calc
Formula=(MeasureRotate % 360) + 1
MaxValue=360
[MeterRotate]
Meter=Rotator
MeasureName=MeasureRotate
ImageName=Rectangle.png
OffsetX=(#ImageW# / 2)
OffsetY=(#ImageH# / 2)
W=(SQRT(#ImageW# ** 2 + #ImageH# ** 2))
H=(SQRT(#ImageW# ** 2 + #ImageH# ** 2))

The only complicated bit are those formulas to obtain the W and H settings for the meter. The formula (SQRT(ImageWidth ** 2 + ImageHeight ** 2)) [Reference] will measure the length from the top left to bottom right of the image, which is the size the meter will need to be to rotate the image in place without cutting off corners.



Note: If the visible part of the image being used is "round", then you will not need the formula to set the width and height of the meter. In fact, doing so will make the overall size of the meter container unnecessarily large. Simply use the full size of the image when specifying the W and H options in the meter.

[Rainmeter]
Update=50
DynamicWindowSize=1
[Variables]
ImageW=128
ImageH=128
[MeasureRotate]
Measure=Calc
Formula=(MeasureRotate % 360) + 1
MaxValue=360
[MeterRotate]
Meter=Rotator
MeasureName=MeasureRotate
ImageName=Circle.png
OffsetX=(#ImageW# / 2)
OffsetY=(#ImageH# / 2)
W=#ImageW#
H=#ImageH#