ConvertImage() can be used to convert from any image format supported by gdi+ to any other format also supported (jpg,bmp,png,tiff,gif). It can also resize the image either by directly specifying the width and height in pixels of the destination image, or by specifying a percentage of the source image.
Many thanks to PhiLho, Lexikos and Sean
Usage:
ConvertImage(sInput, sOutput, Width="", Height="", Method="Percent")
sInput: Location of the input file to be converted. May be of filetype jpg,bmp,png,tiff,gif
sOutput: Location to save the converted file. Extension determines the output filetype jpg,bmp,png,tiff,gif
Width: Width either in pixels or percentage (depending on Method) to save the converted file
Height: Height either in pixels or percentage (depending on Method) to save the converted file
Method: Can either be "Percent" or "Pixels" to determine the width and height of the converted file
Examples:
; Convert "in.jpg" to "out.png" and keep same size ConvertImage("in.jpg", "out.png")
; Convert "in.jpg" to "out.png" and make it 200x100 pixels ConvertImage("in.jpg", "out.png", 200, 100, "Pixels")
; Convert "in.png" to "out.bmp" and make it 1/2 the width (50%) and twice the height (200%) ConvertImage("in.png", "out.bmp", 50, 200, "Percent")
; Convert "in.png" to "out.bmp" and make it 200 pixels wide, whilst maintaining aspect ratio ConvertImage("in.png", "out.bmp", 200, -1, "Pixels")
Function with working example:
gdi+ must first be started as shown in the example script.
ConvertImage.ahk