TemporaryFile tempTargetFile = new TemporaryFile(targetFileName, null, WGFactory.getTempDir());
tempTargetFile.deleteOnEviction(doc.getDatabase().getSessionContext());
File targetFile = tempTargetFile.getFile();
ImageScaler scaler = TMLContext.getThreadMainContext().createimagescaler(file);
scaler.useJPEGForOutput();
scaler.setQuality(fCompression.floatValue());
scaler.scaleToSize(Integer.parseInt(width), Integer.parseInt(height), new Boolean(keepRatio).booleanValue());
// Write scaled image to target file
scaler.writeImage(targetFile);
doc.attachFile(targetFile);
}