Jump to content

Image Converter


Generator
 Share

Recommended Posts

Image Converter

Features:

  • Convert Multi Image Files at Once
  • Many extension Selectable, JPG, BMP, TIF, GIF, PNG
  • Friendly user interface
  • High performance, reduce sleep if needed
  • Checkbox system ;Thanks to smashly
  • Multi-Images Drag&Drop ;Thanks to smashly
  • It's in AutoIt ;D, big thanks to GaryFrost for the Library update
Known Issues:

  • None
Source Code:

;See Attachment
Edited by Generator
Link to comment
Share on other sites

@Generator

I did this while trying to fix the preview bug for you, I could'nt fix it, maybe it a bug with the latest autoit...

Well Generator you may use this as you want just please give credit...

NO BODY EXCEPT GENERATOR CAN USE THIS WITHOUR HIS PERMISSON AS ITS HIS SCRIPT.

#include <GUIConstants.au3>
#include <GUIComboBox.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#NoTrayIcon
_Singleton("Image Converter")
Opt("GUIOnEventMode", 1)
Global $savedir = @DesktopDir & "\", $Valid
Global $Image, $readpic
Dim $oTypes, $oFiles[3], $hFiles[1]
$mainfrm = GUICreate("Image Converter", 544, 355, 193, 125, $WS_MINIMIZEBOX + $WS_CAPTION + $WS_SYSMENU, $WS_EX_ACCEPTFILES + $WS_EX_CLIENTEDGE)
$Dirinput = GUICtrlCreateInput($savedir, 8, 8, 425, 25, $ES_READONLY)
$Browse = GUICtrlCreateButton("Browse", 440, 8, 97, 25, 0)
$FileList = GUICtrlCreateListView("File Name|File Directory|File Size", 8, 40, 249, 273, $LVS_SHOWSELALWAYS, $WS_EX_ACCEPTFILES)
$FileType = GUICtrlCreateCombo("", 264, 40, 273, 30, $CBS_DROPDOWNLIST)
GUICtrlSetData($FileType, "PNG|JPG|BMP|TIF|GIF", "PNG")
_GUICtrlComboBox_SetCurSel($FileType, 0)
$Group = GUICtrlCreateGroup("Image Preview", 264, 64, 273, 248)
$Convert = GUICtrlCreateButton("Convert Images Now", 8, 315, 124, 19, 0)
$Preview = GUICtrlCreateButton("Preview", 135, 315, 124, 19, 0)
$Progress = GUICtrlCreateProgress(264, 315, 273, 25)
$Input1 = GUICtrlCreateInput("", 8, 335, 250, 17)
GUICtrlSetFont($Dirinput, 9, 400, 0, "Tahoma")
GUICtrlSetFont($Browse, 9, 400, 0, "Tahoma")
GUICtrlSetFont($FileType, 9, 400, 0, "Tahoma")
GUICtrlSetFont($Convert, 9, 400, 0, "Tahoma")
GUICtrlSetOnEvent($Browse, "_Browse")
GUISetOnEvent($GUI_EVENT_DROPPED, "_DropFile")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Bye")
GUICtrlSetState($FileList, $GUI_DROPACCEPTED)
GUICtrlSetOnEvent($Convert, "_Convert")
GUICtrlSetOnEvent($Preview, "_Preview")



GUISetState()
$oTypes = _ArrayCreate("PNG", "JPG", "BMP", "TIF", "GIF")
_GDIPlus_Startup()
While 1
    Sleep(1)
