programmatic conversion of picture format

Is there, or could there be, a programmatic way to do the equivalent of the 'convert to high resolution png' button in the pictures window?

I'm thinking about how I can load image data from the clipboard. My thought is to use LoadPict, followed by SavePict to save a temporary file and then LoadImage to load the data. If I find vector graphics in the clip I don't know how to force a conversion.

Hi Tony,

It is not clear what kind of vector graphic you want to support.  The ImageLoad operation in IP9 does not support vector graphics formats and so image file conversions would have to be done using other software (platform dependent).  Many applications load the clipboard with more than one flavor of the data so LoadPict may be able to select a format that it can handle.  If LoadPict can't handle the image format you are in the ExecuteScriptText domain.

A.G.

If I copy a section from a pdf, Igor can load from the clipboard as a picture (TYPE is PDF, and I'm pretty sure in the example I'm looking at that the picture holds vector graphics rather than embedded bitmap). Igor can also convert that picture to standard or high resolution png (two buttons in the Pictures panel). From there, the route to turning the png into a wave is clear, if a little convoluted. So Igor can do what I want, I just don't have a way to 'push the button'.

 

Tony,

This GUI is pretty ancient and it is not supported by explicit operations/functions. 

An ugly workaround is to programmatically create an empty graph window and draw the image (DrawPict) from which it is straightforward to save it as something else. 

An obscure feature that you may find handy is if you draw into a Gizmo window you might be able to save directly into a wave using ExportGizmo.  You may have to create one fake Gizmo object (invisible) in order to get the feature to work.

A.G.

Great, thanks.

I had considered a workaround of that type. It sounds like ExportGizmo might do the trick. I'll report back here after giving it a try.

this worked for me.

loads jpeg, tiff, png or vector graphics from clipboard as a wave.

function ImportClip()
           
    LoadPICT /Q/O "Clipboard", ImageTemp
    if (V_flag == 0)
        return 0
    endif
   
    string strPict = StringByKey("NAME", S_info)
    string strType = StringByKey("TYPE", S_info)
    variable width = NumberByKey("PHYSWIDTH", S_info)
    variable height = NumberByKey("PHYSHEIGHT", S_info)
   
    string ext = ""
    strswitch (strType)
        case "JPEG":
            ext = ".jpg"
            break
        case "TIFF":
            ext = ".tif"
            break
        case "PNG":
            ext = ".png"
            break  
    endswitch
   
    NewPath /O/Q/Z PathTemp, SpecialDirPath("Temporary", 0, 0, 0)
   
    if (strlen(ext)) // bitmap type
        SavePICT /Z/O/PICT=$strPict/P=PathTemp
        ImageLoad /Q/P=PathTemp/N=Image strPict+ext
    else   
        // create a hidden graph as a canvas for pict, match aspect ratio
        variable res = 500 // vertical size of graph in points; increase for higher resolution
        KillWindow /Z GraphTemp
        Display /W=(0,0,res*width/height, res)/N=GraphTemp/hide=1
        DrawPICT 0,0,1*res/height,1*res/height, $strPict
       
        // export the graph window as png
        SavePICT/E=-5/B=288/WIN=GraphTemp/O/P=PathTemp as "ImageTemp.png"
        KillWindow /Z GraphTemp
        ImageLoad /Q/P=PathTemp/N=Image "ImageTemp.png"
    endif
   
    // clean up
    KillPICTs /Z $strPict
    KillPath /Z PathTemp

    return 0
end