Monday, December 29, 2008

Resampling images using PowerShell and GraphicsMagick

I needed to resample several images which were scanned at a higher a resolution than expected, so here's a PowerShell script that I created to resample them to a lower resolution using GraphicsMagick. It's probably not the most elegant, but it seems to work for my requirement. Here it is:

$gm = "C:\Program Files\GraphicsMagick-1.3.3-Q8\gm.exe"
$maxResolution = 100
$defaultResolution = "72x72"

foreach ($file in ls *.jpg) {
echo Processing: $file.Name
$resolutionLine = & $gm identify -verbose $file | Select-String -pattern "Resolution:"
echo $resolutionLine
if ($resolutionLine -match "(\d+)x(\d+)") {
if ([int]$matches[1] -gt $maxResolution -and [int]$matches[2] -gt $maxResolution) {
$file.CopyTo($file.FullName + ".bak")
& $gm convert -resample $defaultResolution -units PixelsPerInch $file $file
echo Resampled: $file.Name

To use, copy the code and save it as a *.ps1 file and run it from the directory you wish to resample images, making any edits as needed. (Note: PowerShell and GraphicsMagick must already be installed.) Use at your own risk, I make no guarantees about this script.

Please leave a comment if you find this script helpful or have any suggestions for improvement.

Thursday, December 04, 2008

Thoughts on error handling in classic ASP

Most of our code base is written in classic ASP and VBScript. And, most of it was written without any sort of error logging. We've been coming to the realization that one of our applications definitely needs some sort of error logging, so I started doing some research.

I've wondered before about adding error logging and friendlier error messages for our other ASP applications, but didn't know of a simple way to do global error handling. But, while researching I found that it's easier than I had imagined.

The trick is to create an ASP page and set it as the default handler for 500;100 errors from IIS. You can use Server.GetLastError() to retrieve information for the last error. You also get to keep context information from the Request and other objects. So, after calling Server.GetLastError(), just log the relevant error and context info, send notification e-mails and display a friendly error message.

Speaking of friendly error messages, I think this error page from is a good example of simplicity and effectiveness: error page

Thursday, September 11, 2008

Remembering my grandmother

Today would have been my grandma Rose Anne Henry's 88th birthday. She passed away this past spring, however, while sitting on the couch waiting for her friend to pick her up for mass.

She was very generous, often giving more than she could afford. She was committed to her church and had served in the Navy. She loved cats, and she dreamed of moving to California so she could spend her days tanning by the pool. She was full of energy and loved to talk our ears off - but we didn't get to see her much since she lived in Gary, Indiana. I regret not spending more time with her ... but that's not the end of the story.

Before I continue, let me take a slight detour to help explain something. Growing up, my parents took me to church. I believed in God and Jesus. But I didn't know for certain if I died whether I would go to heaven. I think there are many people who go to church their whole lives, believe in God, pray and follow traditions and yet still are not certain where they will spend eternity.

So this spring, when my mom called with the sad news that my grandma had passed away, I had three thoughts: I was saddened by her loss. I regretted not spending more time with her. And I wondered where my grandma truly stood with God. My prayer before I drove up for the service was, "God, please show me somehow if my grandma was saved."

I met my family in Indiana, we attended the memorial and met some of my grandmother's friends who had helped her in so many ways. The next day we went to her house to clean. While we were there, a woman and a young lady came to the door asking for my grandma. My mom shared that she had passed away and the woman said she was sorry to hear and mentioned that they were from the nearby First Baptist Church of Hammond and had been visiting with my grandma for the past few weeks. She went on to share that last Saturday, she had prayed to receive Christ.

My grandma accepted Christ as her Lord and Savior the night before she passed away. The next morning she got dressed to go meet with God, and God brought her home.

God answered my prayer in a very real way and I was very encouraged to hear the good news! God confirmed that my grandma would spend eternity with Him, and one day I will get to spend time with her again.

The woman went on to ask each of us at the door (my mom, uncle and myself) if we were 100% sure we would go to heaven when we died. I was thankful that God had drawn me to accept Him as my Lord and Savior when I was in college. And I am so thankful for the woman of God who had the love and courage to share the gospel with my grandma. Thank you, and thank God.

So happy birthday Grandma, may you rest in joy in God's presence.