• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Action that uses a percentage of image size in pixel dimensions

Community Beginner ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

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!

TOPICS
Actions and scripting

Views

4.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jun 12, 2018 Jun 12, 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 thi

...

Votes

Translate

Translate
Adobe
Explorer ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

Untitled-1.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

R-bin, your action is reliant on an image of a certain size... 100CM. If I were to run it on a 10cm or 1000cm image, the 4cm frame would look very different. Wouldn’t it?

That’s why I’m using percentages.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

No the action changes your image Print Resolution to 10CM and adds the Frame if you scale the image print Resolution back to its 100CM print resolution the added frame will also be scaled . So if you add a 2CM frame to a 10CM image  when you scale the 10CM image back to 100CM the 2CM frame will scale to 20CM.   Units like CM is relative to Resolution.   You do not need to know what the resolution is.   You can set the images width  to some measurement Photoshop will set the correct print resolution.

Action can not use logic.  Things need to be a known size.  If you resize an image to a know size like 8" wide without resampling all that changes is the Image Print resolution not a single Pixel is changed deleted or added.  Once the image Print size is set you can add a frames X" wide.  Where X is What you want it to be for that size image.

If you use one of my utility scripts I wrote for use in Actions twice you could even restore the Image to it Original print size.  You would use the script as the first and last step in you action.  The first time it runs it will save your image Print Resolution and current ruler units in the documents metadata.  The second time the script is run it will remove the saved Resolution and ruler units from the documents metadata,  reset the document resolution to its original print resolution and restore you Photoshop ruler units.

Crafting Actions Package UPDATED Aug 10, 2014 Added Conditional Action steps to Action Palette Tips.>

Contains

Example

Download

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

JJMack, I see that the issue you are solving by inserting a jsx into your action is to capture and then restore the original resolution.

I just can't use jsx in the diverse, controlled environment my designers are in. I'm reading your text about Conditional Action Steps, I need to learn how to apply them.

My simple action uses an unconventional layer-based-trick, and requires NO jsx to aquire a percentage of the image to create a selection of a relative size, and can then be run on ANY sized image.

In this case I'm using the action to create a frame, but I can see other uses of this concept.

I'll post the action as soon as possible.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

You mean you can not use scripts that Adobe and other supplied. Like Fit Image, Merge to HDR Pro, Photo Merge, Image  Processor, Image Processor Pro, Load Files into stack . Save layers as files etc. What a poorly controlled environment you and your designers work in.   You should try to improve the environment you work in, tricks there is no real magic.  Put in controls that work fix your environment.  Unconventional layer-based-trick  sound like it will lead to image quality loss to me.  Please do not post your actions unless you just want to find out what is causing your Image quality loss.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

JJMack, I set up this discussion to find a creative solution that didn't require jsx. I found that solution, and it's a much simpler solution than you are suggesting. My image is not degraded, or rescaled in the least. It works for web, print, anything... it's a simple method that has eluded Adobe itself.

There is no call to insult my studio environment. It is not "poor", simply because the logistics, language, learning level, operating systems and security permissions of dealing with 50+designers in 20 offices, on 4 continents would make it less efficient for me to call a JSX from this action.

I have created and used many incredible JSX scripts, and maintained and taught them to my design teams locally... it gets messy with different os environments, and imagine how you would deal with all those time-zones, when users all over have issues, as they would?

And this line of yours is really SMH "Please do not post your actions unless you just want to find out what is causing your Image quality loss."

Who put you in charge of my thread? Why assume my action causes image quality loss... it does not.

And I will post what I please so open-minded power users get the benefit.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/Mark+Bravo 

R-bin, your action is reliant on an image of a certain size... 100CM. If I were to run it on a 10cm or 1000cm image, the 4cm frame would look very different. Wouldn’t it?

That’s why I’m using percentages.

It wouldn’t.

You tried?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

You can do thing scaling to know a known size like 8" wide without resapling and add canvas 4" wider and taller size the frame will be  2" on all four sides but you changed the image print size.   With a little script you could have save the original resolution scaled the image add the fame and the scaled the image back to it original resolution size. You could also  add pattern wood mitered frame or oval frames.  A little scripting can help Actions do better. Here is an old package of actions I did years ago.  I do not know it the all will still work for Adobe has added som bugs into Photoshop scripting after I create the actions the sue some scripting,

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

Mark you can share action.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

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)};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

geppetto,

the color values are just an example of course, feel free to change the parameters at your will and satisfaction.

@ JJMack: the ImageVisualisationPackage is still working properly, as far as I could see when I tested several functions some weeks ago.

Thank you for communicating this helpful code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines