How to center and zoom Photoshop document window based on active layer?
Hi,
I am trying to make the script center and zoom (to specific %) the document window based on the active layer that its being processed.
In other words, i would like to achieve a similar user experience as in when you Alt + Click on a layer thumbnail and the content of that layer is then centered and zoomed to fill your whole document window.
The only difference is that when you perform the alt + click, it zooms in to around 12.5% and i would like it to be 25% zoomin, but my current script modifies multiple layers and asks me to do something for each layer so i want it to zoom in and center my view depending on which layer is being active at the moment. This latter functionality i got it, i just havent been able to achieve the center and zoom.
Right now i got this function but it doesnt seem to work properly when i call it.
If you can provide how should the funciton look like, i will appreciate it. Thanks!
function zoomInOnActiveLayer(doc, zoomFactor) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var centerX = doc.activeLayer.bounds[0].value + (doc.activeLayer.bounds[2].value - doc.activeLayer.bounds[0].value) / 2;
var centerY = doc.activeLayer.bounds[1].value + (doc.activeLayer.bounds[3].value - doc.activeLayer.bounds[1].value) / 2;
if (app.activeDocument.activeWindow) {
app.activeDocument.activeWindow.scrollCenterOnAnchor(new UnitValue(centerX, "px"), new UnitValue(centerY, "px"));
app.activeDocument.activeWindow.zoom = zoomFactor;
}
app.preferences.rulerUnits = originalRulerUnits;
}