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

Scaling

Explorer ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

Hi all, can anyone please help me to retrieve a scaling value of  image in illustrator. How can we identify which scaling has been applied to the image using script. I would like to know how to check whether the image has been applied horizontal scale or vertical scale. Thank you. 

TOPICS
Scripting

Views

3.0K

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
Adobe
Community Expert ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

The Links panel gives scaling info.

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 ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

Hi @Abpujar, please try this. - Mark

Edit 1: improved script.

Edit 2: updated script to better handle RasterItems which have flipped scale Y values. Still more work to fix fully.

Edit 3: now handles RasterItems and PlacedItems correctly (I think!).

 

 

/**
 * Get PlacedItem Scale And Rotation
 * for Adobe Illustrator
 *
 * by m1b
 * discussion: https://community.adobe.com/t5/illustrator-discussions/scaling/m-p/13050842
 *
 */


var doc = app.activeDocument,
    item = doc.selection[0],
    result = getLinkScaleAndRotation(item);

if (result)
    alert('Results:\nHorizontal scale: ' + result[0] + '%\nVertical scale: ' + result[1] + '%\nRotation: ' + result[2] + '°');



/**
 * Return a linked item's scale.
 * @author m1b
 * @param {PlacedItem|RasterItem} item - an Illustrator item
 * @returns {Array} [scaleX%, scaleY%, rotation°]
 */
function getLinkScaleAndRotation(item) {
    if (item == undefined)
        return;

    var m = item.matrix,
        rotatedAmount,
        unrotatedMatrix,
        scaledAmount;

    var flipPlacedItem = (item.typename == 'PlacedItem')
        ? 1
        : -1;

    try {
        rotatedAmount = item.tags.getByName('BBAccumRotation').value * 180 / Math.PI;
    } catch (error) {
        rotatedAmount = 0;
    }
    unrotatedMatrix = app.concatenateRotationMatrix(m, rotatedAmount * flipPlacedItem);
    scaledAmount = [unrotatedMatrix.mValueA * 100, unrotatedMatrix.mValueD * -100 * flipPlacedItem];

    return [round(scaledAmount[0]), round(scaledAmount[1]), round(rotatedAmount)];
}



/**
 * Rounds `n` to `places` decimal places.
 * @param {Number} n - the number to round
 * @param {Number} places - number of decimal places, can be negative
 * @returns {Number}
 */
function round(n, places) {
    var m = Math.pow(10, places || 4);
    return Math.round(n * m) / m;
}

 

 

 

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 ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

Hi @m1b @thank you for the reply, I’m getting the scaling value but I need -ve or +ve value, for example if the image has been applied horizontal scale then the scaling value should be -ve or if the image has a vertical scale then the vertical scale value should be in -ve. If the image has not been applied any scaling then the scaling value should be in +ve. Thank you. 

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 ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

I don't understand what you mean. Can you please give me some examples, eg.

200% horizontal, 150% vertical scale = ?

100% horizontal, 101% vertical scale = ?

101% horizontal, 100% vertical scale = ?

99% horizontal, 100% vertical scale = ?

Then I will understand. - Mark

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 ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

for example If we give -100% horizontal ,100%vertical scale , in this scenario the image will be flip horizontally,(here I need to get the horizontal value as -ve). If we give 100% horizontal ,-100% vertical scale ,in this scenario the image will be flip vertically. if the image has been applied -ve scaling ,then I need to get -ve value.

 

how can we know whether the image has been flipped or not after applying scalingscaling using 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 Expert ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

Hi @Abpujar, you are being so polite! You should have just said that my script didn't work! Haha. I've had another attempt. Please try again with the updated script above.

- Mark

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 ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

Hi @m1b  i’ve tried ur updated script still I’m getting the same result as previous, I just want if the image has been flipped after applying scaling then the value should be -ve (-100). if we have manually given -ve scaling value the image will be flipped.

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 ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

Okay, can you post a small sample illustrator file that shows the error?

- Mark

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 ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

var xScale = Math.sqrt(my_matrix.mValueA my_matrix.mValueA + my_matrix.mValueB my_matrix.mValueB); var yScale = Math.sqrt(my_matrix.mValueC my_matrix.mValueC + my_matrix.mValueD my_matrix.mValueD); xScale = xScale * 100; yScale = yScale * 100;

 

Here I’m getting scaling value , how can we identify whether the image has been flipped or not after applying scaling.if the image has been flipped horizontally then the horizontal scaling value should be -100. How can we calculate ?

 

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 ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

I need a sample file that has a placed image that shows the incorrect scale.

 

When I place an image and flip it horizontally, and run script, I see -100% hor, 100% vert which is correct. I want to understand why your test doesn't show that.

- Mark

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 ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Screenshot 2022-07-05 at 1.02.37 PM-1.png

 

Hi @ here I’ve not applied any scaling to this image but still it shows vertical scale value -100.

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 ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Yes I see @Abpujar, and I want to fix the script. The problem is that when I place an image myself and run script it correctly shows 100%, 100%. So I was hoping you could save your .ai file and post it here so I could see what's different about your file and mine. I can't easily fix something that works perfectly for me. Also which version of Adobe Illustrator are you using? Also did you place that image, or did it come in another way? I really need a sample file to look at. To post a sample file, drag the .ai file when you are replying here—down below where it says "Drag & drop here or browse files to attach".

- Mark

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 ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

I'm using Adobe Illustrator 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
Community Expert ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Hi @Abpujar, thank you! That sample file is what I needed. Okay, believe it or not, but Illustrator shows a Y-flipped matrix for RasterItems compared with PlacedItems. (RasterItems are embedded images, not linked images.) I've updated my script above to better handle RasterItems but I notice it still doesn't give correct results if the rasterItem is scaled and rotated. I'll look into that when I get time.

- Mark

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 ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

One more update to (hopefully) work correctly with both PlacedItems and RasterItems. @Abpujar, please try updated script above.

- Mark

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 ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

Hi @m1b  still it is not working properly. I have tried it with different images. 

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
Mentor ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Did you flip it?

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 ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

No I've not applied any property. 

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 ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Bonjour,

il me semble que vous devriez utiliser

 

scaledAmount = [unrotatedMatrix.mValueA * 100, unrotatedMatrix.mValueD * 100];

 

à la place de

scaledAmount = [unrotatedMatrix.mValueA * 100, unrotatedMatrix.mValueD * -100];

 René

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 ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Thanks @renél80416020, see my reply above. Strangely that Illustrator flips the Y scale in the matrix for PlaceItems—which I wrote the script originally for, assuming (wrongly!) that RasterItems would be handled the same.

- Mark

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 ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

Copied

Bonjour m1b,

C'est puissant cette affaire, merci pour le partage...

Je me demande pourquoi utiliser "app.concatenateRotationMatrix"

et non pas tout simplement?

 scaledAmount = [m.mValueA * 100, m.mValueD * -100 * flipPlacedItem];

René

 

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 ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

Hi @m1b the above code is still not working on different images. can u please check it once.

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 ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

Hi @Abpujar, can you please post sample file of any .ai files that have images that script fails with?

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 ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

Hi @renél80416020, I have to get an unrotated matrix before I can extract the scale value.

- Mark

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