Scripting get exact visible setting of an image in a frame

New Here ,
Jan 28, 2022 Jan 28, 2022

Copy link to clipboard

Copied

Hi,

 

I am quite new here and did some scripting in in design before dot but now I want to create a small solution that I will need for a bigger publishing project.

 

I need to create a script that can get the exact placement of an image from an image box.

 

As an image gets enlarged and repositioned with an image frame, I want the script to read out this setting so that I can save it and re-apply it in a later step when needed.

 

 Can anyone direct me to the right commands/options that I would have to look out for?

 

I'm very grateful for any help! Martin

TOPICS
Scripting

Views

181

Likes

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 Professional ,
Jan 28, 2022 Jan 28, 2022

Copy link to clipboard

Copied

Assuming one image on your first page in a rectangle. The image can be accessed via: 

var img = app.activeDocument.pages[0].rectangles[0].graphics[0];

From there, you can record its geometric bounds: 

var bounds = img.geometricBounds;

which are the image's physical bounds, even those covered by the crop. GeometricBounds is an array indicating the image's four positions: y1, x1, y2, x2.

Likes

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
New Here ,
Jan 31, 2022 Jan 31, 2022

Copy link to clipboard

Copied

Dear Drainp311,

thanks I played a bit around but still do not get what I want to achieve - maybe I can try to explain myself again and maybe you can give me some further advice... Would be great. Hopetp get it then and step up the learning curve ladder...

 

What I want to do (lon goal) is to place on several pages a few iomages in each page. The pages are different from each other each using a certain layout master page so that the predefined boxes for images vary from page to page (well, this is not the main point...).

 

After having placed images in all boxes on all pages, I go over the layout and optimize how images are disply in each box by enlarging or selecting the best part of an image per box. All done manually so far.

 

Now I wnt to read out all, well, information how each image is placed in a box. So that I can re-apply this exact (manual) setting I did after images might get reloaded to a frame again due to some process routines.

 

E.g. Es 10 x 15 cm image get applyed to a 8 x 8 cm box. And it get e.g. enlaregd to some extend and moved to the left and then also down a bit, just because of how this image looks like.

 

Now I want to get the informtion about this images, so that I can later apply these image settings again by a script lets us say in another document with the same master layout used...

 

Hope the explanation helped. Can you help me to better unterstand what informtion I will need – and how to reapply it?

 

Kimd regards, Martin   

 

  

 

Likes

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 Professional ,
Jan 31, 2022 Jan 31, 2022

Copy link to clipboard

Copied

What kind of code have you tried thus far? I don't really write complex routines like this for free, but can help point you on the right path. Do you have any experience writing scripts? Here is the fully searchable DOM if you are unfamiliar with that resource: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html 

 

Likes

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 Professional ,
Jan 31, 2022 Jan 31, 2022

Copy link to clipboard

Copied

Hi Martin,

also read into this article by Marc Autret:

 

Work Around the Width/Height Gap
Marc Autret, October 17, 2009

https://www.indiscripts.com/post/2009/10/work-around-the-width-height-gap

 

Regards,
Uwe Laubender

( ACP )

Likes

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
New Here ,
Jan 31, 2022 Jan 31, 2022

Copy link to clipboard

Copied

Thanks Uwe,

 

this is super special and interesting! Currently my goals are much lower 😉 I stil struggel to get the information I like to have as I just see that this part of the InDesign model is very unfamiliar to me...

  

Likes

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 Professional ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

"After having placed images in all boxes on all pages, I go over the layout and optimize how images are disply in each box by enlarging or selecting the best part of an image per box."

 

Hi Martin,

well, this could be a function you could automate with InDesign's fitting controls.

Look for FitOptions.CONTENT_AWARE_FIT

 

You could write your own algorithm to do this but it would need a master in PhotoShop scripting and image analyzing, pattern recognition, etc.etc. to do this.

 

Best post some screenshots that show the steps you'd like to automate with real-world images of course.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
New Here ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

