Skip to main content
Participant
January 22, 2024
Question

FrameMaker 11: Is there a way to scale imported graphics automatically to fit the column?

  • January 22, 2024
  • 2 replies
  • 316 views

FrameMaker 11 and DITA. We have a DITA document with some graphics imported by reference wider than a column. Is there a way to scale the image automatically to fit the column/anchored frame instead of cropping it when opening the document, f.ex in read/write rules?

 

Any help appreciated.

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    January 23, 2024

    Hi, Tuula268312076vq3

    This script fits an image to an anchored frame within a selection.

    Do not select all to avoid unexpected results.

    I hope it helps you.

     

    var doc = app.ActiveDoc;
    var tr = doc.TextSelection;
    var cmd1 = app.GetNamedCommand ("AlignGfxTBCenter");
    var cmd2 = app.GetNamedCommand ("AlignGfxLRCenter");
    // Get anchor frame from selection
    var textItems = doc.GetTextForRange (tr, Constants.FTI_FrameAnchor);
    for (var i=0;i<textItems.length;i++){
        var aFrame = textItems[i].obj;
        var graphic = aFrame.FirstGraphicInFrame;
        var verticalRatio = aFrame.Height / graphic.Height;
        var HorizontalRatio = aFrame.Width / graphic.Width;
        var applicableRatio = verticalRatio > HorizontalRatio ? HorizontalRatio : verticalRatio;
        graphic.Height = graphic.Height * applicableRatio;
        graphic.Width = graphic.Width * applicableRatio;
        // Align image to center of anchor frame
        graphic.GraphicIsSelected = true;
        Fcodes ([cmd1.Fcode]);
        Fcodes ([cmd2.Fcode]);
    }

     

    frameexpert
    Community Expert
    Community Expert
    January 23, 2024

    This is a useful script. One suggestion is to avoid Fcodes for centering and set the properties LocX and LocY properties directly. You should be able to use this:

    graphic.LocX = (aFrame.Width - graphic.Width) / 2;
    graphic.LocY = (aFrame.Height - aFrame.Height) / 2;

    And of course, you can expand this to work on all of the graphics in the document at once. You can also have a script triggered automatically when the document is opened.

    Participating Frequently
    January 24, 2024

    Thank you for your wonderful suggestion.

    I modified the script and it became about 2.9x faster.

    Participant
    January 22, 2024

    The images are in EPS format.