Image uploads
A particular challenge with maintaining a weblog is the uploading and resizing of images. The process involves choosing the correct images, creating large & thumbnail sized versions, uploading these images to the webserver, and posting the appropriate code into the weblog post. In the spirit of my last few posts, image2web is an applescript I use to automate this process:
--user-specific variables
property theAlbum : "Marked"
--contains the images to be uploaded
property theBasePath : "the:path:to:the:local:images:" as alias
--the local path to the weblog
property tagBaseUrl : "[www.your.website.org/path/to//...](http://www.your.website.org/path/to//blog/images/)"
--the url to the weblog images
---declare globals
property htmlText : ""
--stores the image tags & is copied to the clipboard
tell application "Finder"
set theList to name of every folder of theBasePath
end tell
--choose which weblog category the images belong to
set theCategoryList to choose from list theList
with prompt "Choose the post's category:"
set theCategory to first item of theCategoryList
tell application "Finder"
set theCategoryFolder to folder theCategory of theBasePath
end tell
--I use a smart album that collects photos with the checkmark tag
tell application "iPhoto"
activate
select album theAlbum --so we can see which images are involved
set theImages to every photo of album theAlbum --collect the images
repeat with thisImage in theImages
set thisImage to get image path of thisImage
my processImage(thisImage, theCategoryFolder)
--resize & generate the thumbnail
set theResult to the result --avoid declaring more globals
set thePhotoName to item 1 of theResult
set theMainImagePath to item 2 of theResult
set theThumbnailImagePath to item 3 of theResult
my uploadImage(theMainImagePath, theThumbnailImagePath) --upload the image
my makeTag(theCategory, thePhotoName) --create the appropriate html
end repeat
set the clipboard to htmlText --pass the html code to the clipboard
end tell
on processImage(thisImage, theCategoryFolder)
set theResult to display dialog "Enter the name for " & thisImage & ":" default answer ""
set thePhotoName to text returned of theResult
tell application "Finder"
set theDestinationPath to POSIX path of (theCategoryFolder as string)
set theMainImagePath to (theDestinationPath & thePhotoName & ".jpg")
set theThumbnailImagePath to (theDestinationPath & thePhotoName & "-thumb.jpg")
do shell script "/usr/local/bin/convert -resize 640x480 +profile \" * \" " & "\""
& thisImage & "\"" & " " & theMainImagePath
---use extra quotes to protect against spaces in path names
do shell script "/usr/local/bin/convert -resize 240x240 +profile \" * \" " & "\""
& thisImage & "\"" & " " & theThumbnailImagePath
end tell
return {thePhotoName, theMainImagePath, theThumbnailImagePath}
end processImage
on uploadImage(theMainImagePath, theThumbnailImagePath)
set theMainImage to POSIX file theMainImagePath
set theThumbnailImage to POSIX file theThumbnailImagePath
tell application "Transmit"
open theMainImage
open theThumbnailImage
end tell
end uploadImage
on makeTag(theCategory, thePhotoName)
set htmlText to htmlText & ""
--show the thumbnail & link to the full-size image
end makeTag
The workflow is as follows:
- Mark photos with the check-mark tag
- Run the image2web script
- Past the clipboard to Blapp
- Publish the weblog
This script requires both ImageMagick and Transmit and is inspired by a script from waferbaby.