The goal for 0.3 release was to have all the other formats other than the JPEG and JPG(already working) to resize, I found a open source command line program called imageMagick that can do the resizing.
Now the mission is to ship the small program with the addon and get the images attached in the email to run through this command line program.
The resizing syntax for imageMagick is as follows:
convert.exe source.jpg -resize 600×600 target.jpg
Now to do the same using nsIProcess, I needed the path to the convert.exe program which I had placed inside the component folder of the addon, here is how I got the path:
var getPath = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get(“ProfD”, Components.interfaces.nsIFile);
getPath.append(“extensions”);
getPath.append(id);
getPath.append(“components”);
getPath.append(“convert.exe”);
var path = getPath.path;
Next before getting the nsILocalFile using this path, we must change all instances of slash \ to double slash \\. Very Important step, learnt it the hard way.
path = convertpath.replace(/\\/g,”\\\\”);
// create an nsILocalFile for the executable
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(path);
// create an nsIProcess
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(file);
After this all I needed to do is call run the process with the appropriate arguments:
process.run(false, args, args.length);
The issue that was happeneing here was the paths. The source and destination images need to have the absolute filenames else the resizing does not work. That took me some time to get running, but I think now I have got it working. The complete code will be released soon in 0.3 await it, little more polishing is needed.