Resize a layer to a percentage of the document size and position in corner

I need to create a script that places a logo in the corner of my main document but i need the logo to be constrained to a percentage of the document size. my logos needs to live in the bottom right corner of my images and be no larger than 28 percent height and no larger than 60 percent of the width of the document. i need it to constrain proportions of the original file so if the logo is square it will remain square, or if it is more rectangular it will maintain its rectangular shape.  Heres what i've come up with so far, i am pretty inept at scripting so if disregarding my current script is more helpful than building upon it please ignore mine:
if ( documents.length > 0 )
    var originalDialogMode = app.displayDialogs;
    app.displayDialogs = DialogModes.ERROR;
    var originalRulerUnits = preferences.rulerUnits;
    preferences.rulerUnits = Units.PIXELS;
    try
        app.activeDocument = app.documents[0];    //set active document to 2nd document   
        var docRefOne = app.documents[0];
        var refWidth = docRefOne.width;
        var refHeight = docRefOne.height;
        app.activeDocument = app.documents[1];    //set active document to 2nd document   
         var docRef = activeDocument;
        //current image dimensions
        var w = docRef.width;
        var h = docRef.height;
        activeDocument.selection.selectAll();
        docRef.selection.copy();   //Copy selection
        app.activeDocument = app.documents[0]; //set first document as active document
        var docRef = activeDocument;
        activeDocument.selection.selectAll();
       docRef.paste(true); //paste into selection
    catch( e )
    // An error occurred. Restore ruler units, then propagate the error back
        // to the user
        preferences.rulerUnits = originalRulerUnits;
       app.displayDialogs = originalDialogMode;
        throw e;
    // Everything went Ok. Restore ruler units
    preferences.rulerUnits = originalRulerUnits;
    app.displayDialogs = originalDialogMode;

