[Solved] Resizing All Images?

Discuss the word processor
Post Reply
Jonnster
Posts: 3
Joined: Thu May 05, 2011 5:37 pm

[Solved] Resizing All Images?

Post by Jonnster »

I have a very large document and I need to resize all the images in it to 50% of their current size. Is there any easy way of doing this? Doing it manually one by one just isn't an option as it'll take too long.

Is there a built in option to do this? Is there a Macro I could use?
Last edited by Hagar Delest on Tue Aug 03, 2021 10:11 am, edited 1 time in total.
Reason: tagged solved.
OpenOffice 3.1 on Windows 7
User avatar
RoryOF
Moderator
Posts: 34613
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Resizing All Images?

Post by RoryOF »

A first thought: if the images are linked, you could move them from their source directory, process them to 50% in batch mode with some suitable image processor, saving them in the source directory under the original name, and then they ought relink on opening your document. You may need to adjust their position afterwards.
 Edit: Macro given in
http://user.services.openoffice.org/en/ ... =20&t=1112 
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Jonnster
Posts: 3
Joined: Thu May 05, 2011 5:37 pm

Re: Resizing All Images?

Post by Jonnster »

Thanks but the images are not linked. They are embedded. Also that macro appears to be for one manually selected image. I want to resize all images in one go and even selecting them all manually isn't an option. I am talking about a 3500 page document.
OpenOffice 3.1 on Windows 7
User avatar
RoryOF
Moderator
Posts: 34613
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Resizing All Images?

Post by RoryOF »

You have the core of the macro - the bit that does the work. What you need now is a wrapper that passes through the document, selects each image in turn and then runs that macro.
 Edit: If you have programming skills in (say) BASIC, you could open the archive file that comprises your document and take out content.xml, then pass this to a new file, scanning for svg:width=" and svg:height="; when either of these tokens is found, you read in the next 5 numeric characters up to but not including the ", characters which are in form n.nnn, halve them and return their value to the output stream in place of the original values. Then insert the new content.xml into the archive structure and there you are. Perhaps quicker and simpler than having to learn how to write/run macros in OpenOffice. 
Last edited by RoryOF on Fri May 06, 2011 10:42 am, edited 1 time in total.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Jonnster
Posts: 3
Joined: Thu May 05, 2011 5:37 pm

Re: Resizing All Images?

Post by Jonnster »

And how do I do that?
OpenOffice 3.1 on Windows 7
User avatar
RoryOF
Moderator
Posts: 34613
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Resizing All Images?

Post by RoryOF »

You have to learn the rudiments of programming. There are not macros/programs for every possible task. Writing a macro is a _non-trivial_ task and needs user input.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Resizing All Images?

Post by JohnV »

Definitely back up your file before your run this.

Code: Select all

Sub ResizeAllGraphics 
Dim go,g,i
go = ThisComponent.getGraphicObjects
For i = 0 to go.Count-1
 g = go.getByIndex(i)
 g.Height = g.Height/2
 g.Width = g.Width/2
Next
End Sub
swinebolt
Posts: 1
Joined: Tue Aug 03, 2021 5:12 am

Re: Resizing All Images?

Post by swinebolt »

JohnV
...thanks a lot for the code snippet. It works awesome.

Swinebolt
OpenOffice 2.4 on Ubuntu 9.04
Post Reply