layer.resize
I'm writing a script to Trim an Image record the current width, calculate new width and increase in the image. Here is the code below, but have issues in the layer.resize. Anyone know, whats the problem?
// 1° Determinar pasta fonte das imagens
var sourceFolder = Folder.selectDialog("Select the source folder");
// 2° Determinar pasta no qual receberá novas imagens
var destinationFolder = Folder.selectDialog("Select the destination folder");
// Get all files in the source folder
var files = sourceFolder.getFiles();
// Loop over all files
for (var i = 0; i < files.length; i++) {
// Open the file
var doc = app.open(files[i]);
// 3° Desbloquear o cadeado, transformando em camada
var layer = doc.activeLayer;
layer.blendMode = BlendMode.NORMAL;
layer.opacity = 100;
// 4° Aparar imagem
doc.trim(TrimType.TOPLEFT, true, true, true, true);
// 5° Determinando o maior lado da imagem
var longestSide = Math.max(layer.width, layer.height);
var scaleFactor = (1200 / longestSide)*100
// 6° Alterar tela de pintura 1200x1200
doc.resizeCanvas(1200, 1200, AnchorPosition.MIDDLECENTER);
// 7° CRTL+T (Transformação livre alterando a imagem para o novo tamanho calculado
layer.resize(newWidth, newHeight, AnchorPosition.MIDDLECENTER);
})();
;
// 8° Save as imagem
var saveFile = new File(destinationFolder + "/" + files[i].name);
doc.saveAs(saveFile, SaveOptions.PNG);
// 9° Fechar a imagem
doc.close(SaveOptions.DONOTSAVECHANGES);
}
