macro "Test ImageMagick Commands" { /* v240905: 1st version: Peter J. Lee, Applied Superconductivity Center, NHMFL, Florida State University */ macroL = "Run_ImageMagick_Commands_v240905.ijm"; if (nImages == 0) exit("Sorry this macro needs an image to work from, goodbye"); oTitle = getTitle(); fS = File.separator; win = startsWith(getInfo("os.name"), "Windows"); prefsPrefix = "asc.IMCommands."; qMark = "\""; " qMarkSp = qMark + " "; spQMark = " " + qMark; iMMagickPath = findAppPath("ImageMagick", "magick.exe", "not found"); if (iMMagickPath == "not found") exit("Could not find location of ImageMagick"); execString = qMark + iMMagickPath + qMarkSp + "clipboard: "; // run("Copy to System"); iMSettings = ""; /* ASC message theme */ infoColor = "#006db0"; /* Honolulu blue */ instructionColor = "#798541"; /* green_dark_modern (121,133,65) AKA Wasabi */ infoWarningColor = "#ff69b4"; /* pink_modern AKA hot pink */ dividerColor = "#50bfe6"; /* blizzard blue */ infoFontSize = 12; Dialog.create("Enter IM commands \(" + macroL + "\)"); exampleCommands = newArray("", "adaptive-sharpen", "auto-gamma", "auto-orient", "charcoal", "emboss", "kuwahara", "mode", "raise", "resize", "rotational-blur", "sort-pixels", "swirl", "unique-colors", "unsharp", "wavelet-denoise", "white-balance"); Dialog.addChoice("Choose an example command", exampleCommands, ""); Dialog.addString("Enter parameters", ""); Dialog.addMessage("Examples:\n-adaptive-blur 10x4, -adaptive-sharpen radius 10x1, -auto-gamma, -auto-level, -auto-orient\n-charcoal 5, -emboss 5, -kuwahara 3, -mode 5, -raise 30, -resize 200x50%, -rotational-blur 6\n-sort-pixels, -swirl 360, -unique-colors, -unsharp 10x4+2+0, -wavelet-denoise 5, -white-balance", infoFontSize, infoColor); if (win) Dialog.addCheckbox("Open https://imagemagick.org/script/command-line-options.php to see all options", false); Dialog.addMessage("Alternatively manually enter multiple command sets:______________________", infoFontSize, instructionColor); for (i = 0; i < 6; i++){ lastCommand = call("ij.Prefs.get", prefsPrefix + "lastCommand" + i, ""); Dialog.addString("Line " + i + 1 + ":", lastCommand, 50); } logCommand = call("ij.Prefs.get", prefsPrefix + "logCommand", false); Dialog.addCheckbox("Output command to log window", logCommand); Dialog.show; commandIM = Dialog.getChoice(); parametersIM = Dialog.getString(); if (win) exploreOptions = Dialog.getCheckbox(); else exploreOptions = false; for (i = 0, ; i < 6; i++){ commandString = Dialog.getString(); if (commandString != "") iMSettings += " " + commandString; call("ij.Prefs.set", prefsPrefix + "lastCommand" + i, commandString); } logCommand = Dialog.getCheckbox(); call("ij.Prefs.set", prefsPrefix + "logCommand", logCommand); if (exploreOptions) run("URL...", "url=https://imagemagick.org/script/"); if (commandIM != "") iMSettings = "-" + commandIM + " " + parametersIM; else if (iMSettings == "") exit("No commands entered"); run("Copy to System"); execString = execString + iMSettings + " clipboard:"; showStatus("Executing ImageMagick script"); exec(execString); if (logCommand) IJ.log(execString); wait(round(minOf(6000, maxOf(10, Image.width * Image.height * 10E-6)))); run("System Clipboard"); rename(File.getNameWithoutExtension(oTitle) + "_IM'ed"); String.copy(""); /* clear clipboard */ /* ( 8(|)) ( 8(|)) ( 8(|)) ASC Functions @@@@@:-) @@@@@:-) @@@@@:-) */ function findAppPath(appName, appEx, defaultPath){ /* v210921 1st version: appName is assumed to be the app folder name, appEx is the executable, default is the default return value v211018: assumes specific executable path stored in prefs Prints message rather than exits when app not found v211213: fixed defaultPath error v211214: Adds additional location as packaged within a Fiji/IJ distribution v220121: Changed fS line v230803: Replaced getDir with getDirectory for ImageJ 1.54g9 */ functionL = "findAppPath_v230803"; fS = File.separator; ijPath = getDirectory("imagej"); appsPath = substring(ijPath, 0, lengthOf(ijPath)-1); appsPath = substring(appsPath, 0, lastIndexOf(appsPath, fS)); appFound = false; prefsName = "asc.external.paths." + toLowerCase(appName) + "." + appEx; appPath = call("ij.Prefs.get", prefsName, defaultPath); appLoc = ""+fS+appName+fS+appEx; cProg = "C:"+fS+"Program Files"; defAppPaths = newArray(cProg+fS+"Utilities"+appLoc, cProg+" \(x86\)"+fS+"Utilities"+appLoc, cProg+appLoc, cProg+" \(x86\)"+appLoc, appsPath+appLoc, ijPath+"Apps"+appLoc); if (!File.exists(appPath)){ for(i=0;i