coding UTF-8; // Specify character encoding (prevents garbled text) import Graphics; // Import the graphics library for image processing import File; // Import the file system library for file and folder operations import Text; // Import the text processing library for string manipulation // Default paths for input/output folders const string DEFAULT_INPUT_DIRECTORY = "./input"; const string DEFAULT_OUTPUT_DIRECTORY = "./output"; // Get RGB values of the color to make transparent (input is requested before main() runs) int fromRed = input("Red value of the color to make transparent (0-255)?", "0"); // Red component int fromGreen = input("Green value of the color to make transparent (0-255)?", "255"); // Blue component int fromBlue = input("Blue value of the color to make transparent (0-255)?", "0"); // Green component int fromAlpha = 255; // Alpha of the original color (0 = transparent, 255 = opaque) // Define the replacement color (change here if you want something other than transparency) int toRed = 0; // Red component int toGreen = 0; // Blue component int toBlue = 0; // Green component int toAlpha = 0; // Alpha (0 = transparent, 255 = opaque) // ====================================================================== // Main process - This function is automatically called on startup // ====================================================================== void main () { // Prepare full paths for input and output folders string inputDirectoryPath = getFilePath(DEFAULT_INPUT_DIRECTORY); string outputDirectoryPath = getFilePath(DEFAULT_OUTPUT_DIRECTORY); // Ask the user if they want to specify input/output folders; if yes, get the paths if (confirm("Would you like to specify input/output folders? (Click 'No' to use defaults)")) { inputDirectoryPath = choose("Select input folder", "."); outputDirectoryPath = choose("Select output folder", "."); } // Process all files in the input folder and save them to the output folder processAllFiles(inputDirectoryPath, outputDirectoryPath); // Show completion message to the user popup("Done! Please check the file list on screen and close the window."); } // ====================================================================== // Function that scans and processes all files in the folder // ====================================================================== void processAllFiles(string inputDirectoryPath, string outputDirectoryPath) { // Get list of file names and file count in the input folder string fileNames[] = listDirectory(inputDirectoryPath); int fileN = length(fileNames); // Process each file in the input folder for (int i=0; i OUTPUT: " + outputFilePath); // Run the transparency process processFile(inputFilePath, outputFilePath); } } } // ====================================================================== // Function to process a single image file and save the result // ====================================================================== void processFile(string inputFilePath, string outputFilePath) { // Create a graphics resource from the input image file int inputGraphics = newGraphics(inputFilePath); // Create a new graphics resource with the specified color converted int outputGraphics = newGraphics( inputGraphics, // Original image graphics resource fromRed, fromGreen, fromBlue, fromAlpha, // Color to convert (user-specified) toRed, toGreen, toBlue, toAlpha // Replacement color (transparent) ); // Save the output with a different file name exportGraphics(outputGraphics, outputFilePath, "PNG"); // Save as PNG format // Release resources deleteGraphics(inputGraphics); deleteGraphics(outputGraphics); }