Copy link to clipboard
Copied
I have an image (551 px by 709 px) which is on the clipboard.
I would like this image to appear in my active document (3307 px by 4677 px)
The x and y locations where I want the images to appear are:
- x = 200 y = 800
- x = 751 y = 800
- x = 1340 y = 800
- x = 1929 y = 800
- x = 200 y = 1509
Can anyone help in creating a javascript loop?
- - that uses the x and y values (to be stored in an array) and
- - pastes/places the image in the active document at the x,y locations and
- - the coordinates are for the left hand top of the image as beginning point.
(Everything else concerning this project is already in javascript, but I can't work this out).
Help will be greatly appreciated.
The last line of my code that pastes the image (above) on a new layer.
myselection.paste();
From there on I got stuck.
1 Correct answer
This should help...
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
doc = app.activeDocument;
var ArrayX = [200, 751, 1340, 1929, 200 ];
var ArrayY = [800,800,800,800,1509 ];
for(var a in ArrayX){
doc.paste();
var LB= doc.activeLayer.bounds;
var X = Number(ArrayX) - LB[0].value;
var Y = Number(ArrayY) - LB[1].value;
doc.activeLayer.translate(X,Y);
}
preferences.rulerUnits = startRulerUnits;
Explore related tutorials & articles
Copy link to clipboard
Copied
The way I would do it would be make a selection when I want it and past into the will past it in there and be centered to the selection will also be made a mask to mask off any excess. You could also just past in the clipboard the make a selection and align the new current layer to the sesection.
If look at this script you will see where I ues paste into to tile image into a document. I also align the images to the selection. This may be overkill and not needed.
http://www.mouseprints.net/old/dpr/PasteImageRoll.jsx
Copy link to clipboard
Copied
Thank you for your reaction but I'm looking more for something (small) like this:
var ArrayX = [ 200, 751, 1340, 1929, 200 ];
var ArrayY = [800,800,800,800,1509 ]
for( i in ArrayX)
“paste image at this location ArrayX,ArrayY” (don't know if this can be translated in some sort of code.......)
....
....
Copy link to clipboard
Copied
This should help...
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
doc = app.activeDocument;
var ArrayX = [200, 751, 1340, 1929, 200 ];
var ArrayY = [800,800,800,800,1509 ];
for(var a in ArrayX){
doc.paste();
var LB= doc.activeLayer.bounds;
var X = Number(ArrayX) - LB[0].value;
var Y = Number(ArrayY) - LB[1].value;
doc.activeLayer.translate(X,Y);
}
preferences.rulerUnits = startRulerUnits;
Copy link to clipboard
Copied
Thank you, it's excellent!
Copy link to clipboard
Copied
The main difference between to two approaches is Paul's set you up with a custom script for your particular size clipboard image and your five positions. This works with that clipboard size image. Your document.
My script was designed to be a general purpose script. To handle any number of images that can be any size and aspect ratio. The script lays out tiles the size you want that will look like center crops of your images and not overlap and any number of copies can be laid down and any number of image can be used. All Photoshop supported image file type can be used for source images. A new document will be opened that can hold the required number of tiles. The size of the script is much larger but the majority of the code is for the Scripts dialog and preparing the images clipboard image size so it will fill a tile. The code that lays down the tiles is quit small if you remove the code not needed it boild down to
for (var n=0;n<copies;n++) {// number of copies
var x =pasted*width;
var y =currrow*height;
var selectedRegion = Array(Array(x,y), Array(x+width,y), Array(x+width,y+height), Array(x,y+height));
doc.selection.select(selectedRegion);
doc.paste(true); //paste image into masked layer your document
pasted++
if ( pasted==cols ) { pasted=0; currrow++; }
}
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
I changed my Script yesterday. I created it to tile images images into a document without borders and any inter image spacing to print image on roll paper without any paper waste. A user had asked that I add borders and image spacing. At that time without much thought I said no. That I did not want to add additional path length to the script code. Yesterday I realize that no additional code was needed all I had to do was to externalize border and spacing in the scripts dialog and to to change a few of the existing calculations in the script no additional logic was needed the code didn't need any change. So I added Border and grout to the dialog. Any size image can be used any size tile you need border and spacing and and number of images and number of copies. Only five lines of code needed to be changed and the two field added to the dialog.