WEnd
Func _Browse()
    $savedir = FileSelectFolder("", "", 1)
    If @error = 1 Then
        Return
    Else
        GUICtrlSetData($Dirinput, $savedir & "\")
    EndIf
EndFunc   ;==>_Browse
Func _DropFile()
    _GetFileData()
    If $Valid Then
        $hFiles[UBound($hFiles) - 1] = _GDIPlus_ImageLoadFromFile($oFiles[1])
        GUICtrlCreateListViewItem($oFiles[0] & "|" & $oFiles[1] & "|" & $oFiles[2], $FileList)
        GUICtrlSetData($Input1, $oFiles[1])
        GUICtrlSetOnEvent(-1, "_Preview")
        ReDim $hFiles[UBound($hFiles) + 1]
    EndIf
EndFunc   ;==>_DropFile
Func _GetFileData()
    Local $oSplit, $iSplit, $iCount
    $oSplit = StringSplit(@GUI_DragFile, ".")
    For $i = 0 To UBound($oTypes) - 1
        If StringUpper(String($oSplit[$oSplit[0]])) = $oTypes[$i] Then
            $Valid = 1
            ExitLoop
        Else
            $Valid = 0
        EndIf
    Next
    If Not $Valid Then
        _MsgBox(64, "Invalid File Format", "Please Drag Image file Only", $mainfrm)
        Return
    EndIf
    $iSplit = StringSplit($oSplit[1], "\")
    $iCount = UBound($iSplit, 1) - 1
    If $oFiles[1] = String(@GUI_DragFile) Or _Check() Then
        $Valid = 0
        Return
    EndIf
    $oFiles[0] = String($iSplit[$iCount])
    $oFiles[1] = String(@GUI_DragFile)
    $oFiles[2] = Round(FileGetSize(@GUI_DragFile) / 1024, 1) & "Kb"
EndFunc   ;==>_GetFileData
Func _MsgBox($iFlags, $sTitle, $sText, $hWnd)
    Local $aRet = DllCall('user32.dll', 'int', 'MessageBox', 'hwnd', $hWnd, 'str', $sText, 'str', $sTitle, 'uint', $iFlags)
    Return $aRet[0]
EndFunc   ;==>_MsgBox
Func _Preview()
    GUICtrlDelete($Image)
    $readpic = GUICtrlRead($Input1)
    $Image = GUICtrlCreatePic($readpic, 272, 80, 257, 220)
    EndFunc   ;==>_Preview
Func _Bye()
    _GDIPlus_ShutDown()
    Exit
EndFunc   ;==>_Bye
Func _Check()
    For $i = 0 To _GUICtrlListView_GetItemCount($FileList)
        If _GUICtrlListView_GetItemText($FileList, $i, 1) = String(@GUI_DragFile) Then
            Return True
        EndIf
    Next
EndFunc   ;==>_Check
Func _Convert()
    If _GUICtrlListView_GetItemCount($FileList) = 0 Then Return
    GUICtrlSetState($Convert, $GUI_DISABLE)
    GUICtrlSetData($Convert, "Converting..Please Wait..")
    Local $Ext = _GDIPlus_EncodersGetCLSID($oTypes[_GUICtrlComboBox_GetCurSel($FileType)])
    Local $iMod = 100 / _GUICtrlListView_GetItemCount($FileList)
    For $i = 0 To _GUICtrlListView_GetItemCount($FileList)
        GUICtrlSetData($Progress, $iMod * $i)
        _GDIPlus_ImageSaveToFileEx($hFiles[$i], $savedir & _GUICtrlListView_GetItemText($FileList, $i, 0) & "." & StringLower($oTypes[_GUICtrlComboBox_GetCurSel($FileType)]), $Ext, 0)
        Sleep(800)
    Next
    GUICtrlSetData($Progress, 0)
    GUICtrlSetState($Convert, $GUI_ENABLE)
    GUICtrlSetData($Convert, "Convert Images Now")
EndFunc   ;==>_Convert

well thats all i can think of it very nice.

Link to comment
Share on other sites

@Generator

I did this while trying to fix the preview bug for you, I could'nt fix it, maybe it a bug with the latest autoit...

Well Generator you may use this as you want just please give credit...

NO BODY EXCEPT GENERATOR CAN USE THIS WITHOUR HIS PERMISSON AS ITS HIS SCRIPT.

So are you giving him permission to use his script and demanding credit? or did you want credit for your non working version of his script? :P

Link to comment
Share on other sites

For me it does not work, it says i need "GUIComboBox.au3" and "GDIPlus.au3"

I already have the latest beta :P

You need v3.2.10.0 which is released at homepage

About Image Viewer see:

here

Fixed preview, not sure how is this related to that topic

Have you an example on how to reduce the number of color and how to crop an image ?

Thanks

Use

#Include <GDIPlus.au3>
_GDIPlus_BitmapCloneArea($hBmp, $iLeft, $iTop, $iWidth, $iHeight[, $iFormat = 0x00021808])

@Generator

Perfect, but I am in need of an image RESIZER to schrink the size to the files.

would that be possible to add ?

regards,

ptrex

Not unless I know a way to do it.

Vrey nice, soemtime when i open the converted image it cannot preview...

but if i make it do 2 at any one time then thats fixed...

and im not on about the prieview that you cannot get working, im taking about when it click on where i saved it.

Preview Fixed, it was _GDIPlus_ImageLoadFromFile, now it works in another order and better.

Edit: Problem solved.

P.S: Preview only supports BMP, JPG

Edited by Generator
Link to comment
Share on other sites

Hi,

Nice work

For Delete you can delete a selected item in the listview with GUICtrlDelete(GUICtrlRead($FileList))

To delete all items in your listview _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($FileList))

Suggestions:

Add muti file drag and drop.

Set the Gui to Topmost so I'm not chasing the window while dropping files.

Cheers

Edited by smashly
Link to comment
Share on other sites

Hi,

Nice work

For Delete you can delete a selected item in the listview with GUICtrlDelete(GUICtrlRead($FileList))

To delete all items in your listview _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($FileList))

