Copy link to clipboard
Copied
I tried to get original dimension of placedItem in Script.
How can I get?
Sorry, I can't write English well.
Copy link to clipboard
Copied
If I understand your question correctly then you need to get width and height of the the item.
So you can get this, by using width and height property.
Steps to follow.
1. Place item.
2. Make sure you do not perform any transformation on it.
3. Select the placed item.
4. Run following line of code, it will give you width and height
var _selectedItem = app.selection[0]
alert(_selectedItem.width)
alert(_selectedItem.height)
Let us know if this is what are you looking for.
Copy link to clipboard
Copied
thx, Charu.
I meaned "original size".
I have a image that width of 767 px.
const item = layer.placedItems.add();
item.file = new File('sample.png'); //767px
alert(item.width);
but that's 184px.
I know this is 72dpi and 300dpi magic.
I wanna know to get 767px in script.
Copy link to clipboard
Copied
Hi,
Got it. Try following snippet.
var layer = app.activeDocument.activeLayer;
var _item = layer.placedItems.add();
var _file = new File('sample.png');
_item.file = _file;
var _originalDimesnions = getOriginalWidthAndHeight(_item.file)
alert(_originalDimesnions[0]);
alert(_originalDimesnions[1]);
function getOriginalWidthAndHeight(imageFile) {
imageFile.open('r');
try {
while (imageFile.tell() < imageFile.length) {
var line = imageFile.readln();
var idxOf = (line.indexOf('<exif:PixelXDimension>') > -1) ? line.indexOf('<exif:PixelXDimension>') : line.indexOf('<exif:PixelYDimension>');
if (idxOf > -1) {
if (line.indexOf('<exif:PixelXDimension>') > -1)
_width = parseInt(line.substring(line.indexOf(">") + 1, line.lastIndexOf("<")));
else
_height = parseInt(line.substring(line.indexOf(">") + 1, line.lastIndexOf("<")));
}
}
} catch (ex) {
alert('Error');
}
finally {
imageFile.close();
return ([_width, _height]);
}
}
I hope this gives orginal width and height.
Copy link to clipboard
Copied
thx, Charu.
I understand to get XMP.
but,
imageFile.readln()is garbled characters.
thx, great idea.
Copy link to clipboard
Copied
How about the following
var obj = app.selection[0]
var bb = obj.boundingBox
var h = Math.abs(bb[2]-bb[0])
var w = Math.abs(bb[3]-bb[1])
alert("height " + h + " width " + w)
-Manan
Copy link to clipboard
Copied
thx, Manan.
But, result is not original size.
I meaned "original size".
I have a image that width of 767 px.
const item = layer.placedItems.add();
item.file = new File('sample.png'); //767px
alert(item.width);
but that's 184px.
your code's result is also 184px.
thx.
Copy link to clipboard
Copied
Seems to work for me, i integrated your code into mine to replicate exactly what you do. See the screengrab at the following link
Let me know if I am misunderstanding something
-Manan
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more