This is a discussion on Photoshop scripts for centering a layer content!! within the Web Design Help forums, part of the Web Development category; As the name implies, this script simply centers the active layer within the document, both vertically and horizontally. 1. copy ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| As the name implies, this script simply centers the active layer within the document, both vertically and horizontally. 1. copy the below code in a notepad. 2. For PS CS2 and CS3, save the file with Center Layer 1-0-2.jsx extension. If you are using PS CS then Center Layer 1-0-2.js 3. Copy the file into your "Adobe Photoshop CS#/Presets/Scripts" folder. 4. Restart Photoshop, the script should appear in the File » Scripts menu. // Author: Trevor Morris (trevor@morris-photographics.com) // ================================================== ========================== // Installation: // 1. Place script in 'C:\Program Files\Adobe\Adobe Photoshop CS2\Presets\Scripts\' // 2. Restart Photoshop // 3. Choose File > Scripts > Center Layer // ================================================== ========================== // enable double-clicking from Mac Finder or Windows Explorer #target photoshop // this command only works in Photoshop CS2 and higher // bring application forward for double-click events app.bringToFront(); // main function function centerLayer() { // ensure that there is at least one document open if (!documents.length) { alert('There are no documents open.'); return; // quit } // check for background layer, groups, etc. if (checkInitialConditions()) { // declare global variables var docRef = app.activeDocument; var layerRef = docRef.activeLayer; // set document resolution to 72ppi (required due to a script bug in Photoshop) var docRes = activeDocument.resolution; docRef.resizeImage(undefined, undefined, 72, ResampleMethod.NONE); var allLocked = activeDocument.activeLayer.allLocked; // remember layer's lock state var posLocked = activeDocument.activeLayer.positionLocked; // remember layer's lock state activeDocument.activeLayer.allLocked = false; // unlock layer activeDocument.activeLayer.positionLocked = false; // unlock layer position var docWidth = docRef.width; var docHeight = docRef.height; // NOTE: both width and height will be off by +2px for shape layers var layerWidth = layerRef.bounds[2] - layerRef.bounds[0]; var layerHeight = layerRef.bounds[3] - layerRef.bounds[1]; var deltaX = (docWidth - layerWidth)/2 - layerRef.bounds[0]; var deltaY = (docHeight - layerHeight)/2 - layerRef.bounds[1]; layerRef.translate(deltaX, deltaY); // centers the active layer // restore document's original resolution (required due to a bug) docRef.resizeImage(undefined, undefined, docRes, ResampleMethod.NONE); // restore layer's original lock state layerRef.allLocked = allLocked; layerRef.positionLocked = posLocked; } } // check background layer, groups, etc. function checkInitialConditions() { // check if Background layer is selected if (activeDocument.activeLayer.isBackgroundLayer) { alert('The Background layer cannot be centered.\nPlease select another layer and try again.'); return false; // quit } // check to see if the current layer contains any artwork else if (activeDocument.activeLayer.bounds[0] == activeDocument.activeLayer.bounds[2]) { alert('The current layer contains no artwork.\nPlease select another layer and try again.'); return false; // quit } // check to see if a group is currently selected else if (activeDocument.activeLayer.typename == "LayerSet" && !confirm('Are you sure you want to center the entire group?')) { return false; // quit } // if all above conditions are met, proceed with main function else { return true; // continue } } centerLayer(); ================================================== ===
__________________ Cheers!!!
|
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Keyboard short cuts of PhotoShop CS2 | PixelNameVj | Web Design Help | 1 | 07-30-2007 10:34 AM |
| Photoshop Background's Magix | PixelNameVj | Web Design Help | 0 | 07-13-2007 12:27 AM |
| Follow Up:: Introduction to Scripts and Actions Events Manager in Photoshop CS2 | PixelNameVj | Web Design Help | 0 | 07-11-2007 03:26 AM |
| Introduction to Scripts and Actions Events Manager in Photoshop CS2 | PixelNameVj | Web Design Help | 0 | 07-11-2007 03:17 AM |
| GUI Scripts and VU scripts | vigneshgets | Software Testing | 0 | 05-22-2007 08:22 AM |