Changeset 1267


Ignore:
Timestamp:
2000-07-04T11:00:31+12:00 (24 years ago)
Author:
sjboddie
Message:

added a -create_images option to buildcol.pl that attempts to create
collection images automatically at build time (relies on perl scripting
to Gimp)

Location:
trunk/gsdl/bin/script
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/buildcol.pl

    r1031 r1267  
    5454    print STDERR "   -keepold              will not destroy the current contents of the\n";
    5555    print STDERR "                         building directory\n";
    56     print STDERR "   -allclassifications   Don't remove empty classifications\n\n";
     56    print STDERR "   -allclassifications   Don't remove empty classifications\n";
     57    print STDERR "   -create_images        Attempt to create default images for new\n";
     58    print STDERR "                         collection. This relies on the Gimp being\n";
     59    print STDERR "                         installed along with relevant perl modules\n";
     60    print STDERR "                         to allow scripting from perl\n\n";
    5761}
    5862
     
    6165{
    6266    my ($verbosity, $archivedir, $cachedir, $builddir, $maxdocs,
    63     $debug, $mode, $indexname, $keepold, $allclassifications);
     67    $debug, $mode, $indexname, $keepold, $allclassifications,
     68    $create_images);
    6469    if (!parsargv::parse(\@ARGV,
    6570             'verbosity/\d+/2', \$verbosity,
     
    7277             'index/.*/', \$indexname,
    7378             'keepold', \$keepold,
    74              'allclassifications', \$allclassifications)) {
     79             'allclassifications', \$allclassifications,
     80             'create_images', \$create_images)) {
    7581    &print_usage();
    7682    die "\n";
     
    8591    # read the configuration file
    8692    $textindex = "section:text";
    87     $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc/collect.cfg");
     93    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
    8894    if (-e $configfilename) {
    8995    $collectcfg = &colcfg::read_collect_cfg ($configfilename);
     
    101107    }
    102108   
     109    # create default images if required
     110    if ($create_images) {
     111    my $collection_name = $collection;
     112    $collection_name = $collectcfg->{'collectionmeta'}->{'collectionname'}
     113    if defined $collectcfg->{'collectionmeta'}->{'collectionname'};
     114   
     115    &create_images ($collection_name);
     116    }
     117
    103118    # fill in the default archives and building directories if none
    104119    # were supplied, turn all \ into / and remove trailing /
     
    177192}
    178193
    179 
     194sub create_images {
     195    my ($collection_name) = @_;
     196
     197    my $image_script = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "script", "gimp", "title_icon.pl");
     198    if (!-e $image_script) {
     199    print STDERR "WARNING: Image making script ($image_script) could not be found\n";
     200    print STDERR "         Default images will not be generated\n\n";
     201    return;
     202    }
     203
     204    my $imagedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "images");
     205
     206    &util::mk_all_dir ($imagedir);
     207
     208    # create the images
     209    system ("$image_script -size 1.5 -image_dir \"$imagedir\" -filename $collection.gif -text \"$collection_name\"");
     210    system ("$image_script -image_dir \"$imagedir\" -filename ${collection}sm.gif -text \"$collection_name\"");
     211
     212    # update the collect.cfg configuration file (this will need
     213    # to be changed when the config file format changes)
     214    if (!open (CFGFILE, $configfilename)) {
     215    print STDERR "WARNING: Couldn't open config file ($configfilename)\n";
     216    print STDERR "         for updating so collection images may not be linked correctly\n";
     217    return;
     218    }
     219
     220    my $line = ""; my $file = "";
     221    my $found = 0; my $foundsm = 0;
     222    while (defined ($line = <CFGFILE>)) {
     223    if ($line =~ /collectionmeta\s+iconcollection\s+/) {
     224        $line = "collectionmeta iconcollection _httprefix_/collect/$collection/images/$collection.gif\n";
     225        $found = 1;
     226    } elsif ($line =~ /collectionmeta\s+iconcollectionsmall\s+/) {
     227        $line = "collectionmeta iconcollectionsmall _httprefix_/collect/$collection/images/${collection}sm.gif\n";
     228        $foundsm = 1;
     229    }
     230    $file .= $line;
     231    }
     232    close CFGFILE;
     233
     234    $file .= "collectionmeta iconcollection _httprefix_/collect/$collection/images/$collection.gif\n" if !$found;
     235    $file .= "collectionmeta iconcollectionsmall _httprefix_/collect/$collection/images/${collection}sm.gif\n" if !$foundsm;
     236
     237    if (!open (CFGFILE, ">$configfilename")) {
     238    print STDERR "WARNING: Couldn't open config file ($configfilename)\n";
     239    print STDERR "         for updating so collection images may not be linked correctly\n";
     240    return;
     241    }
     242    print CFGFILE $file;
     243    close CFGFILE;
     244}
  • trunk/gsdl/bin/script/gimp/title_icon.pl

    r1037 r1267  
    4646
    4747
    48 my ($cfg_file, $imagefile, $width, $height, $imageheight, $stripecolor, $stripewidth,
    49     $stripe_alignment, $i_transparency, $text, $text_alignment, $filename, $textspace_x,
    50     $textspace_y, $bgcolor, $fontcolor, $fontsize, $minfontsize, $fontname,
    51     $fontweight, $fontslant, $fontwidth, $fontspacing, $image_dir);
     48local ($cfg_file, $size, $imagefile, $width, $height, $imageheight, $stripecolor, $stripewidth,
     49       $stripe_alignment, $i_transparency, $text, $text_alignment, $filename, $textspace_x,
     50       $textspace_y, $bgcolor, $fontcolor, $fontsize, $minfontsize, $fontname,
     51       $fontweight, $fontslant, $fontwidth, $fontspacing, $image_dir, $dont_wrap);
    5252
    5353sub print_usage {
     
    5757    print STDERR "                          sets of the following options - use to create\n";
    5858    print STDERR "                          batches of images\n";
     59    print STDERR "   -size number           the overall size ratio of the image (i.e. a size\n";
     60    print STDERR "                          of 2 will create an image twice the default size)\n";
    5961    print STDERR "   -image_dir directory   directory to create images in [`pwd`]\n";
    6062    print STDERR "                          this should be full path to existing directory\n";
     
    8385    print STDERR "   -fontslant             [r]\n";
    8486    print STDERR "   -fontwidth             [*]\n";
    85     print STDERR "   -fontspacing           [*]\n\n";
     87    print STDERR "   -fontspacing           [*]\n";
     88    print STDERR "   -dont_wrap             don't attempt to wrap text\n\n";
    8689}
    8790
     
    8992    $image_dir = "./";
    9093    $imagefile = "";
    91     $width = 150;
    92     $height = 44;
    93     $imageheight = 110;
     94    $width = int (150 * $size);
     95    $height = int (44 * $size);
     96    $imageheight = int (110 * $size);
    9497    $stripecolor = $gsdl_green;
    95     $stripewidth = 40;
     98    $stripewidth = int (40 * $size);
    9699    $stripe_alignment = "left";
    97100    $i_transparency = 60;
     
    99102    $text_alignment = "left";
    100103    $filename = "";
    101     $textspace_x = 3;
    102     $textspace_y = 3;
     104    $textspace_x = int (3 * $size);
     105    $textspace_y = int (3 * $size);
    103106    $bgcolor = $gsdl_green;
    104107    $fontcolor = $black;
    105     $fontsize = 17;
    106     $minfontsize = 10;
     108    $fontsize = int (17 * $size);
     109    $minfontsize = int (10 * $size);
    107110    $fontname = "lucida";
    108111    $fontweight = "medium";
     
    116119    if (!parsargv::parse(\@ARGV,
    117120             'cfg_file/.*/', \$cfg_file,
     121             'size/\d+/1', \$size,
    118122             'image_dir/.*/./', \$image_dir,
    119123             'imagefile/.*/', \$imagefile,
     
    138142             'fontslant/.*/r', \$fontslant,
    139143             'fontwidth/.*/*', \$fontwidth,
    140              'fontspacing/.*/*', \$fontspacing)) {
     144             'fontspacing/.*/*', \$fontspacing,
     145             'dont_wrap', \$dont_wrap)) {
    141146    &print_usage();
    142147    die "title_icon.pl: incorrect options\n";
     
    148153    chomp $image_dir;
    149154    }
    150    
     155
    151156    if ($cfg_file =~ /\w/) {
    152157   
     
    177182
    178183sub produce_image {
     184
     185    &adjust_args ();
     186    &wrap_text () unless $dont_wrap;
    179187
    180188    my $use_image = 0;
     
    338346    return 1;
    339347}
     348
     349# adjust arguments that are effected by the size argument
     350sub adjust_args {   
     351
     352    if ($size != 1) {
     353    my @size_args = ('width', 'height', 'imageheight', 'stripewidth',
     354             'textspace_x', 'textspace_y', 'fontsize', 'minfontsize');
     355    foreach $arg (@size_args) {
     356        $$arg = int ($$arg * $size);
     357    }
     358    }
     359}
     360
     361sub wrap_text {
     362
     363    # don't wrap text if it already contains carriage returns
     364    return if $text =~ /\n/;
     365
     366    # the following assumes that all words are less than $wrap_length long
     367    my $wrap_length = 14;
     368
     369    my $new_text = "";
     370    while (length ($text) >= $wrap_length) {
     371    my $line = substr ($text, 0, $wrap_length);
     372    $text =~ s/^$line//;
     373    $line =~ s/\s([^\s]*)$/\n/;
     374    $text = $1 . $text;
     375    $new_text .= $line;
     376    }
     377    $new_text .= $text;
     378    $text = $new_text;
     379}
    340380   
    341381sub query {
Note: See TracChangeset for help on using the changeset viewer.