Batch Replace Images - GitBruno/Novelty GitHub Wiki

/img/image_refs.png

It can be painful to update low-res RGB composites with press-ready files. This guide demonstrates how to update these references inside an IDML file using Regular Expressions.

  • Save as IDML
  • Update file references

1. Package IDML

/img/package.png

Package the native file ticking the Copy Linked Graphics, Update Graphic Links In Package and Include IDML tickbox.

Add your batched art (files you want to update to) to the links folder.

2. Update File References

Now that we have an IDML file we can start looking for the references.

In this example I will need to update all .jpg, .jpeg and .png's with their press-ready counterparts [.tiff, .psd]

Note: Normally I will also do some housekeeping by remove any trailing whitespace, replacing spaces and special characters with underscores but will only change the file extension for now.

2.1 Unpack IDML

To work with the XML files within the IDML package we need to unzip it first:

unzip docname.idml -d docname

You can also use the idmlZipUnZip.zip droplet if you have permission to run software from unidentified developers. You can also use this to repack the file as described below.

Image references are on multiple places, so we need to target multiple files:

  • META-INF/metadata.xml
  • MasterSpreads/*.xml
  • Spreads/*.xml
  • Stories/*.xml

2.2 Run the query.

It is relativly safe to target all files in the folder. The following expression targest all image references inside the Links folder:

(?<=\/Links\/)(.+\.)(jpe?g|png)(?=[\<"'])

It captures two groups, Group 1 is the filename incl. period. Group 2 is the file extension (jpg, jpeg or png)

Replace with \1tif to update the extension to .tif.

$1tif if your engine handles capture groups differently

3. Repack IDML

As with ePub, when we zip our IDML file back up, we need to do add the mimetype first, without compression.

zip -jX0 docname.idml docname/mimetype

Now we can add the rest of the files (with compression), excluding the files we already added (mimetype) and those pesky .DS_Store files.

cd docname
zip -rDX9 ../docname.idml * -x *.DS_Store -x mimetype

Now we should be able to open the updated IDML file in InDesign. Your links will now automatically update.