#!/usr/bin/perl -w use strict; $|++; my $VERSION = '0.05'; #---------------------------------------------------------------------------- =head1 NAME cpanreps-imlib - script to create table heading images. =head1 SYNOPSIS perl cpanreps-imlib [--dir=] [--blank=] [--list=] =head1 DESCRIPTION Given a set of titles, will create an image for each, which consists of the text in white on a transparent background, aligned vertically reading downwards. Note: the ttf-freefont package is required to use the default font. =cut # ------------------------------------- # Library Modules use File::Path; use Getopt::ArgvFile default=>1; use Getopt::Long; use Image::Imlib2; use IO::File; # ------------------------------------- # Variables my %options; my %headings = ( 'distribution' => 'Distribution', 'perlversion' => 'Perl Version' ); # ------------------------------------- # Program ##### INITIALISE ##### init_options(); ##### MAIN ##### Image::Imlib2->set_cache_size(0); my $blank = "$options{dir}/$options{blank}"; if(!-e $blank) { my $image = Image::Imlib2->new(20, 120); # Enable the alpha channel support $image->has_alpha(1); # save out $image->save($blank); } for my $file (keys %headings) { my $text = $headings{$file}; my $target = "$options{dir}/$file.png"; #next if(-e $target); # create a new image #my $image = Image::Imlib2->new(20, 120); my $image = Image::Imlib2->load($blank); $image->add_font_path("/usr/share/fonts/truetype/freefont"); $image->load_font('FreeSansBold/10'); # Enable the alpha channel support $image->has_alpha(1); #$image->set_color(255, 127, 0, 255); #$image->fill_rectangle(0, 0, 20, 120); $image->set_color(255, 255, 255, 255); $image->draw_text(0, 5, $text, TEXT_TO_DOWN, 90); $image->image_orientate(2); # save out $image->save($target); $image = undef; } # ------------------------------------- # Subroutines sub init_options { GetOptions( \%options, 'dir|d=s', 'blank|b=s', 'list|l=s', 'help|h', 'version|v' ); help(1) if($options{help}); help(0) if($options{version}); $options{dir} ||= 'headings'; $options{blank} ||= 'blank.png'; mkpath($options{dir}); # each line is a separate heading if($options{list} && -r $options{list}) { my $fh = IO::File->new($options{list},'r') or die "Cannot read list file [$options{list}]: $!\n"; while(<$fh>) { chomp; my ($file,$name) = split(','); $file =~ s/[^\w]+//g; $headings{$file} = $name || uc $file; } } } sub help { my $full = shift; if($full) { print < L F, F =head1 AUTHOR Original author: Barbie 2008-present =head1 COPYRIGHT AND LICENSE Copyright (C) 2008-2009 Barbie This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut