Posting Flickr images to Web Boards

I post images from Flickr on misc Web Boards regularly, and today I wrote a small Perl script to help me along:

The script is available here:

#!/usr/bin/perl -w
#  This script was developed by Ole Bendik Kvisberg (olekvi at,
#  This script is free software; you can redistribute it and/or modify it
#  under the same terms as Perl itself.
use strict;
use Getopt::Long;
use File::Basename;
my $help        = 0;
my $flickrname  = 'olekvi';
# From
# Flickr Community Guidelines specify that if you post a Flickr photo on
# an external website, the photo must link back to its photo page
my $nolink      = 0;
GetOptions ("flickrname=s"      => $flickrname,         
            "nolink"            => $nolink,
            "help"              => $help);
my $url = shift;
if ($help or !$url) {
sub usage {
        printf ("Usage: %s [OPTION] [PHOTOURL]n", basename($0));
        print "Creates BBCode to insert Flickr photo on web forumsnn";
        print "  -f  --flickrname   your flickr username (i.e 'olekvi')n";
        print "  -n, --nolink       skip link (Flickr says you shouldn't!)n";
        print "  -h, --help         display this help and exitn";
sub createbbc {
        my $photourl = shift;
        unless ($photourl =~ m!^$!) {
                printf ("Invalid Flickr photo url:n%sn", $photourl);
        my $linkurl     = sprintf("", $flickrname, $1);
        my $photobbc    = sprintf("[IMG]%s[/IMG]", $photourl);
        if ($nolink) {
                printf ("%sn", $photobbc);
        else {
                printf ("[URL=%s]%s[/URL]n", $linkurl, $photobbc);       

More or less related posts:

This entry was posted in Code and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *