html2latex
view release on metacpan or search on metacpan
HTML/Latex.pm view on Meta::CPAN
################### BEGIN DEFENITIONS #######################
# Test what modules we can use
eval {require URI};
$present{'URI'} = 1 unless $@;
eval {require LWP::Simple};
$present{'LWP::Simple'} = 1 unless $@;
eval {require Image::Magick};
$present{'Image::Magick'} = 1 unless $@;
# The configuration file gives a "type" to each tag. This hash tells
# what functions to use on each type
my %types = (
"command" => \&command_handler,
"environment" => \&environment_handler,
"single" => \&single_handler,
"ignore" => \&texify,
"other" => \&other_handler,
"kill" => sub {return ""},
HTML/Latex.pm view on Meta::CPAN
my $source = shift;
my($absolute,$relative) = get_uri($source);
if ($absolute and $relative){ #If we can find the file
#if it successfully stores the file
my ($aname,$apath,$asuffix) = fileparse($absolute,'\.(gif|png|jpe?g)');
my ($rname,$rpath,$rsuffix) = fileparse($relative,'\.(gif|png|jpe?g)');
if($asuffix eq '.gif' || $asuffix eq '.jpg' || $asuffix eq '.jpeg'){ #
# Picture is of a convertable type
if($present{'Image::Magick'}){
# convert it with Image::Magick
require Image::Magick;
my $aoutput = "$apath$aname.png"; #write to and return with png
my $routput = "$rpath$rname.png";
my $image = Image::Magick->new();
$image->Read("$absolute");
$image->Write("$aoutput");
undef $image;
print $LOG "IMG: Converted $source to $routput\n";
return $routput;
} else {
# No Image::Magick. Warn user and return nothing.
print $LOG "IMG: Can't convert $source without Image::Magick; using alt\n";
return;
}
} elsif ($asuffix eq '.png'){
# It's a PNG for sure.
my $routput = "$rpath$rname.png";
return $routput;
} else {
# so, it's not a png,gif, or jpg. That means it's an invalid.
print $LOG "IMG: Invalid picture type: $source; using alt\n";
return;
( run in 0.773 second using v1.01-cache-2.11-cpan-beeb90c9504 )