Scale a layer so that it matches the size of the image. (Automation)

I need to scale a layer so that it matches the sizeof the image.


The problem is that I need to automate this procedure and apply on a series of images with different resolutions. (That's why I can't use CTRL + T and just drag the corners of the layer to adjust the image)

The layer I need to resize is 2000 x 1500 pixels.
The images I need layer to match varies from 3000 x 2000 pixels and 5000 x 4000 pixels. (I know all about loss of quality when I step up please don't give me a lecture this).

No matter if the layer changes in proportions.

I use Photoshop CS5.

If you select the layer you want to resize, you can run the following script to do the resizing...

var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var doc = activeDocument;
var docWidth = doc.width.value;
var docHeight = doc.height.value;
var LB = doc.activeLayer.bounds;
var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value);
var LWidth = Math.abs(LB[2].value) - Math.abs(LB[0].value);
var percentageHeight = ((docHeight/LHeight)*100);
var percentageWidth = ((docWidth/LWidth)*100);
doc.activeLayer.resize(percentageWidth,percentageHeight,AnchorPosition.MIDDLECENTER);
align('AdCH');
align('AdCV');
app.preferences.typeUnits = startTypeUnits;
app.preferences.rulerUnits = startRulerUnits;
function align(method) {
app.activeDocument.selection.selectAll();
   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 ) );
   executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
  app.activeDocument.selection.deselect();
};

Tags: Photoshop

