parsed.org

Tips by tag: thumbnail

Convert Imagesize and Output Html-Code by -Flo- on Feb 19, 2008 09:12 AM
I wrote a little Bash-script, that
  • Creates Thumbnails to a specific size
  • Converts original Images to a specific size
  • Creates Html-Code that will show the thumbnail and link to the image (Folders can be included)

Have fun with it:

#!/bin/bash

######################
# Set Variables
######################
ENDING=jpg;
IMG_SIZE=800;
THUMB_SIZE=150;
DIR=folder/folder/images/;
ID=/usr/bin/identify;

######################
# Create Thumbnail
######################
ls -1 *.$ENDING | grep -v thb |while read file;
do convert -thumbnail $THUMB_SIZEx$THUMB_SIZE "$file" "`basename _thb_"$file"`";
        echo "---> _thb_$file created";
done

######################
# Convert image
######################
ls -1 *.$ENDING | grep -v thb | while read file;
do convert -resize $IMG_SIZEx$IMG_SIZE "$file" "`basename "$file"`";
        echo "---> $file converted";
done

######################
# Output HTML-Code
######################
echo "######################";
echo "HTML-CODE:";
echo "######################";
ls -1 *.$ENDING | grep -v thb | while read file;
do
        h=$($ID -format \"%h\" "`basename _thb_"$file"`");
        w=$($ID -format \"%w\" "`basename _thb_"$file"`");
        echo "<a href=\""$DIR$file"\">";
        echo "<img alt=\"\" src=\""$DIR""`basename _thb_"$file"`"\" width=$w height=$h /></a>";
done
echo "######################";
bashconverthtmlimagethumbnail
RSS