Updating Numerical Value to Be Even

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

mycort

Updating Numerical Value to Be Even

Post by mycort »

My use case:
I am creating measurement lines, arrows and labels for when I create designs for iOS. For best quality results, I need to make all assets and measurement values even, but there are
many times where my measurement values are odd numbers....

I need a code snippet that will do the following below:
1) Go through and detect numbers in text layers
2) If the value is an odd number, it will change the numerical value and add +1 to make it an even value


for example:
if I have several text layers with content 23px, 67px, 45px....the script will change these to 24px, 68px, 46px.

Thx.
Mike Hale

Updating Numerical Value to Be Even

Post by Mike Hale »

It is my understanding that for best quality you make two images. One for non-retina and a larger version with the same name + @2x. The device will use the @2x version if it has a retina display.

You can only have the one image and tell the device scale it. In that case the image will look better scaled if the height and wide of the image is even. It would be much, much easier to create two versions than try to even all the elements inside the image. Even doing the scale in Photoshop would look better than letting the device do it.
mycort

Updating Numerical Value to Be Even

Post by mycort »

Hi Mike,

your right about the 2 files, one retina @2x and one at normal size...... but even these need to have a size that needs to be divided evenly for quality issues....as an example, a button needs to be 140 x 60px, not 141 x 63px.

I'm really talking about something else......this is about creating pixel measurement (blue print) that shows spacings and sizes of things in the screen for engineers use for a guide in building. When I measure out a spacing within the screen, sometimes I get an odd number. Then I would adjust the ui elements by decrease or increase the spacing and run the measure script to get a even number....

it would be just much easier if we adjusted all text layers with numbers to be even so that we dont need to adjust the ui elements in the screen....

Here's a link to what I mean:
http://mycort.deviantart.com/art/Pixel- ... -297289490 ... -297289490

I just need to have a script that checks all the text layers with values and make them even....

hopefully that makes sense.
Mike Hale

Updating Numerical Value to Be Even

Post by Mike Hale »

Setting aside whether it's needed or not for vector and text elements, I don't see how you could do that without rasterizing the text layer, even in the GUI.
mycort

Updating Numerical Value to Be Even

Post by mycort »

Is it possible to maybe do the following with script:

- select a text
- edit and highlight the text content
- analyze for if numbers are used
- then just change and add + 1 to make it an even value
- dehighlight text and save text layer
Mike Hale

Updating Numerical Value to Be Even

Post by Mike Hale »

Ok, I think I misunderstood what you are trying to do but so I'm clear this time let me ask... You mean change the font size, not the size of the text outlines themselves?
mycort

Updating Numerical Value to Be Even

Post by mycort »

cool man and no problem, let me explain a little bit more...

My pixel measurement script creates numercial text layer labels like this: 14px, 53px, 66px, 27px, 33px.

if possible, I just need a code snippet to add to my pixel measurement script that will make any odd numbered text layers and add + 1 value, so will make these odd numbers from 53px, 27px, 33px ---------------> 54px, 28px, 34px....it will leave even numbered text layers alone and only applies to odd ones. in this use case, I already have created all my measurement values and just need a code snippet to go back and analyze all odd text layers and change them to even.

if this is too hard to do, here's an alternative idea. My pixel measure script generates lines, arrows and labels based on the length or width you make a selection. IF possible, I'd like a code snippet that will append or slice + 1 value to the selection value that will make it an even number once it generates the value. for example, if I measure 13px with my selection and I run my script, it will give me a text label of 14px instead....but if I make an even selection of 18px, it will generate a text label of 18px.....so only applies to odd numbers...and leaves even numbers alone.

thx.
Mike Hale

Updating Numerical Value to Be Even

Post by Mike Hale »

I didn't understand that you really only want even numbers in your script's output. I had thought you wanted to change the elements so they would be even.

Code: Select allvar myLabel = 37;
myLabel = isOdd(Number(myLabel)) ? myLabel+1:myLabel;

function isOdd( x ){
   return x==x+0 && Boolean(x % 2);
}
mycort

Updating Numerical Value to Be Even

Post by mycort »

sorry for the confusion, works exactly...thx alot!!!!
jackmortain
Posts: 1
Joined: Sun Nov 13, 2022 10:31 am

Re: Updating Numerical Value to Be Even

Post by jackmortain »

mycort wrote: Wed Feb 13, 2013 3:05 am Hi Mike,

your right about the 2 files, one retina @2x and one at normal size...... but even these need to have a size that needs to be divided evenly for quality issues....as an example, a button needs to be 140 x 60px, not 141 x 63px.

I'm really talking about something else......this is about creating pixel measurement (blue print) that shows spacings and sizes of things in the screen for engineers use for a guide in building. When I measure out a spacing within the screen, sometimes I get an odd number. Then I would adjust the ui elements by decrease or increase the spacing and run the measure script to get a even number....

it would be just much easier if we adjusted all text layers with numbers to be even so that we dont need to adjust the ui elements in the screen....

Here's a link to what I mean:

I just need to have a script that checks all the text layers with values and make them even....

hopefully that makes sense.
Yes the issue is got solved by the given Pixel spec measuring script for Photoshop link is not working which is having me a issue with setting a photo resolution to which they want a specific resolution for a Photo.