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

A bug with Image size resize?

Engaged ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

Photoshop CC and CS6

I have a image with a width of 158px I'm trying to perform a rescale down 17.7% of the original 158. That should be ((158 * 17.7) / 100) = 27.96 Now That's what I'd like (I'm looking for it to ceiling up / round up) to 28 and that's the new size I want.

(but nothing seems that simple with PS) When I try this is PS I get 29 px once the image has been rescaled:

Screenshot_190.png

Can you help me understand where the extra pixel comes from and what the solution would be to get the actual CORRECT transform values?

TOPICS
Actions and scripting

Views

9.1K

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

People's Champ , Sep 06, 2018 Sep 06, 2018

I do not know how to resizet layers with even dimensions in one pass

and what opportunities do you have in the Plugin's API other than just duplicate the code for AM.

The last sentence.

Try this script. It processes all layers. It is desirable that there are no empty layers or layers with a mask.

If you specify use_even = true, then all the end dimensions of the layers will be even

Good luck.

var pcnt = 17.7; 

var use_even = false;

app.preferences.rulerUnits = Units.PIXELS; 

var ok = true;

app.activeDo

...

Votes

Translate

Translate
Adobe
People's Champ ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

Image resize works as it should.

What are the numbers in the pictures? Specify.

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
Engaged ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

@r-bin The original image width = 259 and the height = 158

Both the width and height outputs are wrong.

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 ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

I'm not seeing this with either CS6 or CC 2018.

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
Engaged ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

I'm now realizing that the pixel resolution will also be a determining factor.

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

Do you mean pixel aspect ratio  or print resolution.  When you resample an image your resampling the images pixels resolution should not be involve if you are using percent.  If you were resize to some dementional unit  like inches  that would be calulate into pixels using the current resolution.  Resample resample

your Image size shows width  .140" height .169" at 300ppi or width 42.6px by height 50.7px

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 ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

Is this issue when you are running a script or just using resize though the dialog box?

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

I think I understand what he's up to.
Most likely there is an image with a large canvas, for example 1000x1000, and a layer with a 259x158 frame. If you reduce the size of the entire image to 17.7%, you get such an "incorrect" result for a particular layer.

I do not know yet how to overcome this

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
Engaged ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

I may have confused you, when I say I have a image in my document I have a layer that I need to pre calculate the bounds.

My original (Unscaled document size) is: 1358x1620

Layer size (Unscaled): 259x158

What I'm trying to do is scale the document size (1358x1620) down by 17.7% (I'm going to use the width as the example) and when I do the new layer width after the document has been scaled should be: ((158 * 17.7) / 100) = 27.96 so 28 (with ceiling preformed) but it's not it becomes 29 in photoshop, this is happening in both the Image UI and my C++ plugin.

Screenshot_192.png

@Chuck Uebele I'm not understanding what you are unable to do.

@JJMack I'm using CS6 'As my plugins paths are able to be pointed to and that contains a 'pixel resolution' that (as far as I'm concerned defeats the purpose of a pixel height and width) and I'm able to set the pixel resolution, I'm not sure what you're saying with the photos, since the problem is between the final size, of my layer (Showing just with the width)

r-bin​ You're correct, and I need to figure out how to solve this since this is the only other way I can pre calculate the bounds of a layer so I can make sure the scaled down layer is within a bounds I need. So this is a bug?

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

i73  wrote

What I'm trying to do is scale the document size (1358x1620) down by 17.7% (I'm going to use the width as the example) and when I do the new layer width after the document has been scaled should be: ((158 * 17.7) / 100) = 27.96 so 28 (with ceiling preformed) but it's not it becomes 29 in photoshop, this is happening in both the Image UI and my C++ plugin.

