How can I bulk rename Writer images to a standard form?

Mainly out of OCD, I’d like to rename many selected images with standardized names.

In my case, I use a particular image as a scene break, so this same image repeats hundreds of times. The names end up being things like “Image81 Copy 4 Copy 9”. I’d like to find and rename them all to, e.g., “Break 001”, “Break 002”, etc.

The nearest post to this I’ve found is How to remove all the images in a document in LibreOffice Writer? - Ask Ubuntu

It seems like the proposed macro from that link could be adapted to my use, but I’m not sure how to find out how to find and refer to the image name property in LO Basic.

Do you use repetitively the same image between your scenes? Is there any reason to make a distinction between the present images? What is your use of different names? In other words, would it be nicer for you if you had a single image displayed numerous times? This is a trick I use frequently.

To provide the best answer, mention OS name, LO version and save format.

1 Like

It’s the same image, reused multiple times. It’s not the only image in the document; there are essentially two to three images that get reused. I would love to simply use the same image and keep referring to it (as I do in EPUBs). Huge saving of space, but I haven’t found a way to do it.

The names don’t really matter, frankly; I don’t use them for anything. But I get annoyed by the long list of images with useless titles. At least with names, I could be sure what was what.

But reusing/referring to a single image source would be a much better solution.

Windows 11
LO:
Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1
CPU threads: 12; OS: Windows 10.0 Build 22631; UI render: Skia/Vulkan; VCL: win
Locale: en-US (C); UI: en-US
Calc: CL threaded

Save format: ODT

Sub rename_images(event)
	doc = Thiscomponent
	
	i = 1
	For Each image In doc.GraphicObjects
		image.Name = "NewName " + i
		i = i + 1
	Next
	
End Sub
2 Likes

To simply reuse an image (making it unique in the document), create a list style (fifth icon from left in the style sidepane).
Configuration is mainly done in Customize tab:

  • Number: Graphics
  • Graphics: select the image file with the file browser

Position is adjusted in Position tab:

  • Aligned at: distance to center of “page” (printable area) minus a very small amount equivalent to a space
  • Numbering alignment: Centered
  • Number followed by: Nothing
  • other settings irrelevant because there will be no text with your image

Give it a name like Image in Organizer.

Create a new paragraph style with name Image Separator.

  • don’t set Indents in Indents & Spacing (they will be internally; don’t interfere)
  • keep Left alignment; don’t try to Center it, this is already taken into account by the list style
  • set Spacing below and above to your liking in Indents & Spacing (this much much better than using empty paragraphs)
  • in Outline & List tab, associate with List style Image you previously created

When you want to insert your image to separate two scenes:

  1. hit Enter to create a new paragraph
  2. apply paragraph style Image Separator
  3. VERY IMPORTANT, type a space
    Without a space, the “number” (your image) will be deleted. This is a Word-inherited compatibility rule to “fix” the bad habit of using empty paragraphs to vertically space by people not understanding that the mechanical typewriter era has gone long ago.
  4. hit Enter to enter the first paragraph of the next scene
  5. either press Ctrl+0 (digit zero) to return to standard discourse paragraph style (Body Text) or apply your preferred paragraph style

No image is listed/added in the Navigator.

With this trick, if you want to change your image, you do so in the Image list style and magically your whole document is updated without the need to do so on every occurrence.

4 Likes

This is genius, eye-opening, and ‘I can’t believe I didn’t think of this’, all at once. I can’t wait to try it out, but I see no reason it shouldn’t work for me. Now I just need to figure out how to search for and replace particular images.

I suppose the main practical difference will be slightly smaller file sizes, but my mental comfort will be substantially higher. Thanks!

It took me years to imagine such a solution (in another context). It is not obvious at all and certainly an abuse of the list concept.

To quickly navigate to your existing images, double-click on their name in the Navigator.

And, yes, file size will be sightly smaller but not that much because LO does already a pretty good job identifying duplicates of graphical material. The difference won’t be in the image storage but in the encoding: no frames, no complex constructs, a very simple markup.

1 Like

This is great! I’ve set up two styles (scene break and end story), though I did have to refer to your (very clear) instructions once or twice. All my styles are organized, so ‘scene start’ automatically follows ‘scene break’ (though Ctrl+0 was new to me). Thanks again very much for setting this all out so clearly.

If “scene break” and “end story” are both list styles tweaked for image insertion, you can even use another trick. However, the Next style setting may complicate matters.

If “end story” is the final paragraph of your book, i.e. it is followed by nothing, in which case the Next style parameter does not matter, you can merge the list styles into a single one. Attach the “end story” image to level 2. By default, a list item is created at level 1. Consequently you get the “scene break” image. When you want the “end story” image, press Tab before the space to promote the list item to level 2.

And even if you have text after it, you can always change the automatically applied paragraph style for another one. After all, “end story” is much less frequent than “end story”.