{"id":15,"date":"2008-08-18T00:51:36","date_gmt":"2008-08-17T22:51:36","guid":{"rendered":"http:\/\/bassmadrigal.com\/blog\/?p=15"},"modified":"2008-08-18T00:54:40","modified_gmt":"2008-08-17T22:54:40","slug":"bash-thumbnailer-script-with-imagemagick","status":"publish","type":"post","link":"http:\/\/bassmadrigal.com\/blog\/2008\/08\/bash-thumbnailer-script-with-imagemagick\/","title":{"rendered":"Bash Thumbnailer Script with Imagemagick"},"content":{"rendered":"<p>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.<\/p>\n<p>[code=&#8217;bash&#8217;]<br \/>\n#!\/bin\/bash<\/p>\n<p>echo &#8220;Resizing Pictures and Creating PHP&#8221;<br \/>\nmkdir thumbs previews view<br \/>\ncp ..\/rhine-river\/view.php .<br \/>\ncp ..\/rhine-river\/download.php .<\/p>\n<p>totalcount=0<br \/>\ncurrentcount=0<\/p>\n<p>if [ $1 = y ]<br \/>\nthen<br \/>\nname=$2<br \/>\npicnum=0<br \/>\nfor i in *.jpg *.JPG; do<\/p>\n<p>picnum=$(($picnum + 1))<\/p>\n<p>pic=`echo $i | awk -F . &#8216;{print $1}&#8217;`<br \/>\nrename=&#8221;${name}-`printf &#8220;%03d&#8221; $picnum`.jpg&#8221;<br \/>\nmv &#8220;$i&#8221; $rename<\/p>\n<p>done<br \/>\nfi<\/p>\n<p>for i in *.jpg; do<\/p>\n<p>totalcount=$(($totalcount + 1))<\/p>\n<p>done<\/p>\n<p>echo &#8220;There are $totalcount pictures to convert.&#8221;<\/p>\n<p># Create the header<br \/>\necho \\<\\?php > index.php<br \/>\necho \\$pagetitle \\= \\&#8221;Insert Title Here\\&#8221;\\; >> index.php<br \/>\necho include_once\\(\\&#8221;..\/..\/includes\/header.php\\&#8221;\\)\\; >> index.php<br \/>\necho ?\\> >> index.php<br \/>\necho \\<h1\\>Page Description Here\\<\/h1\\> >> index.php<br \/>\necho \\<\/p>\n<ul class=\\\"hoverbox\\\"\\> >> index.php<\/p>\n<p>for i in *.jpg; do<\/p>\n<p>pic=`echo $i | awk -F . &#8216;{print $1}&#8217;`<\/p>\n<p>echo -e &#8220;\\t&#8221; \\<li\\> >> index.php<br \/>\necho -ne &#8220;\\t\\t&#8221; \\<a href\\=\\\"view.php?id\\=$pic\\\"\\> >> index.php<br \/>\necho -ne \\<img src\\=\\\"thumbs\\\/tn-$i\\\" alt\\=\\\"Click for larger picture\\\" \\\/\\> >> index.php<br \/>\necho -e \\<img src\\=\\\"previews\\\/pre-$i\\\" alt\\=\\\"Click for larger picture\\\" class\\=\\\"preview\\\" \\\/\\>\\<\\\/a\\> >> index.php<br \/>\necho -e &#8220;\\t\\t&#8221; \\<\/p>\n<p class\\=\\\"label\\\"\\>Insert Description Here\\<\\\/p\\> >> index.php<br \/>\necho -e &#8220;\\t&#8221; \\<\\\/li\\> >> index.php<br \/>\necho -e &#8220;\\t&#8221; &#8220;&#8221; >> index.php<\/p>\n<p># Creating Thumbnail with a width of 150px<br \/>\nconvert $i -thumbnail 150x -quality 85 -scene 01 thumbs\/tn-$i<\/p>\n<p># Creating Preview with a width of 300px<br \/>\nconvert $i -thumbnail 300x -quality 85 -scene 01 previews\/pre-$i<\/p>\n<p># Creating Large with a width of 800px<br \/>\nconvert $i -resize 800x -quality 85 -scene 01 view\/low-$i<\/p>\n<p>currentcount=$(($currentcount + 1))<br \/>\necho $currentcount\\\/$totalcount Complete&#8230;<\/p>\n<p>done<\/p>\n<p># Create the Footer<br \/>\necho \\<\/ul\\> >> index.php<br \/>\necho \\<?php include_once\\(\\\"..\/..\/includes\/footer.php\\\"\\)?\\> >> index.php<\/p>\n<p>echo &#8220;PHP file index.php is complete. Converted and added $currentcount pictures.&#8221;<br \/>\n[\/code]<\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"http:\/\/bassmadrigal.com\/blog\/2008\/08\/bash-thumbnailer-script-with-imagemagick\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22,4,19],"tags":[16,21,55,56,20],"_links":{"self":[{"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/posts\/15"}],"collection":[{"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":3,"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":20,"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions\/20"}],"wp:attachment":[{"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bassmadrigal.com\/blog\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}