You could do something like this...
#target photoshop
activeDocument.suspendHistory('Logo Resize', 'main()');
function main(){
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDoc = activeDocument;
/////////////////////////////// Amend to suit /////////////////////////////////
var Opacity = 100; /* Opacity of logo */
//Position logo   X,Y
var X = myDoc.width - 10; //Right side of logo
var Y = myDoc.height - 10; //Bottom of logo
var Logo = File(Folder.desktop + "/logo.png"); //logo
if(!Logo.exists){
    alert("Your logo '" + decodeURI(Logo.name) + "' does not exist!");
    app.preferences.rulerUnits = startRulerUnits;
    return;
placeFile(Logo);
var LB = myDoc.activeLayer.bounds;
var docHeight = myDoc.height;
var docWidth = myDoc.width;
var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value);
var LWidth = Math.abs(LB[2].value) - Math.abs(LB[0].value);  
if(LWidth > LHeight) {//Landscape logo
var Percent = 60; /* Resize logo to percentage of smallest side of doc */
if(LWidth < LHeight) {//Portrait logo
var Percent = 28; /* Resize logo to percentage of smallest side of doc */
if(LWidth == LHeight) {//Square logo
var Percent = 15; /* Resize logo to percentage of smallest side of doc */
var percentageHeight = ((docHeight/LWidth)*Percent);
var percentageWidth = ((docWidth/LWidth)*Percent);
if(docWidth < docHeight){
myDoc.activeLayer.resize(percentageWidth,percentageWidth,AnchorPosition.MIDDLECENTER);
}else{  
  myDoc.activeLayer.resize(percentageHeight,percentageHeight,AnchorPosition.MIDDLECENTER);
var LB = myDoc.activeLayer.bounds;
X = X - LB[2].value;
Y = Y - LB[3].value;
activeDocument.activeLayer.translate(X,Y);
activeDocument.activeLayer.opacity=Opacity;
app.preferences.rulerUnits = startRulerUnits;
function placeFile(placeFile) {
var desc = new ActionDescriptor();
desc.putPath( charIDToTypeID('null'), new File(placeFile) );
desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
desc2.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
desc.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc2 );
try{
executeAction( charIDToTypeID('Plc '), desc, DialogModes.NO );
}catch(e){}

Similar Messages

  • Restoring the window size and position of Disk Utility

    I took my mac-mini to a memory upgrade this afternoon, and the guy, who was testing the new configuration of my mini, started, and changed the size of the disk utility window. I hate so much if someone tweaks my personal stuff/setting in their image so much, that I could explode! How can I restore it to the default size and position? I cannot find anything about this on the net, and this is the only setting, I could not restore.

    I'm sorry, ignore that Applescript Snippet, use this one instead (make sure to open disk utility before you run it!):
    tell application "System Events"
              tell process "Disk Utility"
                        set theSize to size of window 1
                        set theNiceSize to (item 1 of theSize) & "x" & (item 2 of theSize) as string
      display dialog theNiceSize
              end tell
    end tell

  • Can you change the units used for size and position in layout editor?

    Hello,
    In Aperture 3.4, does anyone know if you can change the units used for size and position in layout editor?  The page is set in inches, but the image size and position are given in centimetres and I would prefer to work all in inches to create custom layouts.  I can't see any way to change this.  If anyone knows how it would be much appreciated.  Thanks!

    Aperture uses the unit settings defined in the System Preferences.  Set the "Measurement Units" in the "Region" tab of the "Language & Text" preferences to "US"; the Aperture will display the Size & Position in inches, if it is the "Book" layout manager you are asking about.
    Merry Christmas!
    Léonie

  • On a MBP with Mavericks how do I get the Save As dialog box to open at the same size and place at which it was last closed and used to happen before Mavericks?

    Before I upgraded my MBP to Mavericks, the Save As dialog box would reopen at the same size and position as it was when last closed.  Now with Mavericks it always opens in the same position at a very small size.  Is there a way to make it reopen at the last place and size at which it was closed?

    I have resolved the issues presented without having to find and uninstall the Macromedia Flash Player 8.0 in order to get "Adobe Flash Player 10" playback of .swf files on my computer. When I begin this task, I expected to download an "Adobe Flash Player 10" as a player program download instead of the Internet Explorer and Firefox plugin that it appears to be.
    This is what I did and what I believe I have:
    1. I setup Internet Explorer 6 as my default browser and then used the following site to download Adobe Flash Player 10
    http://www.adobe.com/products/flashplayer/
    2. As I had done before (and also suggested in another thread here), I went to Tools/Manage Add Ons and found Shockwave Flash Object, highlighted it, and clicked on Update Active X. Next, what I did not do before, I restarted the computer immediately after that.
    3. Next, I set Mozilla Firefox as my default browser and then used the above site to download Adobe Flash Player 10 again.
    4. With Firefox, the critical step included Firefox Tools/Options/Content with File Types (Configure how Firefox handles certain types of files) and the Manage Tab there. SWF Shockware Flash Object/Change Action/and dotting "use this plugin" - Shockwave Flash, followed by a computer restart got the job done.
    Now, if I want playback of a .swf file, I can
    a. Open With Internet Explorer (assumed with the Adobe Flash 10 "plugin")
    b. Open With Mozilla Firefox (assumed with the Adobe Flash 10 "plugin")
    c. Open With Macromedia Flash Player 8.0
    I am satisfied with those results for my use. Any additional comments on the player vs plugin aspect of the matter would be interesting and helpful.
    ATR

  • Resize Video, both the file size and actual size

    Hi All,
    I am very new to Adobe Premiere (CS3). I have had it for a while but not needed to use until now. A client of mine has sent me a video that he wants on his website. But it’s 150M and 1280 * 720. Can anyone help me out with how I can resize both the file size and actual size to say 800 * 450 so it can stream it via the net?
    Like I said very new to this,
    Cheers,
    Mike.

    The first thing you need to do is determine just what KIND of file you were sent, so you may start a project that matches the file
    Read Bill Hunt on a file type as WRAPPER http://forums.adobe.com/thread/440037?tstart=0
    What is a CODEC... a Primer http://forums.adobe.com/thread/546811?tstart=0
    What CODEC is INSIDE that file? http://forums.adobe.com/thread/440037?tstart=0
    I don't do streaming video, so you should search the help file... I **think** what you want out is a Flash file, but that is only after you know what you are going to load into the CS3 timeline

  • When dragging an image onto a fresh canvas, the resizing feature presnaps the image into the canvas size. I can confirm that this has not happened to me in previous projects. I've also tested this problem by making a new larger document size and dragging

    Contexts: I am very competent with GFX and have worked on many projects.
    When dragging an image onto a fresh canvas, the resizing feature presnaps the image into the canvas size. I can confirm that this has not happened to me in previous projects. I've also tested this problem by making a new larger document size and dragging in the same render. It snaps again. I don't want to re-size from the canvas dimensions, I want to resize from the render's original dimensions.

    Ap_Compsci_student_13 wrote:
    ok sorry but doesn't sscce say to post the whole code?the first S is Short, and yes, it needs to be all the code needed to illustrate the problem and let use reproduce it. If you were developing a new Web framework, your example might be short, but for a student game it's very long.

  • How can validate the ASM size and free space correctly?

    Dears ,,
    I faced problem in ASM size as it appeared in alert file as below
    ORA-19504: failed to create file "+DG_DATA"
    ORA-17502: ksfdcre:4 Failed to create file +DG_DATA
    ORA-15041: diskgroup space exhausted
    So we resize ASM space and large it. But we faced the same problem also although there is free space in ASM.
    It seems that the shown free space is not real.
    How can validate the ASM size and free space correctly?
    Thanks & Regards,,

    *Oracle DBA* wrote:
    Dears ,,
    I faced problem in ASM size as it appeared in alert file as below
    ORA-19504: failed to create file "+DG_DATA"
    ORA-17502: ksfdcre:4 Failed to create file +DG_DATA
    ORA-15041: diskgroup space exhausted
    So we resize ASM space and large it. But we faced the same problem also although there is free space in ASM.
    It seems that the shown free space is not real.
    How can validate the ASM size and free space correctly?
    Thanks & Regards,,
    I was having this problem. Im my case i couldn add datafiles to a tablespace despite the fact that i was having a lot of space in the asm. Try rebalancing. It might help. In my case rebalancing also didn work because it seems that there need to be a threshold space in all the disks for the rebalancing to happen which was not in my case, so i had to shrink some unused space in the tablespace and then after gaining the required space I rebalanced the disk and then the disks got rebalanced, also i was able to use the free space that was showing .

  • Is there a way to increase the icon size (and the text below) without using zoom?  I am trying to help out someone who has moderate visual impairment that does not want to use zoom just to see the icons and their labels.

    Is there a way to increase the icon size (and the text below) without using zoom in iOS 7?  I am trying to help out someone who has moderate visual impairment that does not want to use zoom just to see the icons and their labels.

    Hello Apple.
    It seems you have gone to great lengths to improve accessibility in many areas of the iPad. Why was this obvious problem with icon text size missed?  (It's not with the Mac.). And for so long too.
    Do you employ people with actual accessibility problems to help you do UI design?
    I think too, that some buttons are too close for people who might have motor control problems.
    I love my iPad but I fear as I age, the iPad might not keep up with me.

  • Is there a way to remove the size and position readout when moving Lines in Keynote?

    When moving the endpoints of lines while creating a presentation, a size and position readout appears on the screen. This obscures details below it, often making it difficult to precisely position a line. Is there a way of disabling this? The option in Preferences for disabling this readout for objects does not work for lines. Is this a bug, or am I missing something?

    sberman wrote:
    I'm not completely sure I understand, but ...
    Might Settings > General > Accessibility > Reduce Motion = "On" do what the customer wants?
    I will tell him about that, but I don't think that would be it if that is related to animation.
    We're talking about the wallpaper background that get blurry during the phone screens like http://www.tekrevue.com/wp-content/uploads/2013/09/20130923_ios7emergencycallfla w.jpg (left side) and http://i.i.cbsi.com/cnwk.1d/i/tim2/2013/09/20/ChangingYourTheme.png ... You can see there are background images that got blurred out.

  • Is there a way to change the font size and color of text in the calendar app?

    Does anyone know a way of changing the font size and color of text in the calendar app that comes with the iPad 2?  It is very hard to see the small gray numbers on the calendar.  Thanks

    Looks like you didn't get a reply on your post, but it is still a problem.  Font size is supposedly changeable via "Accessibility" in Settings, but it doesn't work.  You can turn on "Zoom".

  • Is there a way to make movies open with the same screen size and position?

    Hello, I'm a new mac guy having just bought an i-mac a few months ago.
    I have a bunch of saved movies that open in quick time. Each time I open a separate movie by double clicking the file, the window opens in the upper right hand corner in a fairly small window. I must then drag the window size and location to a much larger size. I do this every time.
    I saw under quicktime, preferences, a section about preferences for full screen. This seems to work one time, for that movie, but all subsequent movies (even in full screen) or their same size.
    Is there a way to make the window size and/or location permanent?
    Thanks.

    this would have seemed like an easy thing to do but i've had no luck; one more attempt at a solution?

  • The ipad won't sync some photos, saying the file can't be read by the ipad, however it will sync some photos taken at the same time which are the same size and file type.  Why does it reject some and accept others?

    The ipad won't sync some photos, saying the file can't be read by the ipad, however it will sync some photos taken at the same time which are the same size and file type.  Why does it reject some and accept others?

    Hi there. I'm having the same problem: my iPad won't import some photos from a folder, saying that they can't be read. They are all JPEGS and some photos taken at the same time have synched fine, but out of a folder with 200 photos, it only lets me synch 37. I'm synching albums created via Photoshop Elements 6, which has worked fine until now.
    I've tried deleting all photos and re-synching, and have also deleted the iPod Photo Cache, but it hasn't made a difference.
    The iPad auto-updated to the latest version of iTunes, so maybe that's what's causing it?
    Any advice gratefully received!

  • The photos in my IPhoto have all become mini-thumbnails and I can't open or edit them. When I print the image it comes out normal size.  How do I get the thumbnails back to the standard size and be able to work with them?

    The photos in my IPhoto have all become mini-thumbnails and I can't open or edit them. When I print the image it comes out normal size.  How do I get the thumbnails back to the standard size and be able to work with the photo files?

    What version of iPhoto and system are you running?  On the guess that you're running the latest iPhoto, 9.4.2, Try the following:
    1 - launch iPhoto with the Command+Option keys held down and rebuild the thumnails, Option #2.
    2 - It may take 2-3 attempts so don't give up after only one attempt.
    OT

  • I have a word document that I have put hyperlinks in and turned into a pdf.  When I email and receiver opens in iPad the document is blank.  When I do a file save as pdf the document appears and the hyperlinks work but the document has much of the content

    I have a word document that I have put hyperlinks in and turned into a pdf.  When I email and receiver opens in iPad the document is blank.  When I do a file save as pdf the document appears and the hyperlinks work but the document has much of the content turned into symbols.  What is going wrong?

    You select the printer properties and set the appropriate page size (I think there is a place to set it in PDF Maker too, but not sure). In the printer, this is equivalent to putting the proper paper in the printer.

  • How do I change the font size and color in a text box?

    How do I change the font size and color in a text box?

    Really frustrating to find the first time but simple once you figure it out. I think I spent hours trying to find this. Simply right click on a blank spot in the toolbar up top and select Properties Bar. There it is! The available properties will change depending on whether you have the content (text) selected or the box itself.
    I haven't found a way yet to make it show up as a regular part of the toolbar. It floats around and gets in the way so I don't leave it on and then have to open it again when I need it. Again - frustrating; but at least it's there!

Maybe you are looking for