Rescale text layer to concrete bounds
Hi, I'm working on a script that replace the text of a concrete layer. I want to replace the text, and rescale a move it in order to fit it into a concrete bounds, and center the text in the middle of the canvas. I tryed this:
function rescaleText(doc, layer) {
var textMargins = 100;
var w = doc.width;
var margins = {left: textMargins, right: w - textMargins};
var newScale = ((margins.right-margins.left)/(layer.bounds[2]-layer.bounds[0]))*100
layer.resize(newScale, newScale ,AnchorPosition.MIDDLECENTER);
}
It rescales correctly, but I can't center the text in the middle of the document. Is there any workarround to do that?