Jump to content

Resize Image


Recommended Posts

I spent some time with the search function today, downloading UDF's and trying different things out,.. but I can't find what I am looking for. It's probably because I don't know how to ask (the search function) or the solution is so simple that no one comments on it. So sorry in advance.

How can I resize an image? I'm not to worried about its format at this point because I think that PaulIA's Auto3Lib will do that for me. I am looking for something like this:

ImageResize ("Source Path", "Destination Path", Pixelwidth, PixelHeight)

If someone could show me what I am missing I would really appreciate it.

Edited by MagnumXL
Link to comment
Share on other sites

i am using nconvert as active x control which has the best resampler i could find in freeware

CODE
;

;

; light image converter

; using nconvert ACTIVEx now

;

; http://perso.orange.fr/pierre.g/xnview/de_downloadgfl.html

;

; all api functions can be taken from the help CHM file, which is extensive

;

;

; to register the active X control do this :

; copy GflAx.dll c:\winnt\system32

; regsvr32.exe GflAx.dll

;

; author nobbe, june 2007

;

;

#include <GUIConstants.au3>

$Form1 = GUICreate("nconvert sample", 633, 454, 193, 115, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPCHILDREN)

Dim $filemenu = GUICtrlCreateMenu("&File")

Dim $fileitem = GUICtrlCreateMenuitem("Open", $filemenu)

Dim $widthTh, $heightTh

$Height1 = 150

$Width1 = 150

$Obj1_ctrl = GUICtrlCreatePic("", 120, 32, $Width1, $Height1)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $fileitem

;MsgBox(0,"","msg")

$file = FileOpenDialog("Choose file...", @ScriptDir, "Picture Files (*.*)")

If @error <> 1 Then pic_Open($file)

EndSwitch

WEnd

Func pic_Open($file)

GUICtrlDelete($Obj1_ctrl)

$newFile = resample($file, $Width1, $Height1)

$Obj1_ctrl = GUICtrlCreatePic(@ScriptDir & "\100_a.jpg", 120, 32, $widthTh, $heightTh)

; MsgBox(0,"",$file)

EndFunc ;==>pic_Open

;

; just resample the picture 1/4 of its orig size and save with diff qualities

;

Func resample($file, $Width1, $Height)

; the nconvert GFX api - if this fails you need to register the control first

$imgObject = ObjCreate("GflAx.GflAx")

If $imgObject <> 0 Then

$imgObject.LoadBitmap ($file);

$widthOrig = $imgObject.Width ()

$heightOrig = $imgObject.Height ()

;MsgBox(0, "", $widthOrig & "x" & $heightOrig)

$widthTh = Int($widthOrig / 4) ; 1/4 of original

$heightTh = Int($heightOrig / 4)

;var olecolor = red + (green * 256) + (blue * 65536);

; original RGB colors

$r = 255;

$g = 0;

$b = 255;

$olecolor = $r + ($g * 256) + ($b * 65536);

$imgObject.TextOut ("Test2 ", 50, 500, $olecolor) ; OLE_COLOR

; $imgObject.Sharpen(90)

; resize object

$imgObject.Resize ($widthTh, $heightTh)

$imgObject.SaveFormat = 1 ; jpeg

$imgObject.SaveJPEGQuality = 100 ; 100 % quality

$imgObject.SaveBitmap (@ScriptDir & "\100_a.jpg")

$imgObject.SaveJPEGQuality = 70 ; % quality

$imgObject.SaveBitmap (@ScriptDir & "\70_a.jpg")

$imgObject.SaveJPEGQuality = 40 ; % quality

$imgObject.SaveBitmap (@ScriptDir & "\40_a.jpg")

$imgObject.SaveJPEGQuality = 10 ; % quality

$imgObject.SaveBitmap (@ScriptDir & "\10_a.jpg")

EndIf ; imgobj ==0

EndFunc ;==>resample

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...