Saturday, 21 July 2018

Intro to Autohotkey : How to scan old photo albums with ease using MS Paint.


Even if you are not going scan any photos, if you use a windows PC regularly, you need to know about AutoHotkey. Make any work easier. This is an awesome piece of software. I don't know how I missed it (and and the idea behind it) all my life. What it does is, it can execute a series of keystrokes and mouse clicks with the press of a single key of your choosing. Meaning, we can make the computer do all the repetitive menu navigation and entering of sequential filenames using AutoHotkey. It involves writing a bit of "code", but its easy kid level stuff, nothing like the word implies. Any one can learn to use it but if you are a system admin, this is a must-have. Set up some hotkeys for the other staff and your value will shoot through the roof.

I found AutoHotKey when I had to use Photoshop at work and Photoshop did not allow me to set keyboard shortcuts on the Numpad like how I use Gimp and I had to find a way to remap the Numpad keys to trigger Photoshop default hotkeys. Then I started to map entire sequence of Photoshop hotkeys to single keys. Soon enough, I was using it for all repetitive works. AutoHotKey is Free Open Source Software but it is available only for Windows.

I will show you how to use AutoHotKey in a photo scanning workflow where it has really helped me get work done without hassle.

So, you want to scan and convert your old family photo albums to Google Photo albums? What's the big deal? Just scan them, crop them, upload them right? Well...

  1. You got to take out all the photos from the albums.
  2. Lay down upto four photos each time on the scanner.
  3. Scan the photos.
  4. Crop the photos into individual pictures and save them.
  5. Take the photos off the scanner and put in the next four photos.
  6. After finishing put all the photos back in the album.
  7. Upload scanned photos to drive or photos.
Already looks much more complicated. There will be a lot of clicking through menus to scan the photos and a lot of typing of filenames for saving the individual files. If you have a lot of albums to scan, this will get real tedious.

There are no shortcuts for steps 1, 2, 5, 6 other than keeping the scanner on a stool or something next to you so that you can access the scan-bed while sitting down at your computer. For 3 and  4 we have AutoHotKey!

AutoHotKey (AHK)

Getting started

Get AHK from here. Go through the tutorials. Once installed you can start creating AHK scripts by right-clicking anywhere on the windows desktop or in any folder and selecting New>AutoHotkey Script. Name your script and then right-click on the script file and click Edit Script. The file will open in notepad. There will be some text in the header, ignore those and start writing your code below. When done save, exit notepad, right-click on the script file and click Run Script. An Icon with "H" will appear at the right end of your taskbar, meaning the script is running and your hotkeys are ready for use.

Making MS paint scan using a single key. 

First I need to find out how to make MS Paint scan using my keyboard alone and then note down the sequence of keys I need to press. For MS Paint it is File menu (Alt+f) just like most windows applications. Then Import image from scanner (m). Now my scanner's software dialog comes up and here I have to press down arrow three times to reach my preferred setting and then "Enter" to scan. Here is how to tell AHK how to do it.
s::
Send !f
Sleep 60
Send m
Sleep 400
Send {Down}
Sleep 100
Send {Down}
Sleep 100
Send {Down}
Sleep 100
Send {Enter}
Return
The key before the :: is the key that will trigger our sequence of commands. I have chosen "s" to be the hotkey. Send !f means send the keystroke equivalent of "Alt+f". ! means "Alt" and f is "f". Sleep 60 means wait 60 milliseconds before executing the next command. Without "Sleep", AHK will execute the commands in rapid succession without waiting for processes to complete or dialog boxes to open/close etc and the hotkey will fail. {Down} is "Down arrow key" and {Enter} is the "Enter" key. The Return at the end means that the commands for the Hotkey "s" are over. Its that easy with AHK. I am not a coder but I got the hang of it by day one. There are other alternatives to AHK like AutoIt and windows shell scripting which I heard are not so simple.

So type in the code like above in the new AHK script, save it and then run it. Now in MS Paint I hit "s". AHK speeds through the menus and dialogs and the scanner begins to scan and I get this.


I just need to rotate the picture to the right by 90 degrees before I start cropping.

Cropping, Saving and Un-Cropping

Using paint's select tool drag select one of the four photos, crop to selection(Ctrl+Shift+x), File menu (Alt+f), Save as menu (v), Save as Jpeg (j), Enter a unique filename, Save (Enter), Undo (Ctrl+z) to get back the other three photos lost while cropping.
e::
Send ^+x
Sleep 500
Send !f
Sleep 200
Send v
Sleep 200
Send j
Sleep 200
Send %A_Now%
Sleep 200
Send {Enter}
Sleep 500
Send ^z
Return
Now "e" will be our hotkey for cropping, saving and un-cropping. ^+x is Ctrl+Shift+x to crop to selection, then there is a long sleep of 500 milliseconds (half a second) for the cropping operation to complete. Everything is straight forward like the earlier code till we reach %A_Now%. This is the AHK code to enter the current time(YYYYMMDDHHMMSS). This will become the filename entered in the "Save as" dialog box. Timecode will give us a unique filename so that no previous files in the folder gets over-written and the files are in the same order as you scan and crop. Then it is {Enter} to save, a half second sleep for the save to complete then a ^z which is Ctrl+z to undo the crop so you can continue with cropping the other photos.

Together this is what the entire script looks like.
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#IfWinActive, ahk_class MSPaintApp
s::
Send !f
Sleep 60
Send m
Sleep 400
Send {Down}
Sleep 100
Send {Down}
Sleep 100
Send {Down}
Sleep 100
Send {Enter}
Return

#IfWinActive, ahk_class MSPaintApp
e::
Send ^+x
Sleep 500
Send !f
Sleep 200
Send v
Sleep 200
Send j
Sleep 200
Send %A_Now%
Sleep 200
Send {Enter}
Sleep 500
Send ^z
Return

#IfWinActive, ahk_class MSPaintApp
t::
Send ^+x
Sleep 500
Send !f
Sleep 200
Send v
Sleep 200
Send j
Sleep 200
Send %A_Now%
Return

You'll see there are a few extras here. The bunch of text in the begining is the header part which I mentioned earlier. Then #IfWinActive, ahk_class MSPaintApp, which makes the following hotkey work only when MS Paint is the active window. Then there is another hotkey "t" which is the same as "e" but stops right before hitting "Enter". I only need to use "t" when I need to select the folder before hitting save so that all the files saved later using "e" will go to that folder.

That's it! We did not need any photoshop or some other image processing software. Just MS Paint and some cheating using AHK. So get AHK, read their documentation, Spend some time to learn it.

Head this quote?
"Whenever there is a hard job to be done I assign it to a lazy man; he is sure to find an easy way of doing it."
That lazy man is you, with AutoHotKey.

Saturday, 7 July 2018

Blender VSE tip : Fixing aspect ratios for larger than stage images and footage.

Blender's VSE is really good considering its free but it fails at some basics. Like why does not an image with a different aspect ratio when imported to stage maintain its aspect ratio?


Yes you can check "Image offset" and correct it but only on images that are smaller in both width and/or height of the stage. On a larger image or video you either get a stretched image or a cropped one and no you can't get the cropped areas back by scaling it down.


So we are left with two options. One is to use another program to scale the image or footage to fit the stage resolution and the other is to correct it with the "Transform" effect strip. We are going to do the latter.

Side note: Use the Transform Effect strip to resize only when re-sampling quality is not that important and you just want something done fast. Read about it here.

An example problem is, you have a digital cam image which is of resolution 3200x2400 (4:3 aspect ratio) and you want to import it to your 1920x1080 (16:9 aspect ratio) stage. This causes it to stretch sideways. So you add a transform effect strip and scale along X axis till it looks right. But is it accurate? If you scaled X by 0.75 then yes, it is correct! So how do we get 0.75?

These formulae...

If image is stretched horizontally then scale along X axis by 

(Width of Image * Height of stage) / (Height of Image * Width of stage)

or if the image is stretched vertically then scale along Y axis by 

(Height of Image * Width of stage) / (Width of Image * Height of stage)


Our example problem is horizontal stretch, so we take the first formula and get...

(3200*1080)/(2400*1920) = 0.75

and enter 0.75 into the X scale of the transform effect strip's properties.

If you know the aspect ratios of the image and stage, 4:3 and 16:9 in this case, you could instead do...

(4*9)/(3*16) = 0.75

Which is essentially the same thing and you don't have to type in four digit numbers.

As a picture for reference



Now only if there was an addon for this.

All it needs is one single button to check the nature of stretch, add transform effect and do the math for all selected strips. I don't know much about coding but this one if feel shouldn't be too hard. Would be superb to have it. Would come real handy when making slideshows out of photos and such where a lot of strips need to get processed.

Friday, 23 February 2018

പരാജയത്തിന്റെ പ്രഭാഷണങ്ങൾ

       "ക്ലാസ് അസാധ്യമാണ്," ലകാൻ പറയുന്നു. ഒരു വിഷയം ഇതിനെ പാരസ്പര്യത്തിലാക്കിയിരിക്കുന്നു സത്യം ഉൾക്കൊള്ളുന്ന വൈരുദ്ധ്യാത്മക വിവരണം. അങ്ങനെ, സ്വഭാവം ബറോപോസിന്റെ കൃതികളുടെ തീം ഭാഷയ്ക്കും ക്ലാസ്സിനും ഇടയിലുള്ള പാലമാണ്.



        ഒരു സാംസ്കാരിക പിടിയദ്ധിയെപ്പറ്റിയുള്ള സിദ്ധാന്തം പരിശോധിച്ചാൽ,
ഒന്നുകിൽ യാഥാർത്ഥ്യത്തിന്റെ subdialectic paradigm സ്വീകരിക്കുക അല്ലെങ്കിൽ അവസാനിപ്പിക്കുക. ബോധം എന്നത് സംസ്കാര സമ്പദ് വ്യവസ്ഥയുടെ ഭാഗമാണ് വൈരുദ്ധ്യാത്മക വിവരണം വിമർശനമാണ്. പ്രിൻ നിർദ്ദേശിക്കുന്നു
ഞങ്ങൾ സബ്കൈപ്പിട്ടൻഷ്യൻ ഡെബിലിമേഷൻ ആൻഡ് ഡീബോർഡിസ്റ്റ് തമ്മിലുള്ള തിരഞ്ഞെടുക്കാൻ ഞങ്ങൾക്കുണ്ട് സാഹചര്യം. ഒരു അർഥത്തിൽ, പ്രിന്നിന്റെ പ്രാഥമിക വിഷയമാണ് ബൂഡ്രിലാർഡിസ്റ്റ് ഹൈപ്പർരിയലിസിൻറെ വിശകലനം ഒരു വ്യക്തിയല്ല, പക്ഷേ മുൻകൂർ.

      സമൂഹത്തിന് പ്രാധാന്യം നൽകുന്നത് വാചകവികസനം നിർവചിക്കുകയാണ്. എന്നാൽ ബെറ്റൈൽ കാലഹരണപ്പെട്ട, ലൈംഗികതയെ ആക്രമിക്കാൻ ബാഡ്രില്ലാർഡിസ്റ്റ് ഹൈപ്പർരിയലൈറ്റിന്റെ ഉപയോഗം പ്രോത്സാഹിപ്പിക്കുന്നു കലയുടെ സങ്കൽപ്പങ്ങൾ.

      നിയോപദ്കാർമികത്വ മുതലാളിത്തത്തെക്കുറിച്ചുള്ള ലാചെൻ വിമർശനത്തെ സൂചിപ്പിക്കുന്നു ഭരണഘടന സാധ്യമല്ല, മറിച്ച് സംസ്കാരം സമത്വമാണെങ്കിൽ മാത്രം; അല്ലെങ്കിൽ, ഭാഷ ശ്രേണികളെ ശക്തിപ്പെടുത്താൻ ഭാഷ ഉപയോഗിക്കുമെന്ന് ഞങ്ങൾ അനുമാനിക്കാം. എന്നാൽ, ഈ വിഷയം ബാഡ്രില്ലാർഡിസ്റ്റ് ഹൈപ്പർരിയലിത്വത്തിൽ സാങ്കൽപികമായതാണ്
സംസ്കാരം ഒരു യാഥാർത്ഥ്യമായി ഉൾക്കൊള്ളുന്നു.

      ലൈലാർഡ് ക്ലാസ്സുകൾ വായിക്കാൻ വൈരുദ്ധ ഉപകോണിക സിദ്ധാന്തത്തിന്റെ ഉപയോഗം നിർദ്ദേശിക്കുന്നു. അതുകൊണ്ട്, പിൻചന്റെ രചനകളുടെ സ്വഭാവസവിശേഷത സാധാരണമാണ് ലൈംഗിക ഐഡന്റിറ്റി, ക്ലാസ് എന്നിവ തമ്മിലുള്ള ബന്ധം.

      ഈ പ്രബുദ്ധമായ ലേഖനം സൃഷ്ടിക്കാൻ ഞാൻ പോസ്റ്റ്മോഡിനനിസം ജനറേറ്ററും ഗൂഗിൾ ട്രാൻസ്ലേറ്റുമാണ് ഉപയോഗിച്ചത്. ഇതിനായി രണ്ടു മിനുട്ടെ ചിലവായുള്ളു. എല്ലാ ഓൺലൈൻ ബുദ്ധിജീവികൾക്കും ബുദ്ധിശൂന്യർക്കും   വേണ്ടി ഞാൻ ഈ സ്റ്റാർട്ടർ പാക്ക് സമർപ്പിക്കുന്നു. ഇത് വച്ച് ഒരു പുസ്തകം തന്നെ ഇറക്കിയാലോ എന്ന് ആലോചിക്കുകയാണ് ഞ്ഞാൻ.

Sunday, 3 December 2017

I have forgotten how to surf!

These days all I do on the internet is click back and forth between Facebook, YouTube, Quora and Reddit. Sometimes its enough to keep me occupied but I can't seem to shake the feeling that I miss the "internet".

I think surfing in the Y2K period had more to do with exploring new possibilities than finding substance.


Being a completely anonymous troll in Yahoo messenger chat rooms. Downloading just about anything through p2p software like Kazaa and Limewire. Being entertained by Macromedia Flash web animations. Making own (cringe) websites and hosting them for free on angelfire.com. Posting Mortal Kombat fanart on fan forums. Making new friends on social networks. Ending up on random pages and discovering a lot of crazy and/or NSFW stuff. In those days, new possibilities were always around the corner.

Yes. Made friends on social networks. There was this one website (forgot the name) I was on before I joined Hi5. My friends were all complete strangers, mostly from Malaysia and Brazil. Today, friends I add on Fb are all people I know in person. I could still make new friends but I just don't do it. After Orkut came out, I had settled in the safety of people I know in person. My browsing habits also started to change. I was no longer surfing or "interneting". Maybe I was getting bored with discovering stuff. I also stopped watching the Discovery channel around that time.

Also by then, Internet had grown crazy big. There was so much to see, I didn't know what to look at. Internet had become the same experience as eating out. No matter how large the menu, if I go to Zamzam, I always order the Shawarma or Shawwai. It was not just me. The confusion from too much stuff on the internet was real. And that's when things like stumbleupon.com came out. It showed some random and interesting page every-time you clicked the "stumble" button. Lazy surfing.

Today, nothing I stumble upon really gets me interested. The discovery of internet is complete as far as I am concerned. Internet has become the utility that it was meant to be. I am looking at stumbleupon.com right now and it seems you have to be signed in to use it. Well no thanks, just checking.

I still do surf. Sort of. Mostly within YouTube and then there is the occasional Wikipedia and some online shopping. Other than that, I have really forgotten how to surf. Or the reason to surf has gone away. Everything I "need to know" will reach me through Fb or Whatsapp. But still, when I remember the old 56kbps modem and then I look at today's 2mbps broadband connection, I can't help but think I am not using it enough.

Thursday, 21 September 2017

Use handbrake! The software.

I like wetransfer. Its a great tool for sending large files but I hate it when I get a file via wetransfer related to my work because its usually a 500mb 1920x1080 file for a 5 minute video. That too animatics that would do just as well at 360p which would be around 10mb. This is the local animation industry. We deal with video files day in day out but few give a second thought to the size issue.

So how to reduce your video file to mail-able or whatsapp-able size?


There is such a thing called encoding! Notice how you can rar or zip a video but it wouldn't get meaningfully smaller? So how do you get a 20mb file from a 500mb file? Encoding is the winzip of video files. Well not exactly. Zipping is lossless while encoding is lossy. Meaning, it causes a drop in video quality. But with an encoder, you can control how much quality will be lost.

Enter handbrake, the free and easy to use video encoder.

Select the source files and enter a destination path (like D:\myfiles\video.mp4) and you are now ready to shrink it. 

For the really big reductions, you need to reduce the picture resolution in the "Picture" tab. Check if you really need a 1920x1080 file. If not maybe you could settle for a 960x540 file. Its still quite a good resolution but its only a fourth the size of 1920x1080. If you are making a whatsapp video, go even smaller to 640x360 or lower.

Now in the "Video" tab use these settings and tweak the quality slider if you need to. Lower quality means more data loss means smaller file.

In the "Audio" tab, set codec "aac" and drop to 96kbps bitrate and drop mixdown to stereo or mono as you see fit. Mono will give the best size reduction.

Now click "Start" and you should have your 10min video file shrunk to within the gmail attachment limit of 25mb. Also as long as your file's container is ".mp4" and was encoded with "h.264" for video and "aac" for audio, it should play on pretty much every device. Also, such a file will upload and process faster when uploaded to youtube.

So use handbrake!

Intro to Autohotkey : How to scan old photo albums with ease using MS Paint.

Even if you are not going scan any photos, if you use a windows PC regularly, you need to know about AutoHotkey. Make any work easie...