I just noticed an interesting support request in our support department. The user's intention was to insert an image into a text frame and to readjust the horizontal image size in the case that the text frame is resized.

The Image.Size property is read-only and contains the original size of the image. Images can be scaled using the HorizontalScaling and VerticalScaling properties. The scaling factor can be adjusted in percent. To calculate the proportion between the original size and the new size of the text frame, we simply divide the new frame size by original image size.

private void adaptImageSize(TXTextControl.TextFrame Frame, TXTextControl.Image Image, Size NewSize)
{
    Frame.Size = NewSize;
    float zoomX = ((float)Frame.Size.Width / (float)Image.Size.Width);
    Image.HorizontalScaling = (int)(zoomX * 100f);
}