Script to crop (no delete pixel) snap to ruler guide

Hi everyone,
I manually make 1 ruler guide and automatically create 3 ruler guides. These 4 ruler guide form a rectangular.
Could I have a script that crop my image (no delete pixel) to fit that rectangular formed by the 4 guides .
Thank you in advance for your help!

I had a fight scripting it. Strange thing were happing when I was testing. There seems to be a bug in scripting in cs6 -> CC 2014. Re-size layer seems to back up a history step. undoing the last step.  When I was using suspend history states I was loosing the last guide I set or the layer mask from my last test that I deleted the mask was restored and the script would fail.
http://www.mouseprints.net/old/dpr/FitImageToGuides.jsx
/* ==========================================================
// 2014  John J. McAssey (JJMack)
// ======================================================= */
// This script is supplied as is. It is provided as freeware.
// The author accepts no liability for any problems arising from its use.
/* Help Category note tag menu can be used to place script in automate menu
<javascriptresource>
<about>$$$/JavaScripts/FitImageToGuides/About=JJMack's FitImageToGuides .^r^rCopyright 2014 Mouseprints.^r^rFour and only four guides are required</about>
<category>JJMack's Script</category>
</javascriptresource>
// 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();
// ensure at least one document open
if (!documents.length) alert('There are no documents open.', 'No Document');
else {
  // declare Global variables
  main(); // at least one document exists proceed
  //app.activeDocument.suspendHistory('Fix Image to Guides','main()');  // seems to be a problem layer is resize Photoshop back up a history step ?
//                            main function                                  //
function main() {
  // declare local variables
  var orig_ruler_units = app.preferences.rulerUnits;
  var orig_type_units = app.preferences.typeUnits;
  var orig_display_dialogs = app.displayDialogs;
  app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS
  app.preferences.typeUnits = TypeUnits.POINTS;   // Set Type units to POINTS
  app.displayDialogs = DialogModes.NO; // Set Dialogs off
  try { code(); }
  // display error message if something goes wrong
  catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
  app.displayDialogs = orig_display_dialogs; // Reset display dialogs
  app.preferences.typeUnits  = orig_type_units; // Reset ruler units to original settings
  app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings
//                           main function end                               //
// The real code is embedded into this function so that at any point it can return //
// to the main line function to let it restore users edit environment and end      //
function code() {
  if (app.activeDocument.guides.length != 4) { alert("Four and only four Guides are required"); return; } // quit
  // get guides;
  var theVert = new Array;
  var theHor = new Array;
  for (var m = 0; m < app.activeDocument.guides.length; m++) {
  if (app.activeDocument.guides[m].direction == Direction.HORIZONTAL) {theVert.push(app.activeDocument.guides[m].coordinate)}
  else {theHor.push(app.activeDocument.guides[m].coordinate)}
  if (theHor.length != 2 || theVert.length != 2) { alert("Four Guides two vertical and two horizontal are required"); return; } // quit
  getTarget=getSelectedLayersIdx();
  if (getTarget.length!=1){ alert("The number of layers targeted is " + getTarget.length ); return; } // quit
  if (app.activeDocument.activeLayer.isBackgroundLayer ) { alert("Can not resize the background layer"); return; } // quit
  if (!app.activeDocument.activeLayer.visible ) { alert("Active layer is  not visible"); return; } // quit
  //if (hasLayerMask()) { alert("Active layer is  Masked"); return; } // quit
  if (app.activeDocument.activeLayer.kind == LayerKind.NORMAL  || app.activeDocument.activeLayer.kind == LayerKind.SMARTOBJECT && hasLayerMask()) { deleteLayerMask ();}
  if (app.activeDocument.activeLayer.kind != LayerKind.NORMAL  && app.activeDocument.activeLayer.kind != LayerKind.SMARTOBJECT )  {
  alert("Active layer is " + app.activeDocument.activeLayer.kind); return; } // quit
  // set selection to the ared defined but the guide lines the selectiom may get undone bt the bug in .resize() backing up a steo in histoty ???
  app.activeDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]);
  // resize current normal layer or smart object layer to just cover selection canvas area aspect ratio and size and mask off any overflow
  var SB = app.activeDocument.selection.bounds; // Get selection bounds
  var SWidth = (SB[2].value) - (SB[0].value); // Area width
  var SHeight = (SB[3].value) - (SB[1].value); // Area height
  var LB = app.activeDocument.activeLayer.bounds; // Get Active layers bounds
  var LWidth = (LB[2].value) - (LB[0].value); // Area width
  var LHeight = (LB[3].value) - (LB[1].value); // Area height
  var userResampleMethod = app.preferences.interpolation; // Save interpolation settings
  app.preferences.interpolation = ResampleMethod.BICUBIC; // resample interpolation bicubic
  try {
  if (LWidth/LHeight<SWidth/SHeight) { // layer's Aspect Ratio less the Canvas area Aspect Ratio
  var percentageChange = ((SWidth/LWidth)*100); // Resize to canvas area width
  app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
  else {
  var percentageChange = ((SHeight/LHeight)*100); // resize to canvas area height
  app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
  catch(e) {
  app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
  selectFront(); // Photoshop make top layer current when none are targeted
  code(); // Retry  with top visible layer selected targeted
  return; // rest would have been done during the retry
  app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
  // Seems to be a bug in  resize() the document seems to first be backed up a step in history
  app.activeDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]); // redo the selection
  align('AdCH'); // align to horizontal center
  align('AdCV'); // align to vertical center
  addLayermask(); // add layer mask
// Helper Functions
function align(method) {
  var desc = new ActionDescriptor();
  var ref = new ActionReference();
  ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
  desc.putReference( charIDToTypeID( "null" ), ref );
  desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
  try{executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );}
  catch(e){}
// Function: hasLayerMask
// Usage: see if there is a raster layer mask
// Input: <none> Must have an open document
// Return: true if there is a vector mask
function hasLayerMask() {
  var hasLayerMask = false;
  try {
  var ref = new ActionReference();
  var keyUserMaskEnabled = app.charIDToTypeID( 'UsrM' );
  ref.putProperty( app.charIDToTypeID( 'Prpr' ), keyUserMaskEnabled );
  ref.putEnumerated( app.charIDToTypeID( 'Lyr ' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) );
  var desc = executeActionGet( ref );
  if ( desc.hasKey( keyUserMaskEnabled ) ) { hasLayerMask = true; }
  catch(e) { hasLayerMask = false; }
  return hasLayerMask;
function getSelectedLayersIdx(){
      var selectedLayers = new Array;
      var ref = new ActionReference();
      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
      var desc = executeActionGet(ref);
      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
          var c = desc.count
          var selectedLayers = new Array();
          for(var i=0;i<c;i++){
            try{
               activeDocument.backgroundLayer;
               selectedLayers.push(  desc.getReference( i ).getIndex() );
            }catch(e){
               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );
       }else{
         var ref = new ActionReference();
         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
         try{
            activeDocument.backgroundLayer;
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
         }catch(e){
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
      return selectedLayers;
function selectFront() {
// Alt+. shortcut select ftont visible layer
var idslct = charIDToTypeID( "slct" );
    var desc250 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref207 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idFrnt = charIDToTypeID( "Frnt" );
        ref207.putEnumerated( idLyr, idOrdn, idFrnt );
    desc250.putReference( idnull, ref207 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc250.putBoolean( idMkVs, false );
executeAction( idslct, desc250, DialogModes.NO );
function deleteLayerMask (apply) {
// Delet Layer mask default to not apply first
if (apply == undefined) {var apply = false};
try {
var idDlt = charIDToTypeID( "Dlt " );
    var desc9 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref5 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idMsk = charIDToTypeID( "Msk " );
        ref5.putEnumerated( idChnl, idChnl, idMsk );
    desc9.putReference( idnull, ref5 );
    var idAply = charIDToTypeID( "Aply" );
    desc9.putBoolean( idAply, apply );
executeAction( idDlt, desc9, DialogModes.NO );
catch (e) {}
function addLayermask(){
// Add layer Mask
var idMk = charIDToTypeID( "Mk  " );
    var desc52 = new ActionDescriptor();
    var idNw = charIDToTypeID( "Nw  " );
    var idChnl = charIDToTypeID( "Chnl" );
    desc52.putClass( idNw, idChnl );
    var idAt = charIDToTypeID( "At  " );
        var ref19 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idMsk = charIDToTypeID( "Msk " );
        ref19.putEnumerated( idChnl, idChnl, idMsk );
    desc52.putReference( idAt, ref19 );
    var idUsng = charIDToTypeID( "Usng" );
    var idUsrM = charIDToTypeID( "UsrM" );
    var idRvlS = charIDToTypeID( "RvlS" );
    desc52.putEnumerated( idUsng, idUsrM, idRvlS );
executeAction( idMk, desc52, DialogModes.NO );
// Un link layer mask just added fron the layers content
var idsetd = charIDToTypeID( "setd" );
    var desc2 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref1.putEnumerated( idLyr, idOrdn, idTrgt );
    desc2.putReference( idnull, ref1 );
    var idT = charIDToTypeID( "T   " );
        var desc3 = new ActionDescriptor();
        var idUsrs = charIDToTypeID( "Usrs" );
        desc3.putBoolean( idUsrs, false );
    var idLyr = charIDToTypeID( "Lyr " );
    desc2.putObject( idT, idLyr, desc3 );
executeAction( idsetd, desc2, DialogModes.NO );

Similar Messages

  • Snapping to ruler guides

    Does anybody know why I can't seem to snap an edge of an object to a ruler guide.
    I figure its one of the three.
    1)A bug in CS3
    2)User error - an option is turned off someplace.
    3)Adobe never thought it.
    I am really hoping its #2. But from the help file it looks like #3. I have no problem snapping with a point. But there are times that a guide is easier than the align tools. Though I am getting more use to them all the time.
    Silk

    > I suspect it's because finding the extreme edges of a complex shape, especially a masked shape, is complex, so it's too difficult to program
    Difficult to program? It's difficult to program a bounding box, and have that bounding box snap to guides? Other programs don't seem to find that difficult.
    > the fact that Illustrator's guides respond to the mouse...is much more powerful and versatile.
    More "powerful and verstatle" than what? I certainly do not find Illustrator's snaps to be "more powerful and versatile" than FreeHand, CorelDraw, or Canvas. In fact, I often find Illustrator's snap behaviors downright unreliable unless you are working at a high zoom level.
    JET

  • Crop Tool does not snap reliably

    Still getting used to Photoshop CS5.1. I am having problems with the crop tool. It is supposed to snap to my guides, but it is very haphazard about this. Sometimes it is a pixel or 2 off on one or more edges. This means I have to pay very close attention while cropping, and double check the accuracy of results. This slows me way down. I do mostly web graphics, where pixel accurate crops are essential. I already tried resetting the crop tool. I am using a Mac Pro, early 2008, with 10 GB RAM, and Mountain Lion 10.8.1.

    I think the the Crop Tool always snaps to pixels while it is initially dragged to size. If a guide is not precisely on a pixel boundary then the Crop Tool will not initially snap exactly to the guide - it should snap to the next outward pixel boundary.
    After the initial dragging out of the crop box, slightly drag each of its sides away from the guide and back to the guide for a correct snap to the guide.
    If your guides are supposed to be on pixel boundaries then the problem may be that they are a tiny bit off and so the Crop Tool is snapping to the next pixel boundary outwards. To ensure guides snap to pixels, set the ruler to pixels and hold down Shift while dragging a guide to make it snap to ruler divisions (regardless of the rulers actually being visible or not).

  • Resizing drawing objects defies pixel snapping

    This happens mostly with drawing objects, and to a lesser degree with shapes. When resizing drawing objects in Flash CS6 with pixel snapping turned on, one would expect the dimensions of the shape to snap to even pixel numbers. For the most part it does, but too frequently the position and size values begin to drift into fractions of pixels.
    If you create a rectangle as a drawing object, no stroke, it will snap to pixels properly. Drag it around and it always lands on whole pixel values. Now try resizing it using the free transform tool, or even by clicking and dragging the position and size values in the properties panel. Width and height values will mostly stick to whole pixels, but too often it will slip into fractions of pixels, bizarrely offsetting the x and y values as well. If you resize a drawing object and this error occurs, it does not help to try and move it to snap it back onto whole pixels, because it will snap to whatever fraction of a pixel it's currently stuck in, thereby forcing the user to manually edit the object's x and y coordinates.
    This is a problem in my workflow as I'm constantly having to keep an eye on the properties panel and manually editing the numbers when shapes stray into 2.85 pixels or some such when I want it at 3. I find myself frequently just entering the numbers I want, which defeats the purpose of pixel snapping in the first place.

    This happens mostly with drawing objects, and to a lesser degree with shapes. When resizing drawing objects in Flash CS6 with pixel snapping turned on, one would expect the dimensions of the shape to snap to even pixel numbers. For the most part it does, but too frequently the position and size values begin to drift into fractions of pixels.
    If you create a rectangle as a drawing object, no stroke, it will snap to pixels properly. Drag it around and it always lands on whole pixel values. Now try resizing it using the free transform tool, or even by clicking and dragging the position and size values in the properties panel. Width and height values will mostly stick to whole pixels, but too often it will slip into fractions of pixels, bizarrely offsetting the x and y values as well. If you resize a drawing object and this error occurs, it does not help to try and move it to snap it back onto whole pixels, because it will snap to whatever fraction of a pixel it's currently stuck in, thereby forcing the user to manually edit the object's x and y coordinates.
    This is a problem in my workflow as I'm constantly having to keep an eye on the properties panel and manually editing the numbers when shapes stray into 2.85 pixels or some such when I want it at 3. I find myself frequently just entering the numbers I want, which defeats the purpose of pixel snapping in the first place.

  • Automated process to crop away certain pixels

    How can I automate the process to crop away certain pixels from the edges of a batch of pictures of different dimension?
    Example:
    Picture 1 : 400 x 600px
    Picture 2 : 360 x 480px
    Picture 3 : 600 x 800px
    I want to crop away 5px from each edge of each picture which would then end up being 390x590px, 350x470px and 590x790px respectively.

    MichaelTeoh wrote:
    I want to crop away 5px from each edge of each picture which would then end up being 390x590px, 350x470px and 590x790px respectively.
    Example:
    Picture 1 : 400 x 600px    = 400:600 = 4:6 =  2:3
    Picture 2 : 360 x 480px    = 36:48 = 6:8 = 3:4
    Picture 3 : 600 x 800px   =  3:4
    So you can record the three action to center crop your images to the 2:3 and 3:4 aspect ratios  shown in your examples then use image size to size them you three example  pixel sizes then use canvas size to to trim the 5 px of the border,  just set the canvas to you three sizes 390x590px  350x470px and 590x790px do not check relative and leave the anchor point in the center.  Five pixels will be trimmed form all sides. Any image that started with the correct 2:3 or 3:4 aspect ratios will not be cropped by the first crop only the canvas size crop will trim pixels.
    To handle both Portrait and Landscape image the action would need to record a fit image step instead of the image size step a fit image step fit to longest side need to be recorded  and the canvas size would need to be recorded to trim both width and height by a relative -10px.   My  AspectRatioSelection plugin will automatically orient the aspect ratio recorded to the images orientation.

  • Pixel Snapping in CS5.5

    I am currently making a pixelart game in Flash Professional. In the middle of development (which was probably a bad time to do it) I upgraded to CS5.5 from CS5, and the first thing I noticed was that pixel snapping wasn't how it used to be. In the old version the pixels (in movie clips) would align with the pixel grid. In the new version, however, the pixels snapped into the crossings of the grid.
    Pixel snap in CS5.
    And pixel snap in CS5.5.
    Is there an option I missed or is there a workaround for this?

    Hello
    I'm a member of the Adobe Digital Publishing Suite forum. I encountered similar behaviour several times while working on magazines with DPS. Whenever I click on an element I copied from another document, InDesign opens the parent document.
    Here is a video:
    Watch on youtube: http://www.youtube.com/watch?v=tZp1Vah2rdo
    Follow the Discussion over there (no details on that there yet): http://forums.adobe.com/thread/927707?tstart=0
    but seems connected with DPS, some other friends and clients have the same problem.
    —Johannes
    Message was edited by: Johannes Henseler (changed "same behaviour" to "similar behaviour" because it is not the same, but looks definetly related)

  • Make the Crop Tool in PSE5 snap to document bounds

    Is there a way to make the crop tool in PSE5 snap to the document bounds (which was the default behaviour in V2 and v3)?
    The grid option doesn't work, because the bottom of the image may not align to a grid line. The trick of starting outside the image, drawing past that corner and then holding CTRL to constrain the opposite edge works, but only if you're cropping to two edges of the image, and loses the snap if you try and adjust anything.
    Is there any equivalent of the "snap to document bounds" of the earlier versions?
    Thanks
    Andrew

    Hi Andrew,
    I believe I know exactly what you mean. My workaround is to make the whole photo smaller than the window I am working in (leave an inch of grey around the edges, for example). Then I click the crop tool about half-an-inch outside one corner and drag to half-an-inch (or so) beyond the opposite corner. You will then have your full picture selected right on the edges. Maybe that could work for you.
    Pat Meakin

  • How to delete the orphaned Expected Rule Entries exist in the FIM portal

    Hi,
    How to delete the orphaned Expected Rule Entries exist in the FIM portal.
    A large number of orphaned Expected Rule Entries exist in the FIM portal (originally 140000k+ objects, currently 75000+ objects). They consume the a lot of FIM database space and slows down the identity lifecycle management synchronization processes.
    Regards
    Anil Kumar

    Hello,
    in my environments i use this approach:
    https://social.technet.microsoft.com/Forums/en-US/1af6cf77-4c55-4a3e-93cc-0baae80bc88f/expiration-workflow-cannot-delete-ere?forum=ilm2
    This sets up a compination of Sets, Workflow and MPR to let the "Expiration Workflow" delete EREs as soon as they get orphaned.
    This works fine since 3 years now, even if there are comming SQL-Jobs within a FIM update, but I implemented this before this was done.
    I would suggest to clear the current orphaned EREs with PowerShell to avoid request flooding when implementing the above solution. Then implement that housecleening above.
    Regards
    Peter
    Peter Stapf - ExpertCircle GmbH - My blog:
    JustIDM.wordpress.com

  • How can I delete a fixed profile rule in a Linksys ATA?

    I have a Linksys SPA2100 ATA that I used with a previous VoIP provider. I did a factory reset but their profile rule is still listed in the first Profile Rule section under the Provisioning tab. Profile Rule B, C and D are blank and I can enter a profile rule in there but I can't delete the main profile rule because it is fixed. I can't highlight it and delete it for some reason. There must be another way to delete this profile. This is what is listed there minus the name of the provider. I attached a screen shot too. Thanks.
    Profile Rule: https://spa.act.voip.xxxxxx.com/$PN/stub.bin

    Hi billcanada,
    Take a look at your SPA2102's Voice tab > Info tab > Product Information > Customization:
    It should contain "Open"
    If not, you've got what is known as an "RC-unit" which is what we sell to many service providers allowing them to customize and lock the unit down. Given that you've got admin access, try the following [but don't be disappointed if it doesn't work]:
    1. Enable debug on the SPA2102
    2. Write a simple config file called spa2102.cfg whose contents include:
      Yes
      /spa$PSN.cfg
    3. Save the spa2012.cfg file in the root of your TFTP server
    4. Start the TFTP server
    5. Start Wireshark on the subnet to which the ATA is connected
    6. Power-cycle the ATA
    7. Once it's booted, try and force a resync of your ATA using your browser: htttp://ataIPaddress/admin/resync?tftp://ipAddrOfTftpServer/spa2102.cfg
    8. Verify with Wireshark that the ATA requested and received the /spa2102 file
    9. Use a browser to determine if your config file overwrote the grayed-out Profile_Rule in the web-UI
    Regards,
    Patrick----

  • I could not sync my new phone contacts with my laptop, and when i connect my phone with my laptop it delet my new contects, plz guide me?

    i could not sync my new phone contacts with my laptop, and when i connect my phone with my laptop it delet my new contects, plz guide me?

    Reinstall iTunes.  I had the same problem.

  • Auto delete inbox mail after rules applied

    Just moved our entire office over to Apple Mail. Working out the migration kinks now and learning the ropes. Here’s a productivity question:
    Once you set up rules to apply to incoming mail, is there any way to have the mail in the inbox automatically deleted after the applied Rules duplicate it into a folder?

    patrick1,
    Mail>Preferences...>Accounts>Mailbox Behaviors>Junk>Erase messages in the junk mailbox when: One day old...etc
    ;~)

  • Deleting a dminesion through rules file.

    Hi ,
    We have a requirement to delete dimensions , before bulding metadata ( for a BSo cube) , so can some one  assist me how to delete the dimensiont hroguh rule file.
    Thanks in advacne

    You can't delete a dimension through a rules file.  Do you mean you want to delete all members before rebuilding the same dimension or actually remove the dimension altogether?
    The only way to remove a dimension is to have a 'template' or 'stub' outline without the dimension and copy it over your real outline (probably after clearing all data).  If what you really want is to rebuild the dimension containing only the members in your source, then the 'Remove Unspecified' dimension build setting can be used.

  • How do I crop with "delete cropped pixels" unchecked in a script

    I need to use crop feature with "delete cropped pixels" unchecked in a script.  Is that possible?
    Thanks,
    Tom

    This uses the Array from a Selection, but you can also just set the numbers in the Script.
    /* 2013, use it at your own risk */
    #target photoshop
    if (app.documents.length > 0) {
    activeDocument.suspendHistory('cropping', 'main()')
    ////// the operation //////
    function main () {
    var myDocument = app.activeDocument;
    // set to pixels;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var originalResolution = myDocument.resolution;
    myDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);
    // get selection bounds;
    var theArray = myDocument.selection.bounds;
    cropImage (theArray);
    // reset;
    app.preferences.rulerUnits = originalRulerUnits;
    myDocument.resizeImage(undefined, undefined, originalResolution, ResampleMethod.NONE);
    ////// crop image //////
    function cropImage (theArray) {
    // set to pixels;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    // =======================================================
    var idCrop = charIDToTypeID( "Crop" );
        var desc7 = new ActionDescriptor();
        var idT = charIDToTypeID( "T   " );
            var desc8 = new ActionDescriptor();
            var idTop = charIDToTypeID( "Top " );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc8.putUnitDouble( idTop, idRlt, theArray[1] );
            var idLeft = charIDToTypeID( "Left" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc8.putUnitDouble( idLeft, idRlt, theArray[0] );
            var idBtom = charIDToTypeID( "Btom" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc8.putUnitDouble( idBtom, idRlt, theArray[3] );
            var idRght = charIDToTypeID( "Rght" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc8.putUnitDouble( idRght, idRlt, theArray[2] );
        var idRctn = charIDToTypeID( "Rctn" );
        desc7.putObject( idT, idRctn, desc8 );
        var idAngl = charIDToTypeID( "Angl" );
        var idAng = charIDToTypeID( "#Ang" );
        desc7.putUnitDouble( idAngl, idAng, 0.000000 );
        var idDlt = charIDToTypeID( "Dlt " );
        desc7.putBoolean( idDlt, false );
        var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
        var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
        var idunconstrained = stringIDToTypeID( "unconstrained" );
        desc7.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idunconstrained );
    executeAction( idCrop, desc7, DialogModes.NO );
    // reset;
    app.preferences.rulerUnits = originalRulerUnits;

  • How do I create a script to crop the channels within specific limits defined by me?

    Hi,
    I am trying to automate processing of my channels, but as a first step I need to crop them within specific boundaries (all data at once).
    Kindly let me know any specific script commands which would help me in doing the same.
    Solved!
    Go to Solution.

    Hi Brad_Turpin,
    I have attached a sample data with this post for your reference. In the attached file, there is one time channel (X axis) and one data channel (Y axis), and I need to crop both the channels apart from 0 to 20 sec.
    I checked the syntax for DataBlDel() which is 'Call DataBlDel(ChnNoStr, ChnRow, ValNo, [ValDelOnly])'. What I understand from this is (please correct me if I am wrong), I need to input the 'row no.' and the number of values from and to which I want to delete values from the channel data.
    But the problem for using it is that the 'row no.' and the number of values I want delete may vary when I pull in a different dataset. (i.e. If you look at the attached file you can see that for this example time channels starts from -5 to 40 sec, but for a different dataset time channel may start from -10 to 35 sec. But my requirement for the new dataset still remains same, that is from 0 to 20 sec). What should I do for this condition
    Additionally, I would also like to know the best way to crop if I am having more than one data channels (lets say, I am having 5 data channels apart from the time channel and want to crop all of them from 0 to 20 sec).
    Hope I have not confused you, please let me know for further clarification of my requirement.
    Thanks in advance.
    Regards,
    Fazil Shah.
    Attachments:
    to crop_1.zip ‏7 KB

  • Script That Crops Then Saves and Repeats?

    Hello,
    I am currently new to the scripting on Photoshop. Recently I have started to perform some very repetitive actions and was looking for alternatives to get them done. I looked around the internet for a certain script, but cannot find it. The scripts function would be the following...
    Have a set pixel ratio (2048x2048)
    Start in one of the corners
    Crop the image (Mine is currently a little more than 20,000x20,000 pixels) down to the pixel ratio
    Save that portion of the cropped image in png
    Move left or right or down (whichever is logically next)
    Repeat the process until the whole file has been saved in smaller chunks
    If anyone knows if this script exists please point me to the correct resource, this would help me so, so, so much.
    For anyone who is curious, here is the reason why I need a script that does this.
    Currently I am working on the starting stages of a very large platformer game. Currently art seems to be the most heavy task on the game. The platforming world is going to be very large and hopeful everything will be unique (as in no repeating patterns or textures). There will be two artist working on the game, myself included. I was trying to find a more efficient way of saving these very large scale files in chunks. My current file or test file is around 20,000x20,000 pixels. Doing the math to save one layer of this image in 2048 block images will take 100 repetitive save motions. Take this number times 3 for the amount of layers I need saved and it jumps up to 300. In the end the game will be somewhere around 20,000x100,000 pixels, which will just kill me if I have to do it by hand. It would take days.
    I have tried using slicing and the save for web option, but Photoshop cannot handle the large file. If there are any other methods that I can use to save a Photoshop image in 2048x2048 chunks easily, please let me know. This is a sort of make it or break it deal for the games art on whether we can make it more unique or have to use a lot of repeating patterns.

    20.000 is not the product of a multiplication of 2048 and an integer.
    I can’t remember having come across any Script that fits your needs perfectly.
    If no one else can point to one and as the task is a somewhat specific one I wonder if you should try hiring someone to do it for you (if you should not be able to accomplish it yourself).
    ps-scripts.com • Index page
    Edit:
    Does this help? (You’d need to amend the line
    if (app.documents.length > 0) {main(300, 400)};
    naturally.)
    // make crops of an image according to a specific size;
    // 2014, use at your own risk;
    #target "photoshop-70.032"
    if (app.documents.length > 0) {main(300, 400)};
    ////// function //////
    function main (width, height) {
    // set to pixels and 72ppi;
    var myDocument = app.activeDocument;
    var docName = myDocument.name;
    var basename = docName.match(/(.*)\.[^\.]+$/)[1];
    var docPath = myDocument.path;
    // change to 72ppi;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var originalResolution = myDocument.resolution;
    myDocument.resizeImage (null, null, 72, ResampleMethod.NONE);
    var theState = myDocument.activeHistoryState;
    var theCounter = 0;
    var theVert0 = 0;
    for (var n = 0; n < Math.ceil (myDocument.height / height); n++) {
    theVert0 = height * n;
    var theVert1 = theVert0 + height;
    var theHor0 = 0;
    for (var m = 0; m < Math.ceil (myDocument.width / width); m++) {
    theHor0 = width * m;
    var theHor1 = theHor0 + width;
    // crop and save copy;
    cropThis(theVert0, theHor0, theVert1, theHor1);
    saveCopyAsTif (myDocument, docPath+"/"+docName+"_"+bufferNumberWithZeros (theCounter,3)+"_hor"+bufferNumberWithZeros (m, 3)+"_ver"+bufferNumberWithZeros (n, 3)+".tif");
    myDocument.activeHistoryState = theState;
    theCounter++;
    // reset;
    app.preferences.rulerUnits = originalRulerUnits;
    myDocument.resizeImage (null, null, originalResolution, ResampleMethod.NONE);
    ////// crop //////
    function cropThis (x1, x2, x3, x4) {
    // =======================================================
    var idCrop = charIDToTypeID( "Crop" );
        var desc7 = new ActionDescriptor();
        var idT = charIDToTypeID( "T   " );
            var desc8 = new ActionDescriptor();
            var idTop = charIDToTypeID( "Top " );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc8.putUnitDouble( idTop, idRlt, x1 );
            var idLeft = charIDToTypeID( "Left" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc8.putUnitDouble( idLeft, idRlt, x2 );
            var idBtom = charIDToTypeID( "Btom" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc8.putUnitDouble( idBtom, idRlt, x3 );
            var idRght = charIDToTypeID( "Rght" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc8.putUnitDouble( idRght, idRlt, x4 );
        var idRctn = charIDToTypeID( "Rctn" );
        desc7.putObject( idT, idRctn, desc8 );
        var idAngl = charIDToTypeID( "Angl" );
        var idAng = charIDToTypeID( "#Ang" );
        desc7.putUnitDouble( idAngl, idAng, 0.000000 );
        var idDlt = charIDToTypeID( "Dlt " );
        desc7.putBoolean( idDlt, false );
        var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
        var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
        var idtargetSize = stringIDToTypeID( "targetSize" );
        desc7.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idtargetSize );
    executeAction( idCrop, desc7, DialogModes.NO );
    ////// save pdf //////
    function saveCopyAsTif (myDocument, thePath) {
    // tif options;
    tifOpts = new TiffSaveOptions();
    tifOpts.embedColorProfile = true;
    tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
    tifOpts.alphaChannels = false;
    tifOpts.byteOrder = ByteOrder.MACOS;
    tifOpts.layers = false;
    // save copy;
    myDocument.saveAs((new File(thePath)), tifOpts, true);
    ////// buffer number with zeros //////
    function bufferNumberWithZeros (number, places) {
      var theNumberString = String(number);
      for (var o = 0; o < (places - String(number).length); o++) {
      theNumberString = String("0" + theNumberString)
      return theNumberString

Maybe you are looking for

  • How To Generate Debug Log Files for ebs jsp?

    hi   How To Generate Debug Log Files for ebs r12 jsp? and where i get the log .please help me thanks!

  • My horizontal scroll bar has disappeared

    I no longer have a horizontal scroll bar at the bottom of the page. It disappeared a couple of days ago. I have not made any changes to my settings and am totally puzzled. I did try changing my persona to one I had previously used, and that made no d

  • Problem Transforming

    Hi All, I am facing a problem transforming an XML document using XSLT. I have two XML documents.One is the source document. In the XSL i refer to another XML document which is in the same folder as the source document using document() function.(My XS

  • SUBMIT inside a method & the automation queue

    Hi, I call a method via a tree toolbar button in that calls a standard SAP report using the SUBMIT AND RETURN command. This is done within a screen with several docking containers and split screens attached. The problem is that when I press the toolb

  • Can't load client application at OC4J (9.0.4) start

    I have an EJB application with a client application (set in my orion-application.xml file) that connect to a database to check username (I have my own UserManager). When I deploy my package (OC4J started), the client application is loaded correctly.