Skip to main content
sam95317750
Known Participant
Feb 18, 2019 8:55 AM UTC
Answered

How can I replace .gif format for multiple image names to .png in FM in one go.

I have to change the image file formats from .gif to .png for a FM book. Now if I change the file format then FM does not recognizes the old images and shows and error.

Is there a way to update file format in one go? Thanks.

This topic is closed to new replies. Start a new post to keep the conversation going.
Russ WardCorrect answer
Legend
Feb 18, 2019 12:25 PM UTC

Hi, here is how you can do it for a single file. It's a little more complicated for a whole book... if you don't have that many chapters, it might be quicker just to run the script on each file manually. Hope this helps. -Russ

function graphicsGifToPng()

{

    var counter = 0;

    var graphic = app.ActiveDoc.FirstGraphicInDoc;

   

    while(graphic.ObjectValid())

    {

        if(graphic.constructor.name == "Inset" &&

           graphic.InsetFile != "" &&

           graphic.InsetFile.indexOf(".gif") > 0)

        {

            var path = graphic.InsetFile;

            path = path.replace(".gif", ".png");

            graphic.InsetFile = path;

            counter++;

        }

       

        graphic = graphic.NextGraphicInDoc;     

    }

    alert("Script complete. " + counter + " graphic(s) adjusted.");

}

9 replies

sam95317750
Known Participant
Mar 13, 2019 5:13 AM UTC

Hi 4everJang​ and Russ,

Thank you for your response.

Translate
Russ WardCorrect answer
Legend
Feb 18, 2019 12:25 PM UTC

Hi, here is how you can do it for a single file. It's a little more complicated for a whole book... if you don't have that many chapters, it might be quicker just to run the script on each file manually. Hope this helps. -Russ

function graphicsGifToPng()

{

    var counter = 0;

    var graphic = app.ActiveDoc.FirstGraphicInDoc;

   

    while(graphic.ObjectValid())

    {

        if(graphic.constructor.name == "Inset" &&

           graphic.InsetFile != "" &&

           graphic.InsetFile.indexOf(".gif") > 0)

        {

            var path = graphic.InsetFile;

            path = path.replace(".gif", ".png");

            graphic.InsetFile = path;

            counter++;

        }

       

        graphic = graphic.NextGraphicInDoc;     

    }

    alert("Script complete. " + counter + " graphic(s) adjusted.");

}

Translate
4everJang
Legend
Feb 18, 2019 12:34 PM UTC

As Russ mentioned, opening files in a book is a little more work. You need to cycle through the linked list of BookComponent elements, then open each file and run the code that Russ has shown. Make sure you use the document handle there instead of the activeDoc, just to stay on the safe side.

Also, when opening each FM document, make sure to have FM ignore any missing file names, otherwise your script will block on the images not found and present you with a dialog after all. You should check all the parameters described in the Scripting Guide for GetOpenDefaultParams( ). You will want to switch off messages about files not found, fonts not found, and switch off resolving cross-references.

Translate