Resizing Images In A Word Macro

Posted Posted in Word / VBScript

​​​Creating word documents from a content management system can introduce certain issues. One of which is that images output from the CMS may not be down-sized properly to fit within the bounds of a page or even within a table cell. To fix this I have tweaked the following vbscript macro for word.

Sub AutoResizeGraphics()
    Dim photo As InlineShape
    PArea = 15.24 ‘ Set something for default page width – margins
    ‘ All images in Document
    ‘   For Each shape In ActiveDocument.InlineShapes
    ‘ All images in Selection
    ‘   For Each shape In Selection.InlineShapes
    For Each photo In ActiveDocument.InlineShapes
        With photo
            OrigWidth = .Width
            OrigHeight = .Height
            photomaxwidth = OrigWidth
            tablewidthpercent = 0.95
            ‘ calculate new pagewidth based on the section the image is within
            With .Range.PageSetup
                RMargin = PointsToInches(.RightMargin)
                LMargin = PointsToInches(.LeftMargin)
                PArea = 2.54 * (PointsToInches(.PageWidth) – (LMargin + RMargin)) ‘ convert to cm
            End With
            pagewidthminusmargins = PArea ‘ in cm not points or in
            If PointsToCentimeters(OrigWidth) > pagewidthminusmargins Then
                photomaxwidth = CentimetersToPoints(pagewidthminusmargins)
            End If
            If photo.Range.Information(wdWithInTable) = True Then
                TablePhotoMaxWidth = .Range.Cells(1).Width * tablewidthpercent
                If (OrigWidth > TablePhotoMaxWidth) Then
                    photomaxwidth = TablePhotoMaxWidth
                End If
            End If
            If Not photomaxwidth = OrigWidth Then
                Ratio = OrigWidth / photomaxwidth
                .LockAspectRatio = msoFalse
                .Height = OrigHeight / Ratio
                .Width = photomaxwidth ‘OrigWidth / Ratio
                .LockAspectRatio = msoTrue
            End If
        End With
End Sub​


Creating my first WordPress widget

Posted Posted in Web Development, Wordpress

Creating my first WordPress widget was a fun learning experiment. I wanted to build a simple widget that would embed a twitter feed as a news ticker.

This article gave me a lot to start and learn from:

At the top of the following image you can see what it looks like when embedded into a page. It is the light gray bar at the top of the page. It uses the marquee jquery plugin available here:


This is what the current widget config panel looks like. Very basic but it does integrate the color picker and most importantly… it works!


I didn’t want my widget to be stuck in standard widget boxes… thinking back I probably should have made it just a plugin. I added 2 entry boxes for jQuery insertBefore/insertAfter commands. This way it can mostly be placed anywhere in the DOM as it requires javascript to run anyways.