If you are using Image size to resize a layered document that has a canvas 1358x1620 size to 17.7% of its current document size all layers will be resized to 17.7 if their current size..  Only the Background layer needs to be canvas size. All other layer can be any size and can have any aspect ratio,    Photoshop knows all the layers bounds whatever they are.  If you add a new layer to a document it will be empty. If you fill a centered 5px by 5px Selection with colored pixels the empty layers bounds will now be 5px wide by 5px high a 1:1 aspect ratio.  Since you can no have a document element size less then a pixel  17.7% of x may require the result to be rounded to the nearest pixel.

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
Engaged ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

If you are using Image size to resize a layered document that has a canvas 1358x1620 size to 17.7% of its current document size all layers will be resized to 17.7 if their current size.

That's my problem, yes I agree with you that the layer should be 17.7 of the current document size but it's not. You can see in this photo that the new layer size becomes 29 and not 28 (rounded from 27.966):

Screenshot_192.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
People's Champ ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

This is not a bug.
Why do you care about the exact size of the layer when resize the entire document?
You can resize the layer separately with an accuracy of 1 pixel. Alternatively, after resizing the entire document, adjust the size of the layer to the desired size if necessary.

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
Engaged ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

"This is not a bug."
How would I be able to get the correct pixel size if it's not a bug? What's the solution?

(158 * 17.7) / 100) = 27.96 but photoshop scales it to 29 pixels.

"Why do you care about the exact size of the layer when resize the entire document?"
My application requires that I have a specific size of the layers, I need to pre calculate that it meets these bounds (before resize) and resizes the transforms of the layer before I perform the document resize (after the 17.7 resize all the layers should meet these conditions from the pre transform I performed but they are not, as photoshop gives me wrong values).

"You can resize the layer separately with an accuracy of 1 pixel. Alternatively, after resizing the entire document, adjust the size of the layer to the desired size if necessary."

1. This will add quite a bit of work when I have to re position the layers back to their original positions in the document.

2. I originally did the resize (to the specific size) after the document rescale but I found that rescaling the layers would produce artifacting and it will not solve the problem.

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

Yea, that's adding in slack tolerance. PS will have to resize your document to a full pixel dimension. All layers will be converted by that amount, which may not be the actual amount you entered. Then PS will display the layer bound in whole pixels, adding to the slack tolerance.

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
Engaged ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

@Chuck Uebele How can I calculate that into my formula? Even if there was rounding of the pixels like this example (158 * 17.7) / 100) = 27.96 it should become 28 but photoshop gives me 29.

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

In general, you can not get a formula.

You can try this.

Add on the layer a vector mask equal to the size of the layer.
Resize the image.
Rasterize the vector mask.
Make threshold 128 for the mask.
Apply layer mask.

Bingo! (in 99% of cases, I think)

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
Engaged ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

"In general, you can not get a formula."

I just don't understand why it's not just scaling by the basic function (x * P% / 100) I give it, how exactly does this even make sense? A mathematical formula is set in stone, how do they (Or why do they) need to add padding to the pixels? I must be confused but where or why does this layer not scale down to the 17.7% that I ask from it (I'm also accounting for rounding)? If I fully understand I might be able to work around it, "that's adding in slack tolerance." to me just means that they ceiling up if it's not a whole number, I'm not seeing how they get arbitrary pixels from nothing.

While I appreciate your suggestion r-bin​ That's not a valid solution for me.

Thanks guys for helping me, by the way.

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

As I mentioned, PS has to have a document size in full pixels. so while you might enter 17.7, PS might calculate the scaling at 17.76 to get a full pixel for the doc size. It will then use that 17.76 to scale everything else and not your original 17.7, as that would throw off the layers fitting properly within the document.

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
Engaged ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

@Chuck Uebele fully understand that (and because of that I even tried with rounding the numbers floor and ceiling in my script) but I have tried with a flat 17%, 18% and 19% and I still get the same error in output. Even if (by your example) if the scale was off by 0.01 it still should not be giving me a whole pixel as a rounded value / fitting.

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

del (error)

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
Engaged ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

Hey rbin, I'm not trying to resize the layer by 17.7%

activeDocument.activeLayer.resize(17.7, 17.7) 

I'm trying to get the layer (after document image resize) to be equal to the formula ((x * P%) / 100) in all use cases and it's not

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

Check my script. Percentage count yourself as you want. Everything works perfectly.

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

Also it works as it should.

Active layer should be your VIP layer ))

