Skip to main content
Inspiring
June 12, 2018
解決済み

Action that uses a percentage of image size in pixel dimensions

  • June 12, 2018
  • 返信数 6.
  • 6532 ビュー

Hi all,

I'm trying to create an action that creates a frame that is the same thickness X & Y, based on a 4% percentage of the image width.

The problem is, If I were to just use 4% of an image that is 1000x800, my frame would be 40px x 36px thick - not equal... but I want it to be the same thickness = 40px x 40px thick. But I can't simply type in a set pixel width, because on a 2500x3300px image the frame would be much too thin.

So I need to always use the same percentage (4%) of just one dimension (width). Then convert that data to pixels to work with selections.

I would prefer not to use a JSX in this action, as I'm sending this out to dozens of designers on both PC and Mac.

Thanks!

解決に役立った回答 Mark Bravo

Thanks all. I created a working action with no JS required!

How to make a frame that is the same width on all 4 sides, and always looks the same thickness, no matter how big the image is.

If the image is a puny 90x90 or a giant 5000x7500 - this frame will always be the same percentage thickness of the size.

Duplicate the background layer (or select-all > copy-merged > paste)

Edit>Scale this duplicate layer to 4% HZ x 100% VT- (This is a side frame edge at whatever % thickness you want).

Duplicate this scaled layer 3 more times

Rotate two of the copies 90º for top and bottom, and scale them to 300% x 100% (to overcompensate for a HZ image)

Select the background layer, and each frame edge in turn and align to the 4 sides of the document.

Note: You will have to take care with the scaling - choosing which anchor point will allow you to use a top+side, or bottom+side alignment to anchor to the corners of the document.

Merge the 4 layers, and you get a proportional frame at a percentage of the original width that has the same pixel-thickness all the way around.

This should make a much better Frame Action than Adobe's default frame set which uses pixel numbers, which are invariably the wrong size.

返信数 6

Stephen Marsh
Community Expert
Community Expert
March 8, 2021
JJMack
Community Expert
Community Expert
June 14, 2018

I'm not trying to be in charge.  I just do not think it proper to post Unconventional layer-based-tricks they may confuse many users.

When I worked in development and research the corporation I worked had local and remote IT department staffed with professionals they would maintained and Install software for the corporation diverse PC users. They maintained different configurations for Different development communities as well as configuration for secretarial staff and executives.  Operating syetem like Windows, OS2, Aix, Mac, Mainframes Operating system  and network servers and clusters  etc.  Departments could also add software to the department computers.  Plug-in, scripts, Action and other Photoshop Add-ons could be installed and maintained by department members. 

We had networks around the world  before the Internet became a reality.  I would install software around the world from my home bedroom. It is work and requires professional. Security permissions 50+designers in 20 offices, on 4 continents is Complex.  Most software I installed I have to admit was installed in English but many Application like Photoshop can be configured to use the local language.   I started working on Computers and Operating systems is 1965 I'm retired now sill I believe there should be many more and betters tools for development and maintaining software these days.  I wish Adobe would use some of them  They seem to release more bugs these days then they did years ago.

JJMack
Geppetto Luis
Legend
June 13, 2018

Mark you can share action.

Inspiring
June 13, 2018

If I understood the question correctly this function should be working as well and seems less complex:

w = app.activeDocument.width * 0.04

op = 100      // %

r = 200, g=0, b=0

fillContur(w, op, r, g, b)

