How do I automatically scale a layer to fit a canvas while maintaining the original aspect ratio?

I'm currently tasked with reformatting 3,000 product images (thumbnail, normal, and large sizes for each) for a new online store. To do that, I'm trying to create a Photoshop (CS6) action that can automate the process as much as possible because I have a hard deadline and not a lot of time to get it all done. Where I'm running into issues is scaling the images automatically once I've used File-->Place. My canvas sizes are all square (670px X 670px, 250px X 250px, and 125px X 125px), but the product images I'm placing on the canvases are almost always rectangular with the height greater than the width at about a 2:3 ratio. I need to scale them so that the image is touching the top and bottom edges of the canvas and the width is adjusted accordingly with the image centered horizontally.
I found the program below on another thread, but it's not working exactly like I need it to. It mentions "maintain aspect ratio," but when I run it, the image I'm trying to place ends up getting stretched to fill the entire canvas rather than the width adjusting to the height once the height has reached its maximum. I have no experience with JavaScript, so I'm having a difficult time adjusting the code to meet my needs. Any help would be greatly appreciated since I am a writer who is WAY out of his comfort zone.
var maintainAspectRatio;// set to true to keep aspect ratio 
if(app.documents.length>0){ 
    app.activeDocument.suspendHistory ('Fit Layer to Canvas', 'FitLayerToCanvas('+maintainAspectRatio+')'); 
function FitLayerToCanvas( keepAspect ){// keepAspect:Boolean - optional. Default to false 
    var doc = app.activeDocument; 
    var layer = doc.activeLayer; 
    // do nothing if layer is background or locked 
    if(layer.isBackgroundLayer || layer.allLocked || layer.pixelsLocked 
                            || layer.positionLocked || layer.transparentPixelsLocked ) return; 
    // do nothing if layer is not normal artLayer or Smart Object 
    if( layer.kind != LayerKind.NORMAL && layer.kind != LayerKind.SMARTOBJECT) return; 
    // store the ruler 
    var defaultRulerUnits = app.preferences.rulerUnits; 
    app.preferences.rulerUnits = Units.PIXELS; 
    var width = doc.width.as('px'); 
    var height =doc.height.as('px'); 
    var bounds = app.activeDocument.activeLayer.bounds; 
    var layerWidth = bounds[2].as('px')-bounds[0].as('px'); 
    var layerHeight = bounds[3].as('px')-bounds[1].as('px'); 
    // move the layer so top left corner matches canvas top left corner 
    layer.translate(new UnitValue(0-layer.bounds[0].as('px'),'px'), new UnitValue(0-layer.bounds[1].as('px'),'px')); 
    if( !keepAspect ){ 
        // scale the layer to match canvas 
        layer.resize( (width/layerWidth)*100,(height/layerHeight)*100,AnchorPosition.TOPLEFT); 
    }else{ 
        var layerRatio = layerWidth / layerHeight; 
        var newWidth = width; 
        var newHeight = ((1.0 * width) / layerRatio); 
        if (newHeight >= height) { 
            newWidth = layerRatio * height; 
            newHeight = height; 
        var resizePercent = newWidth/layerWidth*100; 
        app.activeDocument.activeLayer.resize(resizePercent,resizePercent,AnchorPosition.TOPLEFT); 
    // restore the ruler 
    app.preferences.rulerUnits = defaultRulerUnits; 

Hum Im not sure Im getting you here… Have you looked at Image Processor…?
Why are you NOT just using Fit Image and canvas size in your actions…?
These are all built-in to Photoshop.
If you wanted to do all 3 sizes in the 1 fly-bye then use script to process…
If you need extra file naming conventions then script would probably be best…
All of the above should have NO trouble handling your 3k files…

Similar Messages

  • How can I automatically close a dialog box using Javascript after I click the OK button to submit it?

    How can I automatically close a dialog box using Javascript after I click the OK button to submit it? I don't want to have to X out of the dialog box after I am done.
    Thanks
    Linda

    JS can not interact with open dialogs in any way, unless it's a dialog
    created in JS using the Dialog object.
    On Thu, Jul 24, 2014 at 11:13 PM, lindaeliseruble <[email protected]>

  • My wife and I share a computer for our itunes accounts. How can we copy our music libraries to each others accounts without erasing the original library? We want to merge our songs.

    My wife and I share a computer for our itunes accounts. How can we copy our music libraries to each others accounts without erasing the original library? We want to merge our songs.

    If the music is on the same computer, import the songs to your iTunes library by dragging them into iTunes or choosing File > Add to Library (Mac) or File > Add File to Library or Add Folder to Library (Windows).  If the music is on different computers you can set up Home Sharing to copy the music from one library to the other (see http://support.apple.com/kb/HT3819 and http://support.apple.com/kb/HT4620).

  • How can I relocate songs from my Itunes? Itunes tells me that the original files can not be found! can someone help?

    How can I relocate songs from my Itunes? Itunes tells me that the original files can not be found! can someone help?

    punzete wrote:
    I can't do it that way. I erase these songs from the iTunes Library, but when I sycronize the iPhone, all these songs are copied again to the Library. Isn't there any way to stop that? Everything I buy on iTunes Store through my iPhone cannot be erased from the iPhone?
    WHY can't you do it the way 100 million people do it?

  • How to keep original aspect ratio when cropping in Camera Raw?

    How to keep original aspect ratio when cropping in Camera Raw? Cant figure it out! With shift, the aspect ratio is 1:1. But I didnt set it to 1:1 (I checked "normal").

    The Shift key works once you’ve set your crop ratio.  DSLRs would typically do 2:3 and others sometimes do 3:4.

  • HT4972 how to remove jailbreak from my iphone4 (5.1)? .. i want the original setting like a new iphone..please tell?

    how to remove jailbreak from my iphone4 (5.1)? .. i want the original setting like a new iphone..please tell?

    To do this you will have to do a restore using iTunes but since you are on ios 5.1 you should just update to 5.1.1 in itunes. Warning this will remove the jailbreak

  • [Forum FAQ] How do I restore the CDC enabled database backups (FULL + DIFF) while maintaining the CDC integrity

    Question
    Background: When restoring Full + DIFF backups of a Change Data Capture (CDC) enabled database to a different SQL server, the CDC integrity is not being maintained. We did RESTORE the databases with the KEEP_CDC option.
    How do I successfully restore the CDC enabled database backups (FULL + DIFF) while maintaining the CDC integrity?
    Answer
    When restoring a CDC enabled database on a different machine that is running SQL Server, besides using use the KEEP_CDC option to retain all the CDC metadata, you also need to add Capture and Cleanup jobs. 
    In addition, as you want to restore FULL + DIFF backups of a CDC enabled database, you need to note that the KEEP_CDC and NoRecovery options are incompatible. Use the KEEP_CDC option only when you are completing the recovery. I made a test to display
    the whole process that how to restore the CDC enabled database backups (FULL + DIFF) on a different machine.
    Create a database named ’CDCTest’ in SQL Server 2012, then enable the CDC feature and take full+ differential backups of the database.
    -- Create database CDCTest
    CREATE DATABASE [CDCTest] ON  PRIMARY
    ( NAME = N'CDCTest ', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\ CDCTest.mdf' , SIZE = 5120KB ,
    MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
     LOG ON
    ( NAME = N'CDCTest _log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\ CDCTest _log.LDF' , SIZE = 3840KB ,
    MAXSIZE = 2048GB , FILEGROWTH = 10%)
    GO
    use CDCTest;
    go
    -- creating table
    create table Customer
    custID int constraint PK_Employee primary key Identity(1,1)
    ,custName varchar(20)
    --Enabling CDC on CDCTest database
    USE CDCTest
    GO
    EXEC sys.sp_cdc_enable_db
    --Enabling CDC on Customer table
    USE CDCTest
    GO
    EXEC sys.sp_cdc_enable_table
    @source_schema = N'dbo',
    @source_name = N'Customer',
    @role_name = NULL
    GO
    --Inserting values in customer table
    insert into Customer values('Mike'),('Linda')
    -- Querying CDC table to get the changes
    select * from cdc.dbo_customer_CT
    --Taking full database backup
    backup database CDCTest to disk = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\ CDCTest.bak'
    insert into Customer values('David'),('Jane')
    -- Querying CDC table to get the changes
    select * from cdc.dbo_customer_CT
    --Taking differential database backup
    BACKUP DATABASE CDCTest TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\ CDCTestdif.bak' WITH DIFFERENTIAL
    GO
    Restore Full backup of the ‘CDCTest’ database with using KEEP_CDC option in a different server that is running SQL Server 2014.
    Use master
    Go
    --restore full database backup
    restore database CDCTest from disk = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup\CDCTest.bak' with keep_cdc
    Restore Diff backup of the ‘CDCTest’ database.
    Restore Database CDCTest From Disk = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup\CDCTest.bak'
        With Move 'CDCTest' To 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA\CDCTest.mdf',
            Move 'CDCTest _log' To 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA\CDCTest _log.LDF',
            Replace,
            NoRecovery;
    Go
    --restore differential database backup
    restore database CDCTest from disk = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup\CDCTestdif.bak' with keep_cdc
    Add the Capture and Cleanup jobs in the CDCTest database.
    --add the Capture and Cleanup jobs
    Use CDCTest
    exec sys.sp_cdc_add_job 'capture'
    GO
    exec sys.sp_cdc_add_job 'cleanup'
    GO
    insert into Customer values('TEST'),('TEST1')
    -- Querying CDC table to get the changes
    select * from cdc.dbo_customer_CT
    Reference
    Track Data Changes (SQL Server)
    Restoring a SQL Server database that uses Change Data Capture
    Applies to
    SQL Server 2014
    SQL Server 2012
    SQL Server 2008 R2
    SQL Server 2008
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Question
    Background: When restoring Full + DIFF backups of a Change Data Capture (CDC) enabled database to a different SQL server, the CDC integrity is not being maintained. We did RESTORE the databases with the KEEP_CDC option.
    How do I successfully restore the CDC enabled database backups (FULL + DIFF) while maintaining the CDC integrity?
    Answer
    When restoring a CDC enabled database on a different machine that is running SQL Server, besides using use the KEEP_CDC option to retain all the CDC metadata, you also need to add Capture and Cleanup jobs. 
    In addition, as you want to restore FULL + DIFF backups of a CDC enabled database, you need to note that the KEEP_CDC and NoRecovery options are incompatible. Use the KEEP_CDC option only when you are completing the recovery. I made a test to display
    the whole process that how to restore the CDC enabled database backups (FULL + DIFF) on a different machine.
    Create a database named ’CDCTest’ in SQL Server 2012, then enable the CDC feature and take full+ differential backups of the database.
    -- Create database CDCTest
    CREATE DATABASE [CDCTest] ON  PRIMARY
    ( NAME = N'CDCTest ', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\ CDCTest.mdf' , SIZE = 5120KB ,
    MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
     LOG ON
    ( NAME = N'CDCTest _log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\ CDCTest _log.LDF' , SIZE = 3840KB ,
    MAXSIZE = 2048GB , FILEGROWTH = 10%)
    GO
    use CDCTest;
    go
    -- creating table
    create table Customer
    custID int constraint PK_Employee primary key Identity(1,1)
    ,custName varchar(20)
    --Enabling CDC on CDCTest database
    USE CDCTest
    GO
    EXEC sys.sp_cdc_enable_db
    --Enabling CDC on Customer table
    USE CDCTest
    GO
    EXEC sys.sp_cdc_enable_table
    @source_schema = N'dbo',
    @source_name = N'Customer',
    @role_name = NULL
    GO
    --Inserting values in customer table
    insert into Customer values('Mike'),('Linda')
    -- Querying CDC table to get the changes
    select * from cdc.dbo_customer_CT
    --Taking full database backup
    backup database CDCTest to disk = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\ CDCTest.bak'
    insert into Customer values('David'),('Jane')
    -- Querying CDC table to get the changes
    select * from cdc.dbo_customer_CT
    --Taking differential database backup
    BACKUP DATABASE CDCTest TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\ CDCTestdif.bak' WITH DIFFERENTIAL
    GO
    Restore Full backup of the ‘CDCTest’ database with using KEEP_CDC option in a different server that is running SQL Server 2014.
    Use master
    Go
    --restore full database backup
    restore database CDCTest from disk = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup\CDCTest.bak' with keep_cdc
    Restore Diff backup of the ‘CDCTest’ database.
    Restore Database CDCTest From Disk = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup\CDCTest.bak'
        With Move 'CDCTest' To 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA\CDCTest.mdf',
            Move 'CDCTest _log' To 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA\CDCTest _log.LDF',
            Replace,
            NoRecovery;
    Go
    --restore differential database backup
    restore database CDCTest from disk = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup\CDCTestdif.bak' with keep_cdc
    Add the Capture and Cleanup jobs in the CDCTest database.
    --add the Capture and Cleanup jobs
    Use CDCTest
    exec sys.sp_cdc_add_job 'capture'
    GO
    exec sys.sp_cdc_add_job 'cleanup'
    GO
    insert into Customer values('TEST'),('TEST1')
    -- Querying CDC table to get the changes
    select * from cdc.dbo_customer_CT
    Reference
    Track Data Changes (SQL Server)
    Restoring a SQL Server database that uses Change Data Capture
    Applies to
    SQL Server 2014
    SQL Server 2012
    SQL Server 2008 R2
    SQL Server 2008
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

  • How can I automatically have a new tab always be a copy of the current active tab?

    The add-on extension "NewTabURL" (by "sogame") provided the option I want and used for a number of years. But it stopped working when Firefox was updated to version 16.0. When I click for a new tab, all I get is a completely blank tab. How can I automatically have the new tab always be a copy of the current active tab?
    Can the extension "NewTabURL" be revised to work in version 16 and/or version 17? If not, how else can I get the new tab functionality that I desire? I can't seem to find any other extension that provides that functionality.
    Milt Beychok

    My trackball has 4 buttons and a scroll wheel. Each of the 4 buttons is programmable. The 4 buttons are normally pre-programmed for single-click, double-click, drag and right-click by simply pressing on them
    Each of the 4 buttons may be programmed to also have other functions. For example, I programmed "control/single-click" to produce a middle click. I could also have used "shift/single-click" or "alt/single-click" to produce the middle-click. Or I could have similarly programmed double-click or drag or right-click. The Kensington Expert Mouse is quite versatile ... once you get the hang of programming it.
    I have had it for about 4 years and I had never had the need to program one of them until you told me about using a middle-click.
    Milt Beychok

  • How do I automatically insert a file's filename in a header in the file?

    The newest version of NUMBERS seems to have lost the function for inserting a filename into the header of a printed document.  Any suggestions?

    I miss that feature too. A workaround would be to Command-Click the document name in the Print Preview window and select the second line in the file path that is displayed. That will cause a Finder Window to open, with the current Numbers file highlighted. Click once on the highlighted document name, Command-C to Copy, Click back on the Numbers window and click in the Header field and Command-V to Paste.
    This avoids all typing into the header, but the result is just a piece of text, not an object that will automatically update. It seems that if we want all the functionality of iWork '09, we must choose to use iWork '09.
    Jerry

  • How can I duplicate a smart object and then edit it, without affecting the original?

    I have a vector element from illustrator that I am placing in a tshirt mockup in photoshop. I have the layout essentially how I would like, but I am trying different color variations. I would think to just duplicate the first placement and then edit the color of the resulting copy, but this affects both the copy and the original. I looked into it a bit further, and found that I should try the "replace contents" option under smart objects, and that this would change the copy. So I go back to illustrator, made a copy of the original vector, and then made the color change I had in mind, and then saved it as a separate document that I could then use in replacing the contents of the copied. This however, is still affecting both smart objects!
    I have tried this as both linked smart objects and embedded smart objects without success.
    Ultimately, I simply want to maintain the position of the original layer with the duplicated and edited layers. If you know of a better way, please share!

    I'm on CC on a Mac.
    What 21 is talking about is making some sense.
    I am able to create new smart object via copy, then create a variation on the original file linked in the parent smart object. Then I save that from illustrator with a different file name. Then I go back to photoshop and replace contents of the new smart object, linking it to the newer illustrator file.
    This gets around the problem, but it takes a few more steps than the same thing did it in earlier versions of photoshop.

  • How do I sync my iPhone 4s with a different computer other than the original one that I used initally?

    How do I change computers for syncing my iPhone 4s?  The original laptop that I used to sync with died and I can not get my iPhone to sync with my desktop.

    can't if you do not have access to the old library (the usual workaround is to backup the old library and import it to the new itunes)
    for important data...
    sync your existing contacts with icloud, your text messages will not be disrupted, music will sync with whatever music you have on your new itunes, photos shoud still be in the camera roll (I would sync them to photostream before you sync, just in case).   Any photos on your phone that are not in camera roll or photostream... if you lost those pictures with the computer crash I would take screen shots (lock button + home button at the same time) of each photo so they show up in the camera roll.  App data may or may not be lost.  In my experience, it depends on the app.  Some of the apps recognize your apple ID and sync data over the internet with servers, some do not.  I would take note of important data (such as passwords in a password keeper if you have such an app) just in case if you lose that data.

  • How do I reactivate and install Adobe Acrobat on a new computer without the original disk?

    I am moving to a new computer and the Acrobat disk I used to have got lost somewhere in the office environment... so, how do I deactivate Acrobat on my old computer and activate/install it ion my new computer without the original disk?

    If you were using the same serial number then, yes. You are only allowed two installs and they should be on computers used by the licensee (you).
    You would need to deactivate on any additional computers if this is the case.
    Just an FYI, you are in the Adobe Reader forum. If this doesn't work, you'll want to head to the Acrobat forum where you'll find more experienced users.
    Acrobat
    Good luck.

  • How start your projects? (and maintain the original format)

    Hi!
    This is my question, exist a "better way" for start a good and clean project in Indesign?
    For example, a common case:
    -The writer send me a word file
    -I use command PLACE for import the word file
    - I maintain the format (cursives, bolds, etc.)
    -In ID i delete the "paragraph styles" and the "character styles" of Word but i preserv the "aparence".
    In this case, this is my problem, i create a Paragraph Style (Arial regular 12, black) and i apply to a paragraph:
    This is my message in the bottle
    So, change to Arial...etc...erasing the cursives and bolds:
    This is my message in the bottle
    ¿How maintain  the cursives and bold when i applied a style?
    Thanks

    I think you'll find this thread helpful: http://forums.adobe.com/thread/429756
    The scripts mentioned shold work in CS4 or CS5.

  • How do I save an enlargement of a photo on i photo from the original?

    I want to save an enlargement of a photo on i photo from the original but don't know how.

    That is done with cropping - crop to show the desired area and click Done - the cropped ("enlarged") image is saved
    LN

  • Images, JFS, CSS - How to display the correct aspect ratio

    Hello,
    This is not really related to Jave ServerFaces, however, since I am using JSF to build my application, I thought I would post it here.
    I am trying to display images by using the following tag
    <h:graphicImage style="height:200;width:140;border-width: 0;"
    value="img/#{group.items[1].picFileName}-s.jpg"
    alt="#{mainMenuController.item.customerFacingName}"/>The above tag is doing what it is supposed to do, that is display an image with height: 200 and width: 140, which is equal to the aspect ratio
    of 1.43 (=200/143).
    However, some of the images that I want to display, do not have
    the aspect ratio of 1.43. As a result of that, their height or width is modified according to the above values. This distorts some of the imsage.
    I was wondering if some one else had faced that problem and solved it. One solution that can work is to edit the images to produce an aspect ratio of 1.43, however, editing the individual images is not feasible.
    One probable solution that comes to mind is via CSS: that is by FLOATing the image in a box of fixed height and width. By doing this, the aspect ratio of the image will not be affected. I do not know if FLOATing an image in a box is possible or not. I do not know how to float an image in a box.
    More over, I am using Tiles to control the layout. Defining an image box within a <DIV> tag might complicate things.
    Any ideas, comment, suggestion will be heplful!
    Rauf

    Put the post in a HTML/CSS forum....

Maybe you are looking for

  • How can I move pages around in an iPhoto book?

    Is there a way to move the pages around in an almost completed iBook?

  • How to execute Script logic file

    Hi, I want to execute a "stand alone" scipt logic file only once. Simply spoken, the script should write some members from application A to application B (I would set the scope for the members that are concerned in the script itself) once. Is there a

  • Working With A Result Set

    Hi Everybody, I'm working on a application with will retrive data from a database for the past seven days, and then find the average for each of the days, the database is basically (id,date,hour,houraverage) - I can connect to the databse okay, but t

  • Error 22: Window does not have a constructor.

    Hi I am getting the following error message when I try to run scripts in PSE11, including the PSE scripts like PhotoMerge. I have tried reseting my preferences, rebooting my mac, rebuilding the db3 file, and reinstalling the action. None have worked.

  • Safari 7.1 does not open on macbook pro

    After updating Safari 7.1, I can not open the app.  Click on Safari icon and nothing happens. I have OS X 10.9.5 installed on Oct 3rd.