| View previous topic :: View next topic |
| Author |
Message |
tic
Joined: 22 Apr 2007 Posts: 1353
|
Posted: Mon May 05, 2008 2:21 am Post subject: ConvertImage() Convert and resize images with 1 function |
|
|
ConvertImage()
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:
| Code: | | 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:
| Code: | ; Convert "in.jpg" to "out.png" and keep same size
ConvertImage("in.jpg", "out.png") |
| Code: | ; Convert "in.jpg" to "out.png" and make it 200x100 pixels
ConvertImage("in.jpg", "out.png", 200, 100, "Pixels") |
| Code: | ; 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") |
| Code: | ; 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
Last edited by tic on Thu May 29, 2008 4:17 pm; edited 3 times in total |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 903 Location: The Interwebs
|
Posted: Thu May 29, 2008 3:43 am Post subject: |
|
|
Wonderful script, already making a simple GUI for myself to support it
One question; going through the function, I notice many different possible return values. I'm assuming these are for different errors, in which case could you tell me what the various values might mean?
Edit: Also, one more question >< Is this function enabled for using -1 as one dimension to maintain aspect ratio, or is it necessary to calculate it manually? |
|
| Back to top |
|
 |
biotech
Joined: 24 Feb 2006 Posts: 145
|
Posted: Thu May 29, 2008 8:42 am Post subject: |
|
|
great script!
is it possible to change just height or width? and image to be resized
repecting original aspect? |
|
| Back to top |
|
 |
Sarah
Joined: 12 Jul 2007 Posts: 90 Location: Hawaii, USA
|
Posted: Thu May 29, 2008 11:52 am Post subject: |
|
|
Hey, that is handy. Very nice job and well done. I posted a different thread, but on GDI topic in the main group. It would be neat to see some of what I was asking evolve into this (image composite layering & joining) Have a very nice day! |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1353
|
Posted: Thu May 29, 2008 4:11 pm Post subject: |
|
|
| Krogdor wrote: | Wonderful script, already making a simple GUI for myself to support it
One question; going through the function, I notice many different possible return values. I'm assuming these are for different errors, in which case could you tell me what the various values might mean? |
I have added the return values to the top of the function now
| biotech wrote: | great script!
is it possible to change just height or width? and image to be resized
repecting original aspect? |
Good idea. -1 may now be specified for either Width or Height to maintain aspect ratio. |
|
| Back to top |
|
 |
biotech
Joined: 24 Feb 2006 Posts: 145
|
Posted: Thu May 29, 2008 9:28 pm Post subject: |
|
|
one more thing...i have monochrome tiff with 200kb in size when i resize them they appear much bigger over 2Mb and they are now 32-bits tiffs...is there a way to maintain original 1-bit tiff after resize. if so this i would probably use this script because it is going to be the most easiest way of doing this...
thanks! |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 903 Location: The Interwebs
|
Posted: Thu May 29, 2008 11:33 pm Post subject: |
|
|
| tic wrote: |
I have added the return values to the top of the function now
...
Good idea. -1 may now be specified for either Width or Height to maintain aspect ratio. |
Great, thanks :3 |
|
| Back to top |
|
 |
Bral
Joined: 29 Sep 2007 Posts: 1
|
Posted: Sun Aug 24, 2008 1:33 am Post subject: |
|
|
| How to adjust image quality? |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1353
|
Posted: Sun Aug 24, 2008 4:04 pm Post subject: |
|
|
| Check out the gdi+ library. This function has been superceded by it |
|
| Back to top |
|
 |
|