Skip to main content
Known Participant
July 3, 2022
Question

Scaling

  • July 3, 2022
  • 2 replies
  • 7272 views

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. 

This topic has been closed for replies.

2 replies

m1b
Community Expert
Community Expert
July 3, 2022

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

 

 

 

AbpujarAuthor
Known Participant
July 4, 2022

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. 

AbpujarAuthor
Known Participant
July 18, 2022

Hi @Abpujar, feel free to send me a sample file and I'll see what I can find out. - Mark


Hi @m1b in this file I’ve copied image from other document and placed it in illustrator, now the image typename is rasterItem , here I’m not getting file property to this image.(here the image extension is .eps).is there any other way to retrieve the file details without using file property?

Ton Frederiks
Community Expert
Community Expert
July 3, 2022

The Links panel gives scaling info.