How do I crop a percentage from the edges of an image?

I'm using a batch crop and straighten script to separate scanned photos, but there is always a little bit where the crop hasn't been performed perfectly. I'd like to find a way to crop 1-2% off all edges of my document/image. I'm not worried about loosing image integrity. Would be nice to have a script to add to my existing script. Essentially this step will make my edges crisp and eliminate any slivers of white space or bent corners.
Here is the script that I'm using to divide my scanned photos:
#target Photoshop 
app.bringToFront; 
var inFolder = Folder.selectDialog("Please select folder to process");  
if(inFolder != null){ 
var fileList = inFolder.getFiles(/\.(jpg|tif|psd|)$/i); 
var outfolder = new Folder(decodeURI(inFolder) + "/Edited"); 
if (outfolder.exists == false) outfolder.create(); 
for(var a = 0 ;a < fileList.length; a++){ 
  if(fileList[a] instanceof File){ 
    var doc= open(fileList[a]); 
    doc.flatten(); 
    var docname = fileList[a].name.slice(0,-4); 
    CropStraighten(); 
    doc.close(SaveOptions.DONOTSAVECHANGES);  
    var count = 1; 
    while(app.documents.length){ 
      var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".jpg"); 
      SaveJPEG(saveFile, 12); 
      activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;  
      count++; 
function CropStraighten() { 
executeAction( stringIDToTypeID('CropPhotosAuto0001'), undefined, DialogModes.NO ); 
function SaveJPEG(saveFile, jpegQuality){ 
jpgSaveOptions = new JPEGSaveOptions(); 
jpgSaveOptions.embedColorProfile = true; 
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 
jpgSaveOptions.matte = MatteType.NONE; 
jpgSaveOptions.quality = jpegQuality;  
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE); 
function zeroPad(n, s) {  
n = n.toString();  
while (n.length < s) n = '0' + n;  
return n;  
Message was edited by: Jeremy Klein

Hmm...not sure what is going on. It seems to do something if the percentage is higher than .1, but nothing below that. It is doing some strange things, treating some images, but disregarding others.
Thanks for all your help. I can close this thread. I don't want to take up any more of your time and I can always use an automated script to do the process, it just takes longer.
Here's is my last version of the code:
#target Photoshop
app.bringToFront;
var inFolder = Folder.selectDialog("Please select folder to process"); 
if(inFolder != null){
  var fileList = inFolder.getFiles(/\.(jpg|tif|psd|)$/i);
  var outfolder = new Folder(decodeURI(inFolder) + "/Edited");
  if (outfolder.exists == false) outfolder.create();
  for(var a = 0 ;a < fileList.length; a++){
    if(fileList[a] instanceof File){
      var doc= open(fileList[a]);
      doc.flatten();
      var docname = fileList[a].name.slice(0,-4);
      CropStraighten();
      doc.close(SaveOptions.DONOTSAVECHANGES); 
      var count = 1;
      while(app.documents.length){
        cropPercentage(0.02);
        var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".jpg");
        SaveJPEG(saveFile, 12);
        activeDocument.close(SaveOptions.DONOTSAVECHANGES) ; 
        count++;
function CropStraighten() {
  executeAction( stringIDToTypeID('CropPhotosAuto0001'), undefined, DialogModes.NO );
function cropPercentage(ratio) {
  if (app.documents.length > 0 && ratio < 0.5) {
    var doc = app.activeDocument
    var crop_w = Math.floor(doc.width*ratio + 0.5)
    var crop_h = Math.floor(doc.height*ratio + 0.5)
    doc.crop(new Array(crop_w, crop_h, doc.width-crop_w, doc.height-crop_h))
function SaveJPEG(saveFile, jpegQuality){
  jpgSaveOptions = new JPEGSaveOptions();
  jpgSaveOptions.embedColorProfile = true;
  jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
  jpgSaveOptions.matte = MatteType.NONE;
  jpgSaveOptions.quality = jpegQuality; 
  activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
function zeroPad(n, s){ 
  n = n.toString(); 
  while (n.length < s) n = '0' + n; 
  return n; 

Similar Messages

  • How can I make different catalogs from the same image

    How can I make different catalogs from the same image where that image has been changed in some way between the catalogs. For instance if I wanted to have a catalogs for cropped images and have 3 catalogs one for 4x6 , 5x7 and 8x10 cropping. When I tried this , if I changed a file in one catalog that same image in the other would change also.

    Do not confuse the creation of the crops and the display in collections per crop ratio.
    Of course one virtual copy (VC) per crop ratio is needed. If the same image should be cropped in all 3 mentioned ratios there would be 3 VCs.
    The OP asked how to have/see a set of same-crop-ratios.
    After having created the virtual copies for whatever crop ratio he wants, the way to display this result in the fashion asked for is via smart collections, provided they can be found. Without a plugin the naming of the VC with the crop ratio applied is a straight way to achieve that.
    IF the wish is to get new crops automatically added. (See my answers 2+3)
    IF the wish is to creat static collections per crop ratio for a certain set of images, I'd go as follows:
    1. Select all images you want to have cropped in that way,.
    2. With this selection click on the + to add another collection and fill the dialog box like this:
    Then navigate into this newly created selection and perform the 4x6 crop - according to taste individually or by synchronizing the first crop.
    Cornelia

  • Why is it that no matter how small I crop/trim a clip, the file sz is big?

    Why is it that no matter how small I crop/trim a clip, the file size is still the same size? I can crop a 20 min video down to 10 seconds and it stays at 5 gigs.

    Hi NikonGirl - as Lennart explains, only clips that you have not used any part of can be removed from the project's Media folder.
    If space is of major concern for you, what you can do when you've finished editing, is 'Share' your project to Full Quality QuickTime. This keeps your original quality but removes all of the clips or parts of clips that have been edited out. That QT file can be stored or of course used later to make a DVD.

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • How can I get all photos from the camera roll onto the photo stream so they will share between iphone and ipad?

    How can I get all photos from the camera roll, and all new pictures taken, to get on the photostream so they can share between iphone and ipad?

    When turning PhotoStream on with photos available in the Camera Roll, only photos captured by the iPhone or saved on the iPhone are placed in the PhotoStream.
    For all photos that were in the Camera Roll prior to turning PhotoStream on, import the photos with your computer and add the photos to your PhotoStream on your computer.

  • How do I delete a file from the Adobe Reader for iOS?

    How do I delete a file from the Adobe Reader for iOS?

    Read this:
    http://forums.adobe.com/thread/1012973?tstart=0

  • How do I download an app from the Mac App Store but not install it yet?

    How do I download an app from the Mac App Store but not install it yet?
    Can I simply download it and not install?
    What if the App gets updated before I download it?
    Why? Well, I am very busy and wish to install at my leisure even though I have purchased the App (required at a specific day in the month in order to appear on my business accounts).
    Thanks.

    There is a difference in what Kappy stated and what you stated. A major paid upgrade (v2.x to v3.0), yes, costs money, as it would in any other delivery stream. Updates (v3.0 to v3.1) to a a major version are free.
    Most apps sold through the Mac App Store (MAS) are the type that use the simple drag & drop installation. Those are downloaded directly to the designated apps folder and installation is done. Large pro-type apps download an installer to your Apps folder. Those you can install at your leisure. The MAS does not have a lot of apps using this type of installation.
    Be sure to always backup your MAS purchases, because there is no guarantee that the app will always be available for download in the future and it is your responsibility to archive copies.

  • How to run a Concurrent Program from the back end?

    Hi,
    How to run a Concurrent Program from the back end?
    Is it Possible to see that Concuurent Request id which we run from the back end, in the front end?
    If yes, then Please Give reply how to write the code
    Thanks in Advance,
    Bharathi.S

    This is documented in Chapter 20 of the Application Developers Guide http://download.oracle.com/docs/cd/B53825_03/current/acrobat/121devg.pdf. These MOS Docs also have some information available
    221542.1 - Sample Code for FND_SUBMIT and FND_REQUEST API's
    235359.1 - How to Launch Planning Data Pull MSCPDP using FND_REQUEST.SUBMIT_REQUEST
    HTH
    Srini

  • I have an alias of one of my external hard drives in my trash. When I click on "show original" all my external H D 's and my Mac hard drive show up. How do I delete this icon from the trash without loosing all my files?

    I have an alias of one of my external hard drives in my trash. When I tried to delete it, it showed that I was deleting 80,000 files and counting. I stopped the delete process and when I clicked on "show original" all my external H.D.'s and my Mac hard drive show up. How do I delete this alias from the trash without loosing all my files? When I tried to drag it back to the desk top, it just made a duplicate and remained in the trash. When I turned off the external H.D., the trash was then empty. Tried rebooting the computer and then turning the external hard drive back on and the alias shows up in the trash again. Much help appreciated.
    Rich

    In Finder's Menu, select Go menu>Go to Folder, and go to "/volumes". (no quotes)
    Volumes is where an alias to your hard drive ("/" at boot) is placed at startup, and where all the "mount points" for auxiliary drives are created for you to access them. This folder is normally hidden from view.
    Drives with an extra 1 on the end have a side-effect of mounting a drive with the same name as the system already think exists. Try trashing the duplicates with a 1 or 2 if there are no real files in them, and reboot.
    If it does contain data...
    http://support.apple.com/kb/TS2474

  • HT5622 We have two iphones with the same Apple ID. Since I installed iOS this morning I have started receiving all my sons texts and when I send him a text it is delivered to both of us. How can I remove my phone from the joint Apple ID and remove myself

    My son and I both have iphones with the same Apple ID. Since I installed iOS this morning I have started receiving all my sons texts and when I send him a text it is delivered to both of us. How can I remove my phone from the joint Apple ID and remove myself from finding out what he is up to during Freshers week!

    You have to use a different Apple ID for your son.
    Read this note:
    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family
    still valid for ios 7

  • I recently brought a new HP laptop and I downloaded the newly updated iTunes on it; however I have an old Aver laptop with iTunes version 10.7 on it or the one before iTunes 11 came out. How can I transfer my movies from the old version to the new one?

    I recently brought a new HP laptop and downloaded iTunes 11 on it. My old laptop which is a Acer has iTunes version 10.7, I believe. I wanted to know, How can I transfer 18 movies from the old iTunes onto my new Itunes? It only shows the most recent two movies when I look at the purchases in my account. I had a lot of moves downloaded last year from the old version and would like some assistance on how to get all those movies into my iTunes 11 library. Thank you.

    you should starting with copying the iTunes folder from your old laptop to the new one.
    the iTunes folder is in your user profile Music folder.
    it should go to the same location on the new laptop.
    Provided that you have your media, music and movies in the default location, and you sign in to your apple ID and authorize your new computer (all in iTunes)
    you should have all intact.
    Post if any problems.

  • How do I remove an app from the menubar

    I deleted an app form my lanchpad when it was requesting a password as resident on the menubar and when I try to quit it at the menubar it does not close.  How do I remove this app from the menubar?

    Command-click it and drag it out. If that doesn't work, find and run an uninstaller for that application.
    (86726)

  • How do I remove an app from the update list that is under someone else's apple id?

    How do I remove an app from the update list that is under someone else's apple id? So this way the update always fails because it asks for someone else's password. I don't have the app on my mac, it only appears in the update list. It's just annoying, because the update keeps appearing, and the reminder keeps reminding me that I should install a new update.

    You installed a hacked app, originally from the Mac App Store. It contains the receipt for a different app, downloaded using an account that you don't control. You need to identify and remove the hacked app.
    Important: The app you need to remove is not necessarily the one named in the App Store alert. For example, the App Store may prompt you to update "Angry Birds" or "Twitter," but the hacked app may be something else entirely. Don't make any assumptions about which app you're looking for. To find it, you must carry out a systematic search with Spotlight.
    1. Triple-click anywhere in the line of text below on this page to select it:
    kMDItemAppStoreHasReceipt=1
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    2. In the Finder, press command-F to open a search window, or select
    File ▹ Find
    from the menu bar. In the search window, select
    Search: This Mac
    from the row of tokens below the toolbar. Below that is a popup menu of search criteria, initially showing Kind. From that menu, select
    Other...
    A sheet will drop down. In that sheet, select
    Raw Query
    as the criterion, then click OK or press return.
    Now there will be a text box to the right of the menu of search criteria. That's where you enter the raw search query. Click in that box and paste the text you copied earlier by pressing command-V.
    4. The search window will now show all the App Store products that are installed. Compare those search results with the list of your purchases from the App Store. To see the complete list, you may need to unhide hidden purchases. If any apps were download from the App Store using other Apple ID accounts that you control, sign in to the store under each of those ID's and check the purchases.
    At least one of the apps in the Spotlight search results is not among your purchases in the App Store. Move each such item to the Trash, after quitting it if it's running. You may be prompted for your administrator password. Empty the Trash.
    Quit and relaunch the App Store. Test.
    If you find these instructions confusing, ask for an alternative method.

  • How do I move an icon from the second page of my home screen to the first page  and vice versa?

    How do I move an icon from the second page of my home screen to the first page and vice versa?

    Hold an icon down until they all wiggle.
    Drag it wherever you want it.

  • How do I receive multiple texts from the same sender, each individually?

    How do I receive multiple texts from the same sender, each individually?

    So I receive automated reminders from my job &amp; I want them to come individually. For example, one text -- time stamped 10:14 pm, then another 11:12 am, coming as separate msgs.

Maybe you are looking for

  • Host Parameter is Null Error

    So i'm trying to publish my podcast on itunes, but all i get is ''Host Parameter is Null''. The rss feed has been created following itunes instructions, and it has been 100% validated on the feed validator. If you also paste our feed manually it work

  • Delivery Date in inbound delivery doc not accurate

    Dear all, I have a question with regards to the wrong delivery date appear in our inbound delivery. Our inbound delivery is created via a message output in the outbound delivery of a standard SAP cross company stock transport order. The delivery date

  • Need more than 5 computers or link other accounts

    Firstly let me say I love Home Sharing! BUT>>>> We have a household with 5 iMac's, 2 MacBook Pro's 1 MacBook Air, 1 iMac G5, 1 Mac Mini, 3 iPhone 4,s, 3 iPad 2's, 4 iPod's, and an Apple TV. (Just your standard Apple Fanboy) Here is our problem, I hav

  • Extracting string from a file name

    Hello, I have a legacy (read: I didn't build it) SharePoint list  that includes some validation when uploading files that's giving me some trouble. Basically, our users are required to add files to a list in a certain filename format and based on the

  • New nano with 1. gen. armband...does it fit???

    I really need help on this one. Does the new 2. generation nano fit the old armbands that came in many colors? Has anyone tried it out for real? Can't find any information about it. Thanks