Skip to content

How do you rotate text on an image? #190

Answered by replaysMike
replaysMike asked this question in Q&A
Discussion options

You must be logged in to vote

As per discission with @JimBobSquarePants , here is the correct transform for rotation that was discussed in issue #192 :

TextOptions textOptions = new(font);
FontRectangle bounds = TextMeasurer.Measure(text, textOptions);
AffineTransformBuilder builder = new AffineTransformBuilder()
    .AppendRotationDegrees(rotationAngle)
    .AppendTranslation(new PointF(100, 50));;

// We should probably add an extension to FontRectangle to make the conversion to Rectangle easier.
Matrix3x2 transform = builder.BuildMatrix(Rectangle.Round(new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height)));
var drawingOptions = new DrawingOptions
{
    Transform = transform
};
image.Mutate(c => c.DrawText(

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@replaysMike
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by replaysMike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants