
thumbnails with imagemagick
So you want little square thumbnails like Flickr. Here is a bash script that uses imagemagick to generate square thumbnails.
makethumb:
#!/bin/bash
#
# makethumb
#
# A bash script to generate square thumbnails using imagemagick.
#
# Feel free to use and abuse, its just a script. Requires imagemagick!
# See www.websurfshack.net for more stuff like this
#
if [ "$1" = "" ]; then
echo "Usage: makethumb source_file [size] [output file]"
echo ""
echo "e.g."
echo " makethumb large.jpg"
echo " makethumb large.jpg 65"
echo " makethumb large.jpg 45 thumb.jpg"
echo " makethumb large.jpg 25 thumb.gif"
echo ""
echo "Note: You may specify an output file of a different type to the source. The image will be converted automatically to that type."
echo ""
exit
fi
if [ ! -e "$1" ]; then
echo "Input file "$1" not found. Please specify a valid input file!"
exit
fi
ORIG_FILE="$1"
if [ "$2" = "" ]; then
SIZE="45"
else
SIZE="$2"
fi
if [ "$3" = "" ]; then
THUMB_FILE="THUMB_${ORIG_FILE}"
else
THUMB_FILE="$3"
fi
echo "Creating ${SIZE}x${SIZE} thumbnail '${THUMB_FILE}' from source image '${ORIG_FILE}'"
#Grab the image dimensions
WIDTH=`identify -format '%w' ${ORIG_FILE}`
HEIGHT=`identify -format '%h' ${ORIG_FILE}`
echo "Source image is ${WIDTH}x${HEIGHT}"
if [ $WIDTH = $HEIGHT ]; then
echo "Image is already square so just resizing..."
`convert ${ORIG_FILE} -thumbnail "${SIZE}x${SIZE}" -strip ${THUMB_FILE}`
else
if [ $WIDTH -gt $HEIGHT ]; then
echo "Image is landscape"
`convert ${ORIG_FILE} -resize "x${SIZE}" -gravity NorthWest -crop ${SIZE}x${SIZE}+0+0 +repage -strip ${THUMB_FILE}`
fi
if [ $WIDTH -lt $HEIGHT ]; then
echo "Image is portrait"
`convert ${ORIG_FILE} -resize "${SIZE}" -gravity NorthWest -crop ${SIZE}x${SIZE}+0+0 +repage -strip ${THUMB_FILE}`
fi
fi
NEWFILEDATA=`identify ${THUMB_FILE}`
echo "Output file: ${NEWFILEDATA}"
echo "Done!"
Add an empty space to your dock to split the icons up a bit. You can add as many as you like:
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
killall Dock
We have written about mod_rewrite before, but did you know that you can check if a file (or directory) exists before you attempt to redirect to it? Here’s how:
RewriteCond %{DOCUMENT_ROOT}/files/%{REQUEST_URI} -f
RewriteRule ^/([^/]*)$ /files/$1 [PT]
The RewriteCond checks for the existance of a file in the specified path, this is done with the special mod_rewrite rule -f. If you want to check if a file does not exist, you could use the following:
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
Also, you can check for the existance of a directory with ‘-d’
The results of the above rule will allow the user, when they visit the URL
http://example.com/foo.html
to instead be served:
http://example.com/files/foo.html
so long as /files/foo.html exists. If it doesn’t, the usual behaviour will occur (such as other rewrites/redirects running, or causing a 404 error to be displayed).
Mac OS does something weird with some font files. Basically it stores the data in two separate places which means that copying using scp or rsync tends to fail. This use of resource forks makes it incredibly difficult to copy these files without using the Finder.
RsyncX HFS is one option, its a version of rsync that supports resource forks.
Another option though is to use the command line utility ditto. This comes with OS X and essentially allows you to compress all of the files into a single copyable file. You can use it like this, but you could rtfm.
Create an archive:
ditto -c --rsrc SourceDirContainingFonts AnyOldFileName
You could then zip that (although ditto may support compression… rtfm), scp it to another location. To unarchive simply:
ditto -x --rsrc AnyOldFileName DestinationDir
You can do the archie-copy-unarchive in one go too:
ditto -c --rsrc SourceDirContainingFonts - | ssh user@host 'ditto -x --rsrc - DestinationDir'
Obviously, you can use this for anything, not just fonts. But its fonts that caused me the grief!