AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ConvertImage() Convert and resize images with 1 function

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
tic



Joined: 22 Apr 2007
Posts: 1353

PostPosted: Mon May 05, 2008 2:21 am    Post subject: ConvertImage() Convert and resize images with 1 function Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 903
Location: The Interwebs

PostPosted: Thu May 29, 2008 3:43 am    Post subject: Reply with quote

Wonderful script, already making a simple GUI for myself to support it Very Happy

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
View user's profile Send private message AIM Address
biotech



Joined: 24 Feb 2006
Posts: 145

PostPosted: Thu May 29, 2008 8:42 am    Post subject: Reply with quote

great script!
is it possible to change just height or width? and image to be resized
repecting original aspect?
Back to top
View user's profile Send private message
Sarah



Joined: 12 Jul 2007
Posts: 90
Location: Hawaii, USA

PostPosted: Thu May 29, 2008 11:52 am    Post subject: Reply with quote

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) Smile Have a very nice day!
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1353

PostPosted: Thu May 29, 2008 4:11 pm    Post subject: Reply with quote

Krogdor wrote:
Wonderful script, already making a simple GUI for myself to support it Very Happy

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
View user's profile Send private message
biotech



Joined: 24 Feb 2006
Posts: 145

PostPosted: Thu May 29, 2008 9:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 903
Location: The Interwebs

PostPosted: Thu May 29, 2008 11:33 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Bral



Joined: 29 Sep 2007
Posts: 1

PostPosted: Sun Aug 24, 2008 1:33 am    Post subject: Reply with quote

How to adjust image quality?
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1353

PostPosted: Sun Aug 24, 2008 4:04 pm    Post subject: Reply with quote

Check out the gdi+ library. This function has been superceded by it
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group