Copy link to clipboard
Copied
I flow a lot of source images into InDesign, but most of the image frames are originally in square dimensions (like 3" x 3" or 12" x 12"). This is the case even if the image inside the frame is 3" x 12" (example image attached).
The frame I need images to fit into (rectangle frame tool) has a measurement of 1.5" x 2.85" and the images need to scale proportionally. They fit properly when I place them, but the original empty space from the images is still showing. My only fix for the last few years has been to manually crop out the excess space in each image that needs it. I was wondering if (hoping!) there's a way to automatically crop out this extra space when the images are originally placed.
Hi @Red-Temujin , just to follow up on the Photoshop trim command, not sure if this works for you, but the script below will open the document links in Photoshop, and trim away the white pixels. My example opens all of the links, which you might not want, but it could also specify the links on a targeted layer, or the single link as you place:
Edited Code:
//#targetengine "session";
//opens document links in Photoshop and trims
app.scriptPreferences.measurementUnit = MeasurementUnits.P
...
Copy link to clipboard
Copied
" My only fix for the last few years has been to manually crop out the excess space in each image that needs it."
Well, do that in PhotoShop before placing the image in InDesign.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
A better background:
I place hundreds of images at a time directly from clients' libraries, which usually have the images in square dimensions. They're almost always different images, so first cropping in PhotoShop wouldn't help with the automation (unless there's a way to automate in PhotoShop and not in InDesign).
If what I'm asking for doesn't exist, I understand. I just wanted to ask the community to see if I could save myself from perfroming the most mundane task of the process.
Copy link to clipboard
Copied
More details below.
Even if I would like to script this ( which is technically doable) using the result path of the Text Wrap functionality of InDesign with Apply Text Wrap to Motif will not result in a perfect solution:
So with an image like that it's hard to impossible to automate this if you want the motif here, the rectangle with the rounded corners.
FWIW: What could yield a better result is a script that would use PhotoShop perhaps. But here we have also the issue to part the foreground motif from its background.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The red lines of the two images are where the crops would be needed.
Copy link to clipboard
Copied
Another word on this:
The better the resolution and the overall quality of the images you want to place, the better one could automate this with a script.. With poor image quality the results of a possible automation of this task will be mediocre to be not acceptable.
Here with your sample image its obvious that automation software needs a helping hand from a human being.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Red-Temujin,
thank you for the second screenshot.
I know excatly what you mean.
But still I'm sceptical…
It should be doable with a script if the overall resolution and image quality is "good enough".
But you have to eyeball every result and correct a "wrongly" cropped image placed in a frame.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Almost all images I deal with are hi-res (at least 1200 px x 1200 px). I understand some images may need the human touch, based on your picture above, but having the option to automate most of them would be a great help.
Copy link to clipboard
Copied
After re-reading your first message I think that maybe I'm missing something here.
Could you provide a sample document?
The document should contain one frame with the wrong position of the image inside its container frame.
Plus a second frame where you corrected the image.
Only the InDesign document is needed.
( Optional also include the original image file as well. )
In the meanwhile I did some tests with ExtendScript code that are looking promissing.
Thanks,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you for providing the sample document with the image file.
Unfortunately the sample proofs that (mis)-using InDesign's 2021 new text wrap feature to crop that image is not good enough for the precision we need here:
That means we need the help of PhotoShop for pixel precision.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Never mind. I tested the brush like you did the other image. I see what you mean. InDesign keeps a lower resolution image to work with, compared to the original. This makes the text wrap untenable....
But just thinking with my keyboard, do we really need the text wrap to work perfectly? All I need is the furthest left and right edges, or up and down edges.
Copy link to clipboard
Copied
Hi Uwe & Red, have you considered using the InDesign clipping path/detect edges tool? you can apply a negative frame inset, which removes the interior white areas from the path.
Copy link to clipboard
Copied
I tested that as well, Luke. It's not perfect for what I had in mind, but it might be the best option. The main problem with that: the rectangle frame tool doesn't allow the clipping path to detect edges—at least everything I've tried. It can only be done after an image has been loaded.
Copy link to clipboard
Copied
Hi Luke,
yes, I also considered that option. The issue: you cannot tell programmatically which one will fit better.
So I really think, that PhotoShop should find the drawing pixels vs. the white ones and then either crops the image or does a rectangular clipping path. Thing is: you first have to find out how to do this reliably by scripting PhotoShop.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Does the only way to do this in InDesign involve the text wrapping tool? PhotoShop has the Automate < Crop and Straighten Photos ability that is perfect for what I'm looking for (except that it's not in InDesign). Also, it wouldn't need to straighten the images.
Copy link to clipboard
Copied
This thread has gone cold, so I just wanted to add a bit to it. In the attached (missing-text-wrap) it shows how there isn’t an option to use text wrap with the rectangle frame tool. Simply having this option before loading all the images would save me many hours per project, so it would pretty much solve my issue. I added another screenshot (Sample-Problem) to show the only problem with this fix. “And” and “or” have been placed oddly due to Uwe’s previous find—but this is something I can check for and fix the few times it occurs.
Of course, having an automated crop option with the rectangle frame tool would be best, but I understand that may be impractical or impossible.
Copy link to clipboard
Copied
You can make an object style for text wrap and then clear overrides when you drop in your images.
Copy link to clipboard
Copied
Hi Uwe, Not sure if this helps, but Photoshop has the trim() method, which lets you trim to the transparent or white background pixels. So this trims away the pixels defined by the top left pixel color. There are also boolean parameters for skipping the top, left, bottom, or right sides:
var d = app.activeDocument
d.trim(TrimType.TOPLEFT)
Does this:
https://www.indesignjs.de/extendscriptAPI/photoshop-latest/#Document.html#d1e47935__d1e49165
Copy link to clipboard
Copied
Hi @Red-Temujin , just to follow up on the Photoshop trim command, not sure if this works for you, but the script below will open the document links in Photoshop, and trim away the white pixels. My example opens all of the links, which you might not want, but it could also specify the links on a targeted layer, or the single link as you place:
Edited Code:
//#targetengine "session";
//opens document links in Photoshop and trims
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var lnks = app.documents[0].links;
var pad = 4;
var img, fr, x;
for (var i = 0; i < lnks.length; i++){
trimLink(lnks[i].filePath);
while (lnks[i].status != LinkStatus.NORMAL) {lnks[i].update()}
img = lnks[i].parent
fr = img.parent
x = fr.geometricBounds[3]-img.geometricBounds[3]
img.move([0,0], [x,0]);
img.fit(FitOptions.FRAME_TO_CONTENT);
fr.textWrapPreferences.properties = {textWrapMode:TextWrapModes.BOUNDING_BOX_TEXT_WRAP, textWrapOffset:[0,pad,0,pad] }
};
/**
* A function to run in Photoshop
* @ param file path
* return file path
*/
function trimLink(pa){
var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = psScript.toString() + "\rpsScript('"+pa+"');";
bt.onResult = function(resObj) { }
bt.onError = function( inBT ) { alert(inBT.body); };
bt.send(8);
//opens the link, trims white pixels and saves
function psScript(pa) {
app.bringToFront();
open(File(pa));
var d = app.activeDocument;
d.trim(TrimType.TOPLEFT);
d.save();
d.close();
}
};
Run on your sample files:
Copy link to clipboard
Copied
Hi Rob,
well, yes, that's the way to go, I think!
It's our OP's project so only Red-Temujin can know if the image material is good enough, e.g. all images have a background of white pixels only. Just to name one criterium.
Thanks for sharing the code.
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
If running the script on all of the document’s links doesn’t work (it looks like there will be links @Red-Temujin doesn‘t want to trim), here is a version that trims a selected image:
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var s=app.activeDocument.selection[0];
var pad = 4;
var lnk, img, fr, x;
if (s.constructor.name == "Image") {
lnk = s.itemLink;
trimLink(lnk.filePath);
while (lnk.status != LinkStatus.NORMAL) {lnk.update()}
img = lnk.parent
fr = img.parent
x = fr.geometricBounds[3]-img.geometricBounds[3]
img.move([0,0], [x,0]);
img.fit(FitOptions.FRAME_TO_CONTENT);
fr.textWrapPreferences.properties = {textWrapMode:TextWrapModes.BOUNDING_BOX_TEXT_WRAP, textWrapOffset:[0,pad,0,pad] }
} else {
alert("Please Direct Select an Image and Try Again.")
}
/**
* A function to run in Photoshop
* @ param file path
* return file path
*/
function trimLink(pa){
var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = psScript.toString() + "\rpsScript('"+pa+"');";
bt.onResult = function(resObj) {}
bt.onError = function( inBT ) { alert(inBT.body); };
bt.send(8);
//opens the link, trims white pixels and saves
function psScript(pa) {
app.bringToFront();
open(File(pa));
var d = app.activeDocument;
d.trim(TrimType.TOPLEFT);
d.save();
d.close();
}
}
Copy link to clipboard
Copied
I’m sorry, Rob, but I’m having trouble utilizing your first script. I’m receiving two errors:
#1 Error in Line 11:} Too many closing braces
#2 Error Number: 29446 Error String Source: lnks[i].relink(File(cp));
Can you please let me know at what point(s) along the process I’m messing up?
1) Copy and paste the script in NotePad (or VS Code)
2) Save as ImageTRIM.jsx
3) Copy the file into the Scripts Panel folder
4) Open scripts in InDesign and double-click on imageTRIM
(As you can probably tell, my coding ability is dubious at best)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now