var pcnt = 17.7;

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("layerID"));

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var id = executeActionGet(r).getInteger(stringIDToTypeID("layerID"));

try { activeDocument.backgroundLayer.isBackgroundLayer = false; } catch(e) {}

var d = new ActionDescriptor();

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("selectAllLayers"), d, DialogModes.NO);

var d = new ActionDescriptor();

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("linkSelectedLayers"), d, DialogModes.NO);

var d = new ActionDescriptor();

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);

var d = new ActionDescriptor();

var r = new ActionReference();

r.putIdentifier(stringIDToTypeID("layer"), id);

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

///////////////////////////////////////////////////////////////////////////////////////////

//////////////////// Here it is, the magic! )) ////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////

var d = new ActionDescriptor();

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

d.putEnumerated(stringIDToTypeID("freeTransformCenterState"), stringIDToTypeID("quadCenterState"), stringIDToTypeID("QCSIndependent"));

var d1 = new ActionDescriptor();

d1.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), 0);

d1.putUnitDouble(stringIDToTypeID("vertical"),   stringIDToTypeID("pixelsUnit"), 0);

d.putObject(stringIDToTypeID("position"), stringIDToTypeID("point"), d1);

var d2 = new ActionDescriptor();

d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"), pcnt);

d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("percentUnit"), pcnt);

d.putBoolean(stringIDToTypeID("linked"), false);

d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("bicubic"));

executeAction(stringIDToTypeID("transform"), d, DialogModes.NO);

var d = new ActionDescriptor();

d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"), pcnt);

d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("percentUnit"), pcnt);

d.putEnumerated(stringIDToTypeID("horizontal"), stringIDToTypeID("horizontalLocation"), stringIDToTypeID("left"));

d.putEnumerated(stringIDToTypeID("vertical"), stringIDToTypeID("verticalLocation"), stringIDToTypeID("top"));

executeAction(stringIDToTypeID("canvasSize"), d, DialogModes.NO);

///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////

var d = new ActionDescriptor();

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("selectAllLayers"), d, DialogModes.NO);

var d = new ActionDescriptor();

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("unlinkSelectedLayers"), d, DialogModes.NO);

var d = new ActionDescriptor();

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);

var d = new ActionDescriptor();

var r = new ActionReference();

r.putIdentifier(stringIDToTypeID("layer"), id);

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

i73  wrote

If you are using Image size to resize a layered document that has a canvas 1358x1620 size to 17.7% of its current document size all layers will be resized to 17.7 if their current size.

That's my problem, yes I agree with you that the layer should be 17.7 of the current document size but it's not. You can see in this photo that the new layer size becomes 29 and not 28 (rounded from 27.966):

You did not read what I wrote correct Layers will be 17.7% of their current size not the document canvas size,  Layers can be larger and smaller and have a different aspect ratio than the Document Canvas size the can also be Canvas size. New layers can have any size. Place layers Pasted layers are new layer and new empty layer can have any bounds equal to the document canvas or smaller it depends on the pixels you fill in that empty layer.

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
Engaged ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

I read you fine JJMack, you are saying that "all layers will be resized to 17.7 if their current size." I understand this and this is what I want; what I'm telling you is that they are not actually being scaled down 17.7% with precision.

I said "the layer should be 17.7% of the current document size" Meaning that they should be 17.7% of their original size.

I fully understand the process that a document that's scaled down to 17.7% the original size will effect the bounds of the layers to 17.7% and I have shown it in code.

The problem is I'm wanting the layers to be 17.7% of their original size (x * P% / 100) or (originalScaleHeight * 17.7% / 100) if you look up at the above reply I posted before you that's not the case. There's some arbitrary values to the width and or height that are being calculated that I need to fully understand where they are coming from. 

I know its just a pixel but I need 100% accuracy in this case and that's the issue.

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