A while ago, I was working on creating a script to create thumbnails of all the pictures I had taken so I could put them up on my personal site for family/friends to view. It started out as a very basic script but as I developed my website, I found new ways to display the photos. Namely using css for the image to come up double sized by mousing over on the picture. Well this created quite a challenge to put all the code for my pictures in the HTML. So I went a step further and adjusted the script to create the php necessary for the galleries. The way I create all my pages is to use a standard header and footer file and include them into my individual pages. So I then changed the script so it created a full blown page ready to be used. The script is below. You may have to modify it slightly for your own needs, but it should work fine. The main requirement is the imagemagick software. In Slackware it is included with the default install. With your own distro you may need to add it yourself.
[code=’bash’]
#!/bin/bash
echo “Resizing Pictures and Creating PHP”
mkdir thumbs previews view
cp ../rhine-river/view.php .
cp ../rhine-river/download.php .
totalcount=0
currentcount=0
if [ $1 = y ]
then
name=$2
picnum=0
for i in *.jpg *.JPG; do
picnum=$(($picnum + 1))
pic=`echo $i | awk -F . ‘{print $1}’`
rename=”${name}-`printf “%03d” $picnum`.jpg”
mv “$i” $rename
done
fi
for i in *.jpg; do
totalcount=$(($totalcount + 1))
done
echo “There are $totalcount pictures to convert.”
# Create the header
echo \<\?php > index.php
echo \$pagetitle \= \”Insert Title Here\”\; >> index.php
echo include_once\(\”../../includes/header.php\”\)\; >> index.php
echo ?\> >> index.php
echo \
Page Description Here\
>> index.phpecho \
- >> index.php
- >> index.php
echo -ne “\t\t” \ >> index.php
echo -ne \ >> index.php
echo -e \\<\/a\> >> index.php
echo -e “\t\t” \Insert Description Here\<\/p\> >> index.php
echo -e “\t” \<\/li\> >> index.php
echo -e “\t” “” >> index.php# Creating Thumbnail with a width of 150px
convert $i -thumbnail 150x -quality 85 -scene 01 thumbs/tn-$i# Creating Preview with a width of 300px
convert $i -thumbnail 300x -quality 85 -scene 01 previews/pre-$i# Creating Large with a width of 800px
convert $i -resize 800x -quality 85 -scene 01 view/low-$icurrentcount=$(($currentcount + 1))
echo $currentcount\/$totalcount Complete…done
# Create the Footer
echo \
for i in *.jpg; do
pic=`echo $i | awk -F . ‘{print $1}’`
echo -e “\t” \
echo \ >> index.php
echo “PHP file index.php is complete. Converted and added $currentcount pictures.”
[/code]
I am getting this up really quick for a friend to use, I will edit the post later with links to the css and other code I am using along with a couple of modifications to the script.
Excellent works perfectly, you save me a lot of time and headaches.
Good Job, thank you.