AutoHotkey Community

It is currently May 26th, 2012, 7:32 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: May 5th, 2008, 2:21 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
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 May 29th, 2008, 4:17 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2008, 3:43 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Wonderful script, already making a simple GUI for myself to support it :D

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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2008, 8:42 am 
Offline

Joined: February 24th, 2006, 12:56 am
Posts: 172
great script!
is it possible to change just height or width? and image to be resized
repecting original aspect?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2008, 11:52 am 
Offline

Joined: July 12th, 2007, 10:24 pm
Posts: 103
Location: Hawaii, USA
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2008, 4:11 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Krogdor wrote:
Wonderful script, already making a simple GUI for myself to support it :D

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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2008, 9:28 pm 
Offline

Joined: February 24th, 2006, 12:56 am
Posts: 172
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2008, 11:33 pm 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2008, 1:33 am 
Offline

Joined: September 29th, 2007, 4:37 pm
Posts: 1
How to adjust image quality?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2008, 4:04 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Check out the gdi+ library. This function has been superceded by it


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 8:13 am 
Offline

Joined: April 27th, 2008, 5:28 pm
Posts: 489
How can I use a variable in this
Code:
ConvertImage("in.jpg", "out.png")


My variable for example would be
Code:
Mylistbox = Pic.jpg ; I want to convert it to Pic.bmp
;this does not work
ConvertImage(mylistbox,mylistbox.bmp)

_________________
Check out my scripts.
(MyIpChanger) (XPSnap) (SavePictureAs)

All my scripts are tested on Windows 7, AutoHotkey_L 32 bit Ansi unless otherwise stated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 10:00 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Code:
ConvertImage(mylistbox,"mylistbox.bmp")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 1:56 pm 
Offline

Joined: April 27th, 2008, 5:28 pm
Posts: 489
SKAN wrote:
Code:
ConvertImage(mylistbox,"mylistbox.bmp")
I wanted to retain the original filename but converted to bmp. This converts the image to mylistbox.bmp

_________________
Check out my scripts.
(MyIpChanger) (XPSnap) (SavePictureAs)

All my scripts are tested on Windows 7, AutoHotkey_L 32 bit Ansi unless otherwise stated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 1:59 pm 
Offline

Joined: September 17th, 2006, 6:15 pm
Posts: 85
Location: Munique/Germany
Try
Code:
Mylistbox = Pic
ConvertImage(mylistbox . ".jpg",mylistbox . ".bmp")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 2:24 pm 
Offline

Joined: April 27th, 2008, 5:28 pm
Posts: 489
oliver.lipkau wrote:
Try
Code:
Mylistbox = Pic
ConvertImage(mylistbox . ".jpg",mylistbox . ".bmp")
Mylistbox is a variable defined somewhere else in my script. It already includes the absolute path and filename. If I make Mylistbox = pic then it would be converting pic.jpg which does not exist.

Am I correct?

_________________
Check out my scripts.
(MyIpChanger) (XPSnap) (SavePictureAs)

All my scripts are tested on Windows 7, AutoHotkey_L 32 bit Ansi unless otherwise stated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 2:26 pm 
Offline

Joined: September 17th, 2006, 6:15 pm
Posts: 85
Location: Munique/Germany
DataLife wrote:
oliver.lipkau wrote:
Try
Code:
Mylistbox = Pic
ConvertImage(mylistbox . ".jpg",mylistbox . ".bmp")
Mylistbox is a variable defined somewhere else in my script. It already includes the absolute path and filename. If I make Mylistbox = pic then it would be converting pic.jpg which does not exist.

Am I correct?

take a look at SplitPath or StringTrimLeft


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, Yahoo [Bot] and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group