Sign in to follow this  
Followers 0
beernuts

MSPaint thumbnail snippet

2 posts in this topic

This code takes the file and pathname from edit1 infobox in my GUI and sends it to MSpaint to make a thumbnail 200 pixels high and saves that thumbnail in the same place as the original file but rewrites the file name to include "_thumb.jpg" There's a tiny bit of math in it to maintain the correct aspect ratio allthough sometimes the picture will be cropped a tiny bit, 2 pixels max. If you want the height to be different than 200 you could call another value from your GUI or change the value in $heightfixer in the code.

$thumbnameandpath = ControlGetText("My GUI" , "" , "Edit1") 
    
    $digitsinthumbpath = StringLen($thumbnameandpath)
    $numberfromleftinfilename = StringInStr($thumbnameandpath, "\" ,0, -1)
    $OriginalFNNoPath= stringtrimleft($thumbnameandpath, $numberfromleftinfilename)
    
    
    
    
    
    
    $cutthumbextension = StringTrimRight($thumbnameandpath, 4)
    $newthumbname = $cutthumbextension & "_thumb.jpg"
    
                                            
                                                                        
                run("mspaint.exe")
                WinWaitActive("untitled - Paint")
                send("^o")
                WinWaitActive("Open")
                send($thumbnameandpath)
                sleep(1000)
                send("!o")
                
                WinWaitActive($OriginalFNNoPath)
                send("^e")
                WinWaitActive("Attributes")

                $originalwidth  = ControlGetText("Attributes", "", "Edit1")
                $originalheight = ControlGetText("Attributes", "", "Edit2")
                send("{ENTER}")
                WinWaitActive($OriginalFNNoPath)
                send("^w")
                WinWaitActive("Stretch and Skew")

                $heightfixer = 200 / $originalheight
                $heightpercentshrink = $heightfixer * 100
                $newpercentage = Ceiling($heightpercentshrink)
                Send($newpercentage)
                sleep(500)
                send("{TAB}")
                sleep(500)
                Send($newpercentage)
                sleep(500)
                send("{ENTER}")
                WinWaitActive($OriginalFNNoPath)
                send("^e")
                WinWaitActive("Attributes") 
                send("{TAB}")
                sleep(500)
                Send("200")
                sleep(500)
                                
                                        
                                        

                                            
                send("{ENTER}")
                WinWaitActive($OriginalFNNoPath)
                            
                send("!f")
                sleep(200)
                send("a")
                WinWaitActive("Save As")
                send($newthumbname)
                sleep(500)
                send("!s")
                sleep(2000)
                send("!{F4}")

Share this post


Link to post
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
Sign in to follow this  
Followers 0