function fillContur(w, opac, red, green, blue) {

    // Parameters: w = desired width of the frame (4% of image width)

    //                  opac = opacity of the frame (usually 100%)

    //                  red, green, blue = RGB-Color of the frame

    //     

    // Fill modes:

    //  c2t( "Otsd" )  = outside

    //  c2t( "Insd" )   = inside

    //  c2t( "Cntr" )   = centered  (used in this example)

    var d = new ActionDescriptor();

    var d1 = new ActionDescriptor();

    d.putInteger( c2t( "Wdth" ), w );

    d.putEnumerated( c2t( "Lctn" ), c2t( "StrL" ), c2t("Cntr") ); 

    d.putUnitDouble( c2t( "Opct" ), c2t( "#Prc" ), opac );

    d.putEnumerated( c2t( "Md  " ), c2t( "BlnM" ), c2t( "Nrml" ) );

    d1.putDouble(  c2t( "Rd  " ), red );

    d1.putDouble(  c2t(  "Grn "), green );

    d1.putDouble(  c2t(  "Bl  "), blue );

    d.putObject( c2t( "Clr " ),  c2t( "RGBC" ), d1 );

    executeAction( c2t( "Strk" ), d, DialogModes.NO );

}

function c2t (s) {return app.charIDToTypeID(s)};

Geppetto Luis
Legend
June 13, 2018

Thank you for your time

but I would like it to apply the color chosen by me first floor

and not a default color r = 200, g = 0, b = 0

However, the action of Mark Bravo intrigues me.

Mark Bravo作成者解決!
Inspiring
June 13, 2018

Thanks all. I created a working action with no JS required!

How to make a frame that is the same width on all 4 sides, and always looks the same thickness, no matter how big the image is.

If the image is a puny 90x90 or a giant 5000x7500 - this frame will always be the same percentage thickness of the size.

Duplicate the background layer (or select-all > copy-merged > paste)

Edit>Scale this duplicate layer to 4% HZ x 100% VT- (This is a side frame edge at whatever % thickness you want).

Duplicate this scaled layer 3 more times

Rotate two of the copies 90º for top and bottom, and scale them to 300% x 100% (to overcompensate for a HZ image)

Select the background layer, and each frame edge in turn and align to the 4 sides of the document.

Note: You will have to take care with the scaling - choosing which anchor point will allow you to use a top+side, or bottom+side alignment to anchor to the corners of the document.

Merge the 4 layers, and you get a proportional frame at a percentage of the original width that has the same pixel-thickness all the way around.

This should make a much better Frame Action than Adobe's default frame set which uses pixel numbers, which are invariably the wrong size.

sidpalas
Inspiring
June 13, 2018

Clever solution, thanks for coming back and sharing it!

Your action will work as long as the image is not more than 3x as wide as it is tall, correct?

Mark Bravo作成者
Inspiring
June 13, 2018

That's correct... which in this case is fine. That variable could be tweaked to any number... 2000%, and it would work.

JJMack
Community Expert
Community Expert
June 13, 2018

You need to use logic to get the size of the with and height then calculate the size you want the frame to be in pixels and add 2x the number of pixels to the canvas width and height. You need to script it

In an Action you can only use ruler units set to Percent.  The Frame will only be equal on all for sides when image are square for width and height are equal in size.

A Photoshop javascript would work on MAC an PC.  If you ise an Action you need to distribute and install the action on all machines.   The same would be true for a JSX.  You could use the Script in an Action so all your Actions could ne in the same Action Set.  The Script needs to be added the Photoshop's script path

JJMack
sidpalas
Inspiring
June 12, 2018

I don't know how to accomplish this (or even if it is possible) using only an Action.

Extendscript is compatible with both PC and Mac. There are occasional differences in behavior, but for something relatively simple like this I would expect it to work fine on both platforms.

Is the concern that the designers are already familiar with installing actions and may have trouble getting up and running with a script?

Mark Bravo作成者
Inspiring
June 13, 2018

Yes, @Sidpalas "Is the concern that the designers are already familiar with installing actions and may have trouble getting up and running with a script?"

I'm sending this to many designers at offices around the globe, with no way to control the possible variables of users interacting with a Photoshop JS for the first time.

I love the JS capabilities, and use them... just not in this case.

Inspiring
June 13, 2018

so why don't you write a jsx-script and put  the actionButtonInstaller.jsxat at the beginning of your script

as was posted by Kjell Post, kjell@irstafoto.se some time ago?

The designers will have to run the script only once and for future calls they have an action in their action palett available.

After all designers working with PS should be able to run a script from the PS menue.