[Solved] Resize image to 50%

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Tommy
Posts: 251
Joined: Sun Dec 23, 2007 2:44 pm

[Solved] Resize image to 50%

Post by Tommy »

i'd like to have a macro to aumtoatically resize to 50% (or to another custom value) an image embedded in a writer document

actually to do this you have to manually:
- ricght click on image
- select image menu entry
- select "cut" tab
- digit the % value you want

i'd like a macro (which could be assigned to an hotkey or a button) so i schould juast click on the image and digit the hotkey or press the button, to resize immediately the image.

i tried to record a macro doing the aforementioned operations but it doesn't work.

am i doing something wring?
Last edited by Tommy on Sun Dec 23, 2007 11:19 pm, edited 1 time in total.
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
uros
Volunteer
Posts: 30
Joined: Sun Dec 02, 2007 10:26 pm
Location: Slovenia

Re: [REQ] resize image to 50%

Post by uros »

Hi Tommy!
Try this macro:

Code: Select all

Sub ResizeEmbeddedPictureInWriter
	oDesktop = createUnoService("com.sun.star.frame.Desktop")
	oDocument = ThisComponent
	oSelection = oDocument.CurrentSelection
	If oSelection.ImplementationName <> "SwXTextGraphicObject" Then
		MsgBox "Select image first..."
		Exit Sub
	End If
	nFactor = InputBox("Resize factor in %:","Resizing picture...",50)
	If Not(IsNumeric(nFactor)) Then Exit Sub
	nFactor = Val(nFactor)/100
	Dim oSize as new com.sun.star.awt.Size
	oSize.Width = Int(oSelection.Width * nFactor)
	oSize.Height = Int(oSelection.Height * nFactor)
	oSelection.setSize(oSize)
End Sub
Hope it helps!
Uros
User avatar
Tommy
Posts: 251
Joined: Sun Dec 23, 2007 2:44 pm

Re: [REQ] resize image to 50%

Post by Tommy »

:lol: this macro kicks ass :lol:

you should submit it to: http://www.ooomacros.org/index.php

thank you for your help!!!
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
Posts: 251
Joined: Sun Dec 23, 2007 2:44 pm

Re: [solved] resize image to 50%

Post by Tommy »

come on uros, you should really submit this macro to OOoMacros
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
Posts: 251
Joined: Sun Dec 23, 2007 2:44 pm

Re: [solved] resize image to 50%

Post by Tommy »

if you copy and paste and image from Draw into Writer, the "resize macro" doesn't work on that image.

should i create another macro for such operation? should i edit the original macro?

if anbody has an answer, please tell me
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
Posts: 251
Joined: Sun Dec 23, 2007 2:44 pm

Re: [Solved] resize image to 50%

Post by Tommy »

nevermind.

i found here the solution. ( http://groups.google.it/group/it-alt.co ... 6162de7245 )

here's the DrawImageResize macro.
credits to martello

Code: Select all

Sub DrawImageResize 
        Dim oSize as new com.sun.star.awt.Size 
        oDocument = ThisComponent 
        oSelection = oDocument.CurrentSelection 
        sel=oSelection.getByIndex (0) 
        nFactor = InputBox("Resize factor in %:","Resizing picture...",50) 
    If Not(IsNumeric(nFactor)) Then Exit Sub 
    nFactor = Val(nFactor)/100 
        oSize.Width = Int(sel.size.Width * nFactor) 
        oSize.Height = Int(sel.size.Height * nFactor) 
        sel.setSize(oSize) 
End Sub
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
guy2kool
Posts: 1
Joined: Mon Mar 21, 2011 1:55 am

Re: [Solved] Resize image to 50%

Post by guy2kool »

Hello,

This was a great thread, thanks to Uros. I know it's quite a few years ago, but I was hoping on being able to resize the image into a standard "inch by inch" format.

Like I would like a macro that would resize the picture to 3" x 5" on writer. Although I appreciate uros' code for 50%, I was hoping on something like 3" x 5" in inches or in pixels is fine also. The reason why is that I receive a bunch of pictures that are different sizes.

Someone Please help!!! Thanks so much in advanced.
OpenOffice 3.3.0 on Windows 7 x64 Ultimate
User avatar
Tommy
Posts: 251
Joined: Sun Dec 23, 2007 2:44 pm

Re: [Solved] Resize image to 50%

Post by Tommy »

I'm not a big macro expert but I think that uros macro can be changed to obtain what you desire.

just taking a look to the code, I think that the crucial point is:

Code: Select all

nFactor = InputBox("Resize factor in %:","Resizing picture...",50)
   If Not(IsNumeric(nFactor)) Then Exit Sub
   nFactor = Val(nFactor)/100
   Dim oSize as new com.sun.star.awt.Size
   oSize.Width = Int(oSelection.Width * nFactor)
   oSize.Height = Int(oSelection.Height * nFactor)

I think that we should modify the nFactor from a % value to a fixed value for width and lenght
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
Post Reply