Suggestions:

Add muti file drag and drop.

Set the Gui to Topmost so I'm not chasing the window while dropping files.

Cheers

Thanks for the info, updated as described.
Link to comment
Share on other sites

Thanks for the info, updated as described.

Sorry my bad missiformation about the DeleteAll ..

After reading some of the other forum posts in regaurds to deleting all listview items I think you should be using something like

While _GUICtrlListView_GetItemCount($FileList) > 0
    _GUICtrlListView_SetItemSelected($FileList, 0, True)
    GUICtrlDelete(GUICtrlRead($FileList))
WEnd

Cheers

Link to comment
Share on other sites

Sorry my bad missiformation about the DeleteAll ..

After reading some of the other forum posts in regaurds to deleting all listview items I think you should be using something like

While _GUICtrlListView_GetItemCount($FileList) > 0
    _GUICtrlListView_SetItemSelected($FileList, 0, True)
    GUICtrlDelete(GUICtrlRead($FileList))
WEnd

Cheers

agreed

Link to comment
Share on other sites

Thank you for the updates

Seems to be working good ftm , the preview works nicely and the context remove/remove all makes it user friendly.

Suggestions:

Add another column called Pixels to the $FileList listview and put the Dimension of the image.. eg: WxH

Add checkboxes in the the $FileList listview. This way a user can select the the files to be processed or removed by checking or unchecking the items in the list.

Add the option to SelectAll/UnSelectAll. (would be handy if checkboxes idea was implemented)

Add MultiDrop files and and use a filter so that only supported picture files will be added.

Doing the filter part makes the msg box redundant and you can also catch dupes in the process so there not added again to the list.

I find single 1 at a time adding images is slow and tedious when you want to drop 20 + pics.

Add drop a folder in the save path field...

Edit: Add checkbox to gui so when it's checked it opens output folder when the coversion is done

I've actually added these above features already to a modified version of your script.

And it really speeds up my use of the interface.

I open a folder, press Ctrl + A and drag the contents of the folder into your interface.

Out of 200+ files/folders dropped 65 are actual images..

Bam.. 65 images in the list with no nags..

I then select by clicking the checkboxes.

I drag the output folder I want the pics saved to into the save field and hit convert..

After selected images are converted I the hit the remove and the selected images are removed

I do the same process again on the images that are left because I want them in a different directory..

Sometimes I drop an archive and I realize it's the wrong archive of images ..

I then Select All and hit Remove..

It's really quite functional using multi drop and checkboxes with dupe and filter checking when dropping files:)

Cheers

Edited by smashly
Link to comment
Share on other sites

Thank you for the excellent update, damn your IC is rockin' .. w00t.

Nice work

I worked out how to do the resize option , as well as use a small preview using gdi instead of ie..

Which means icon previewing works, with just about any other format for previewing.

In the mean time I've dropped the copression/quality/dpi settings till I tidy up the resize functions a bit more ..

But I added some other trivial options instead :P

Will post the updates shortly...

Between both our scripts and other user input you'll end up making a full blown imaging tool in autoit.

Hmm, I think I'm getting ahead myself again.. lol

Cheers

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...