Jump to content

Macro To Convert Myriad Picture Files


Recommended Posts

Hello, I am fairly new to programming, but I have a lot of experience with computers. I am simply looking for a way to make a terribly mundane task take care of itself.

I am looking to be able to write a macro that will go through all the pictures that I have in a particular folder (10,000+ images), open each individual image in Paint (but only if the image is jpg or bmp, and not gif & png) resave the image as a png to the same directory, then close Paint and move on to the next.

I would like to be able to indicate the directory in the script and I would like the script to be able to distinguish between the different image formats (and only open the appropriate ones in Paint for re-saving as png).

I am looking for a more advanced way of doing this, meaning more than simply mouse position on the screen and having it click the appropriate item. Ideally, it would use the titles of the objects (such as the paint window to recognize when it has loaded the image, and the name of the save as > png identifiers) and be able to select them without inhibiting the mouse, So if necessary I could perform another task while this is going on. A pause feature would be nice also if I needed to perform another task while it is operating (but this is less crucial). Deleting the original jpg & bmp files could be in the script or not, either way (as that is easy enough to do once they are all converted...yay sort by > type feature)

Also, would there be any way to build in a shortcut key that I could turn on or off at any time throughout its running that would make the new instance of Paint appear on top or behind all other windows, so it could run in the "background" when it opens a new image or when it opens up a new image it could be on top?

Note: I am not simply looking to change the .jpg or .bmp extensions at the end of the image...changing the extension does no re-encode the image and often leads to damaged images, reduced quality, etc.

Thanks in advance for anyone who is willing to help me with this project, I think this could be a very useful tool.

(I just downloaded AutoIT two days ago so I don't really know all it is capable of yet. Seems very extensive and an easy to understand language though, so I hope this won't be too difficult of a project)

Link to comment
Share on other sites

You might find that easier by using AutoIt to find the files and pass them to ImageMagick to do the conversion.

There are many examples posted on this forum (which also has a working search, BTW).

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You might find that easier by using AutoIt to find the files and pass them to ImageMagick to do the conversion.

There are many examples posted on this forum (which also has a working search, BTW).

:mellow:

Thanks for the link, but I really don't want another image program on my computer...I already have Paint, Windows Picture & Fax Viewer, Fireworks, Photoshop, and Ifranview (for gif, ico, etc). I really just want something that can automate my converting them (since Paint is the simplest, I would like to just use that).

Yeah, I always use the search function first (thanks for not being sh*tty about it anyway, lol), but I didn't find anything related to what I am actually looking to do with helpful examples or anything...which is why I registered and posted =)

Link to comment
Share on other sites

Thanks for the link, but I really don't want another image program on my computer...I already have Paint, Windows Picture & Fax Viewer, Fireworks, Photoshop, and Ifranview (for gif, ico, etc). I really just want something that can automate my converting them (since Paint is the simplest, I would like to just use that).

Yeah, I always use the search function first (thanks for not being sh*tty about it anyway, lol), but I didn't find anything related to what I am actually looking to do with helpful examples or anything...which is why I registered and posted =)

Lucky you said you had IrfanView, the main exe can use command line parameters to convert a picture silently.

Example: i_view32.exe C:\Image1.jpg /convert=C:\Image1.png

#include<file.au3> ;This allow us to use the _FileListToArray function.

HotKeySet("!{Esc}","_Exit") ;Alt+Escape exits the program.

$FolderPath = "C:\Temp\" ;Change this to the path of your pictures, the last backslash is super important.

$Jpgs = _FileListToArray($FolderPath, "*.jpg", 1) ;Creates an array of all jpgs in the folder specified above.

If Not @error Then
    For $Count = 1 To $Jpgs[0] ;Loop through all pictures
        ShellExecuteWait("C:\Program Files\IrfanView\i_view32.exe", $FolderPath & $Jpgs[$Count] & " /convert=" & $FolderPath & StringReplace($Jpgs[$Count],".jpg",".png",1,2))
        ;ShellExecuteWait("C:\Program Files\IrfanView\i_view32.exe","C:\Image1.jpg /convert=C:\Image1.png")
        ToolTip("Completed: " & $Count &" of "&$Jpgs[0],10,10)
        Sleep(1250)
        ToolTip("")
    Next
    MsgBox(0,"Conversion Completed","Fin!")
Else
    MsgBox(0, "Error", "Unable to find jpegs")
EndIf
Func _Exit()
    Exit
EndFunc

Tested with the latest version of IrfanView.

Edited by BitByteBit
Link to comment
Share on other sites

Lucky you said you had IrfanView, the main exe can use command line parameters to convert a picture silently.

...

Tested with the latest version of IrfanView.

Wow, it works perfectly! Thank you for showing me a better way to do it! (I see now that my way would have been terribly cumbersome) I didn't even realize that Irfanview had that capability, pretty cool. I wanted to write it myself, but this is probably better, now I can work backwards and figure out why everything works the way it does =)

Thank you so much again BitByteBit, you just saved me probably a hundred or so hours!

Link to comment
Share on other sites

  • 1 month later...

Thanks for the example script... it's close to what I needed as well.

I wanted to be able to right-click on png files to convert them to jpg files (posters for movie jukebox).

I can work with this now to get what I need from it.

there are examples to add functionality to right click also, i think i even wrote one a while back. so you can put your conversion script on your right click menu based on extension.
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...