Similar Questions

  • How to configure CPU Meter so that it displays the image instead of the text version.

    How to configure CPU Meter so that it displays the image instead of the text version.

    Hi John,.

    Welcome to the Microsoft community.

    The CPU Meter gadget shows the status of the two main resources, you can follow on your computer - the use of your CPU and memory.

    To install the CPU Meter gadget in Windows 7, just right click anywhere on your desktop and click on Gadgets. Search the CPU Meter gadget and drag it to your desktop.

    See the Microsoft Article below and check if this is useful:

    http://Windows.Microsoft.com/en-us/Windows7/customize-desktop-gadgets

    Let us know if you encounter problems under windows in the future. We will be happy to help you.

  • In the program Panel, when I click the SPACEBAR (that is, 'Play'), the image does not advance.

    In the program Panel, when I click the SPACEBAR (that is, 'Play'), the image does not advance. When I click on 'Play' again once (that is, 'Stop'), the fixed image confirms that we went. Please, what should I do so that when I click the SPACEBAR (that is, 'Play'), the image does indeed move forward? Thank you!

    You send messages in the forum Business Catalyst, you should put this in the forums Adobe Premiere http://forums.adobe.com/community/premiere

  • Photoshop CC: Have a template that I transferred the image to.  The image is too small.  How to resize the image in the template?  Or I have to go to the file original image and resize here over and over again until I have found the right person?

    I have a model I am able to plug different images at different times.  The problem is when I plug an image in this template, I think that the image is either too big or too small.  Is it possible to connect the image in the template and resize the image (and not the template itself) OR I have to go into the file with the original image and resize them it there and then try to plug it into the model to see if it fits - and if it does not fit, return to the original with the image file and resize it again and see if this fits - and so on and so on...?  "" I tried the "image size" option, but it's all or nothing - especially miss!

    Thank you!

    First, make sure that the original image is larger that you need. It is easier to delete pixels that so add nonexistent pixels.

    Place the image in the template.

    In the menu filters, choose Convert to smart object. (Make sure that the image layer is selected before doing this step)

    Now reduce the size of the image of what you need (ctrl-t or cmd - t) when satisfied click return/enter.

    Because the image layer is a smart object, you can replace the inner image in another image and the scale will remain the same. You will find the option to replace the image in the layers > smart menu object.

    If you need assistance more let us know.

  • How can I change the thumbnail of the mask layer for a thumbnail of the image itself?

    Hello

    I'm in Photoshop CS5 in Windows, and I've been using Photoshop for a while now. I'm not sure what I've done, but for these days, in my palette of layers, thumbnails that appear are different.

    I have attached a small screenshot of my photoshop below. Here in 1 layer, the thumbnail at left (brush) used is that of the opening of the image and the thumbnail in the right used to be an indication of grayscale pixels that have been selected. No idea how to return back?

    layer_Mask_thumbnail.JPG

    Hi slaveofphoton,

    Go to Options from the layers panel, and choose one thumbnail size other than none.

  • Is it possible to print the chart of the sound waves that show under the images in the project window?

    I use iMovie 9.0.8 and that you want to print, or export the graphic sound waves that show under the thumbnail images in the project window. Is this possible? and if so, how?

    You can take a screenshot using the command, shift and 4 keys and drag the icon in the shape of cross on the area. When you release the mouse button, an image is saved to your desktop.

    QuickTime Player 10 allows to record the screen if you want to capture the movement.

  • Why did - he still watermark that appears on the image?

    That watermark still shows on the image?

    This can also help:

    I downloaded my 10 free images and they all have the Adobe watermark on them, so I can't use them. Why have a watermark on them?

  • Y at - it a script that will be the image draws a raster object selection?

    Hello! Here's my problem:

    I need to run Image Trace - with a specific preset - more Action on each object of a selection. So, basically, I want to run the Trace of the Image (default) + current Action on every object in my selection.

    Is there already a scrip there and if not how would I build one? I am new to scripting, which means that I have basically no idea of what I'm doing. Can someone help me?

    Sorry,

    a bad line of code on my part has been the origin of the problem.

    Line 14 to the controls of the code for an element of the frame

    I was testing just the object itself.

    I should have tested its typename.

    Replace this line with this:

    if(sel[i].typename == 'RasterItem'){
    

    that should solve the problem

  • Imported wmv file now shows that half of the image

    Hello

    I have a standard animation that I use in all my trailers and DVD. This plays ok on PC, but today when I imported a new animation project shows that the lower half of the image rather than the whole image. It seems to be half when plaid in the monitor. The sequence is the same size as the animation. Even if the animation shows, like that in the front source imported in a sequence monitor. Can anyone help? Thank you

    Cropped image.jpg

    It is a known issue with a recent update from Windows.

    Upper half of the video is missing (black screen) - Help!

    http://forums.Adobe.com/message/5494175#5494175

  • How to get rid of search bars that appear on the images after you mouse over them?

    When I mouse over any image on some sites an 'x' in a black and white circle appears in the right corner of the image and a search bar in the left corner. Mouse research leads to a drop-down list with about three links box. By clicking on the "x" close the search bar, but how I keep from always appear? Very annoying when on a page with multiple images (e.g. browsing someone Photo Gallery on DeviantArt)

    It's weird - if you run a search, what is sought?

    This is probably a feature of an add-on. You can view your add-ons and initially disable all non-essential and unrecognized plugins and extensions.

    Firefox orange (or the Tools menu) button > addons > Plugins category

    Firefox orange (or the Tools menu) button > addons > Extensions category

    After restarting Firefox, if the display persists, could you post a screenshot of it and see if anyone recognizes? This article may help: How to make a screenshot of my problem?

  • I joined to buy an image, after that I joined the image disappeared. Why?

    2 days ago I searched for images of the reserve for a flyer design, I downloaded the preview image to make a model for a customer, design was accepted and I have activated an account Adobe Stock to buy the image. I can find no more is the image. When you use the search engine for the game of football image the image only showed in other stock photo sites. previewing the image name is: AdobeStock_40913022_WM

    Hello

    In the search field, enter 40913022 and make sure the 'photos' option is checked:

    Let us know if you still have any questions.

    Thank you

    Bev

  • List of laptops that compatible with the images of windows 8.1 and 10 HP.

    Hello

    I need to find a list of laptop computers that are compatible with the v10 and Windows v8.1. The operating system will be installed from origial HP image.

    Could you please help me to know suh list?

    Kind regards

    Emil

    Hello

    Even if such a list is available, I'm afraid that you do not publicly.

    Most or all out last year 1 HP computers are compatible Windows 10

    Most or all computers HP published between late 2012 and between summer 2015 are compatible in Windows 8

    Class specifications business most released in the past recent years can run Windows 7, 8, 10 and ~ ~ Linux [I mean backward compatibility, compatibility certainly not ahead]

    If you have a specific questions. specific HP models, do not hesitate to post.

    I hope this helps.

  • How can I change the shadows that appear on the images and fonts

    There are shadows on all policies and the picures that dispay. This is how I can eliminate this annoying.

    Hello

    Please follow the steps below and update us with the results.

    How to remove shadows:

    a. click "start". Right click on "computer". Select 'Properties' from the menu. Click the "Advanced system settings" link in the left pane of the window.

    b. click on the "settings" button in the "Advanced" tab in the "System Properties" dialog box

    c. click on the "Custom" radio button in the "Visual effects" tab in the "Performance Options" dialog box

    d. click to uncheck the check box next to "Shadows fall usage labels icon on the desktop."

    e. click the button 'Apply' and 'OK' to remove the shadows of fonts in Vista. Close the dialog boxes.

    Let us know if it helps!

  • I use Photoshop CC and have just watched a tutorial by Andy Anderson about bosses. In the tutorial Andy put a frame around a picture using the fill on the Edit menu. When I try the exercise my fill window is different and that is not the image

    I use Photoshop CC and have just watched a tutorial by Andy Anderson about bosses. In the tutorial Andy put a frame around a picture using the fill on the Edit menu. When trying to exercise my fill window is different and does not have the picture frame option. How to overcome this please?

    Hello

    Please, go to the filter menu and choose make it > photo frame.

    Thank you

  • I want to import pictures like 'Add' so that they remain in their current location in my finder folders, but when try to import that they show the images faded, indicating that they were already imported... but, I can't find them in my catalog.

    ?

    Thanks for the reply. I found how to solve my problem.

Maybe you are looking for

  • Satellite Pro L300 - using partition magic

    Hello I have a Toshiba Satellite Pro L300 laptop and I would like to make an additional partition next to the C: drive already existing and the hidden partition. I created the recovery discs and I want to use the magic of partition for the partitioni

  • Printhead HP Photosmart e6520

    The printhead for the HP Photosmart e6520 may be replaced, or can it be cleaned only? If so, how often should it be cleaned? Thanks for a response.

  • HP pavilion 15-p077tx: missing audio beats

    yesterday, I installed update with taking assistant in charge of hp and after restarting the wasnot his work so I installed the driver from the hp website, but they provided the driver realtek audio. My sound works but the beats and driver interface

  • Dialog control stamp kills system Exec.vi!

    Hello! I have just a really strange behavior in my application. I managed to narrow it down to a much smaller VI, please don't look at the framework, but the real problem, this test of the vi MAIN looks like this because it's a skeleton of an applica

  • The Windows media player 10 is corrupt and not showing not in Add and remove programs

    I download windows media player 10 from microsofts Web site was updated, but when I click on the icon for media player and try to open it I get a windows media player error is not installed correctly. Error message: The wmplayer.exe file has a versio