Page 1 of 1

[Solved] Resize image to 50%

Posted: Sun Dec 23, 2007 5:23 pm
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?

Re: [REQ] resize image to 50%

Posted: Sun Dec 23, 2007 9:15 pm
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

Re: [REQ] resize image to 50%

Posted: Sun Dec 23, 2007 11:18 pm
by Tommy
:lol: this macro kicks ass :lol:

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

thank you for your help!!!

Re: [solved] resize image to 50%

Posted: Wed Dec 26, 2007 5:59 am
by Tommy
come on uros, you should really submit this macro to OOoMacros

Re: [solved] resize image to 50%

Posted: Sun May 18, 2008 1:26 pm
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

Re: [Solved] resize image to 50%

Posted: Tue May 27, 2008 10:06 pm
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

Re: [Solved] Resize image to 50%

Posted: Mon Mar 21, 2011 2:04 am
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.

Re: [Solved] Resize image to 50%

Posted: Mon Mar 21, 2011 10:39 pm
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