Dear Uwe,

if I get you right you suggest to use the "new" autofit" option while placing an image? Is it the "context-sensitive adaption" of an image in its frame? Well, this is not needed in our case, just as it would support the initial step to place images. Thie "autofit" works helps sometimes but we still have tp optimize the image in its frame to te exact detail of a picture we like to show.

 

For me it us important to get/save the final detail/position of the image within its frame. As in our process we might reimport all images again several times. Why so? As adaptions of other detals of the layout take place and we then have to reimport all images (and textes) to its frames. This multiple re-import processes work well as I use InData from EM Software.

 

But during this process I will make already the final fits of the images. And I like to get and save the made detail settings in order to re-apply them again after another re-improt process was neccessary. So InData does all the image and text loading. Sometimes I have to update text or I have a second language version. So, all gets imported again, mages are in the same frames etc. And the the magic shall happen that the images gets resized to what I did before and saved via a nice script 😉

Here come also two screenshots for a better explanation:

1 Lookbook - Probelayout InData 6_2-1-22_10-48-33.jpg2 Lookbook - Probelayout InData 6_2-1-22_10-48-33.JPG   

 

Likes

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
Advisor ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

Could you use the difference betwen the bounds fitted by you and the fit frame to content bounds. Use that difference to reposition the image on re-import.

 

...

 

Look at snippets, that might give some clue.

 

P.

Likes

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 Professional ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

Hi Martin,

well, supposed you have two graphic frames, one with the image and another one without it; the empty frame has different properties, but the same size, so you could not just duplicate the one with the image to get what you want. You could use contentPlace() to transfer a duplicate of the image from one frame to another.

 

See for example into my answer here:

https://community.adobe.com/t5/indesign-discussions/moving-embedded-graphic-to-another-frame/td-p/86...

 

DOM documentation of method contentPlace() :

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Graphic.html#d1e257494__d1e259354

 

On the other hand:

If the properties of both frames are the same you could simply duplicate and move the frame with the image and remove the empty frame.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
New Here ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

Hi Uwe

 

I do not want to copy images within a layout ... – but to maintain image dimentisons and what is visible within a from of once placed and adjusted images after the layout (frame are all at the same places, but empty) gets updated in a new run. The goal is that all reloaded images get adjusted to the formerly achieved status.  

 

Or did I get you suggestion wrong?

 

Likes

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 Professional ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

Hi Martin,

obviously I did not get your question. Now it's more clear.

Hm. You could write the properties of the placed image to its frame.

Use a label with a key string and a value string for that.

 

ExtendScript methods insertLabel() and extractLabel() could be used.

If you want to retrieve actual code from the label's value you could use eval() with the extracted string.

 

What's still unclear for me is why you need to remove the image from its frame.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
New Here ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

Hi Uwe,

good if I could describe the circumstances better. Thanks for your suggestion where to save the information. Still I am not sure which information I will have to grab and maybe how to put it back when needed to the appropriate frame after an image was loaded in it again in a second run in order to rearrange the image to the formerly selected visible part.

 

Why I do this? I have a whole book of pages that get generated automatically. Due to the amount of different information I will e. g. in text frames I usually have to reload all inforamtion a few times till it fits at the end.

 

Somewhere in this process the image optimization (which part of an image will be visible in which size...)     takes place and while all images are placed accordingly at the end – it usually occurs that all the data has to be relaoded again for a few times, just as updated, crorected or otherwise altered data comes in.

 

So, I want to save all image arrangement work and re-apply it...

 

Also it can be that some pages have to be added somewhere in between, also this causes a reload of all data. In theses cases all images that where already present will be re-placed again on layouts with exact the same frames (though the can cariy from page tp page).

Hope you get an even better picture.   

 

 

Likes

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 Professional ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

LATEST

If I understand the request correctly:
Wouldn't it be better/easier to crop the images to their frames, then resave them in their own folder, and finally replace all the images completely?

Likes

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