#!/usr/bin/perl use Image::Magick; use Irssi; use POSIX; require URI::Find; use vars qw($VERSION %IRSSI); $VERSION = "0.1"; %IRSSI = ( "authors" => "Sigve Sebastian Farstad", "contact" => "sigvefarstad@gmail.com", "name" => "imgrender", "description" => "Renders ascii art versions of linked images to a separate window.", "url" => "http://arkt.is/imgrender", ); Irssi::signal_add('message own_public', 'parse_text'); Irssi::signal_add('message public', 'parse_text'); Irssi::signal_add('message own_private', 'parse_text'); Irssi::signal_add('message private', 'parse_text'); @characters = ("%0%b ","%0%b▓","%4%b░","%4%b▒","%0%b█","%0%b░","%0%b▒","%0%g▓","%0%c▓","%4%c▓","%2%b░","%2%g░","%2%c▓","%6%c░","%2%c░","%2%g▒","%6%c▒","%2%c▒","%0%g█","%0%c█","%0%g░","%2%b▓","%4%c░","%0%c░","%0%g▒","%4%c▒","%0%c▒","%7%K▓","%3%B▓","%7%B▓","%3%K▓","%5%G▓","%1%C▓","%5%C▓","%1%G▓","%7%G▓","%3%C▓","%7%C▓","%3%G▓","%5%K▓","%1%B▓","%5%B▓","%1%K▓","%0%W▒","%4%Y▒","%4%W▒","%0%Y▒","%2%M▒","%6%R▒","%6%M▒","%2%R▒","%2%W▒","%6%Y▒","%6%W▒","%2%Y▒","%0%M▒","%4%R▒","%4%M▒","%0%R▒","%1%C▒","%5%G▒","%5%C▒","%1%G▒","%3%B▒","%7%K▒","%7%B▒","%3%K▒","%3%C▒","%7%G▒","%7%C▒","%3%G▒","%1%B▒","%5%K▒","%5%B▒","%1%K▒","%0%r▓","%0%m▓","%4%m▓","%1%b░","%0%y▓","%0%w▓","%4%w▓","%3%b░","%2%y▓","%2%w▓","%6%w▓","%3%c░","%1%g░","%2%m▓","%5%c░","%1%c░","%7%K░","%7%B░","%3%K░","%3%B░","%7%G░","%7%C░","%3%G░","%3%C░","%5%K░","%5%B░","%1%K░","%1%B░","%5%G░","%5%C░","%1%G░","%1%C░","%1%r░","%1%m▓","%5%m░","%1%m░","%1%y▓","%1%w▓","%5%w▓","%3%m░","%3%y░","%3%w▓","%7%w░","%3%w░","%1%y░","%3%m▓","%5%w░","%1%w░","%1%r▒","%5%m▒","%1%m▒","%3%y▒","%7%w▒","%3%w▒","%1%y▒","%5%w▒","%1%w▒","%0%r█","%0%m█","%0%y█","%0%w█","%6%R▓","%2%M▓","%6%M▓","%2%R▓","%4%Y▓","%0%W▓","%4%W▓","%0%Y▓","%6%Y▓","%2%W▓","%6%W▓","%2%Y▓","%4%R▓","%0%M▓","%4%M▓","%0%R▓","%7%R░","%7%M░","%3%R░","%3%M░","%7%Y░","%7%W░","%3%Y░","%3%W░","%5%R░","%5%M░","%1%R░","%1%M░","%5%Y░","%5%W░","%1%Y░","%1%W░","%6%K░","%6%B░","%2%K░","%2%B░","%6%G░","%6%C░","%2%G░","%2%C░","%4%K░","%4%B░","%0%K░","%0%B░","%4%G░","%4%C░","%0%G░","%0%C░","%1%W▒","%5%Y▒","%5%W▒","%1%Y▒","%3%M▒","%7%R▒","%7%M▒","%3%R▒","%3%W▒","%7%Y▒","%7%W▒","%3%Y▒","%1%M▒","%5%R▒","%5%M▒","%1%R▒","%7%R▓","%3%M▓","%7%M▓","%3%R▓","%5%Y▓","%1%W▓","%5%W▓","%1%Y▓","%7%Y▓","%3%W▓","%7%W▓","%3%Y▓","%5%R▓","%1%M▓","%5%M▓","%1%R▓","%0%W█","%0%Y█","%0%M█","%0%R█","%0%C▒","%4%G▒","%4%C▒","%0%G▒","%2%B▒","%6%K▒","%6%B▒","%2%K▒","%2%C▒","%6%G▒","%6%C▒","%2%G▒","%0%B▒","%4%K▒","%4%B▒","%0%K▒","%0%r░","%1%b▓","%4%m░","%0%m░","%1%g▓","%1%c▓","%5%c▓","%2%m░","%2%y░","%3%c▓","%6%w░","%2%w░","%0%y░","%3%b▓","%4%w░","%0%w░","%6%K▓","%2%B▓","%6%B▓","%2%K▓","%6%R░","%6%M░","%2%R░","%2%M░","%4%G▓","%0%C▓","%4%C▓","%0%G▓","%6%Y░","%6%W░","%2%Y░","%2%W░","%4%R░","%4%M░","%0%R░","%0%M░","%6%G▓","%2%C▓","%6%C▓","%2%G▓","%4%K▓","%4%Y░","%0%B▓","%4%W░","%0%Y░","%4%B▓","%0%K▓","%0%C█","%0%G█","%0%B█","%0%K█","%0%r▒","%4%m▒","%0%m▒","%2%y▒","%6%w▒","%2%w▒","%0%y▒","%4%w▒","%0%w▒"); @colors = ([0,0,0],[0,0,138],[0,0,184],[0,0,186],[0,0,187],[0,0,46],[0,0,93],[0,138,0],[0,138,138],[0,138,184],[0,138,46],[0,184,0],[0,184,138],[0,184,184],[0,184,46],[0,186,0],[0,186,186],[0,186,93],[0,187,0],[0,187,187],[0,46,0],[0,46,138],[0,46,184],[0,46,46],[0,93,0],[0,93,186],[0,93,93],[109,109,109],[109,109,189],[109,109,235],[109,109,63],[109,189,109],[109,189,189],[109,189,235],[109,189,63],[109,235,109],[109,235,189],[109,235,235],[109,235,63],[109,63,109],[109,63,189],[109,63,235],[109,63,63],[127,127,127],[127,127,135],[127,127,220],[127,127,42],[127,135,127],[127,135,135],[127,135,220],[127,135,42],[127,220,127],[127,220,135],[127,220,220],[127,220,42],[127,42,127],[127,42,135],[127,42,220],[127,42,42],[135,127,127],[135,127,135],[135,127,220],[135,127,42],[135,135,127],[135,135,135],[135,135,220],[135,135,42],[135,220,127],[135,220,135],[135,220,220],[135,220,42],[135,42,127],[135,42,135],[135,42,220],[135,42,42],[138,0,0],[138,0,138],[138,0,184],[138,0,46],[138,138,0],[138,138,138],[138,138,184],[138,138,46],[138,184,0],[138,184,138],[138,184,184],[138,184,46],[138,46,0],[138,46,138],[138,46,184],[138,46,46],[159,159,159],[159,159,201],[159,159,21],[159,159,63],[159,201,159],[159,201,201],[159,201,21],[159,201,63],[159,21,159],[159,21,201],[159,21,21],[159,21,63],[159,63,159],[159,63,201],[159,63,21],[159,63,63],[184,0,0],[184,0,138],[184,0,184],[184,0,46],[184,138,0],[184,138,138],[184,138,184],[184,138,46],[184,184,0],[184,184,138],[184,184,184],[184,184,46],[184,46,0],[184,46,138],[184,46,184],[184,46,46],[186,0,0],[186,0,186],[186,0,93],[186,186,0],[186,186,186],[186,186,93],[186,93,0],[186,93,186],[186,93,93],[187,0,0],[187,0,187],[187,187,0],[187,187,187],[189,109,109],[189,109,189],[189,109,235],[189,109,63],[189,189,109],[189,189,189],[189,189,235],[189,189,63],[189,235,109],[189,235,189],[189,235,235],[189,235,63],[189,63,109],[189,63,189],[189,63,235],[189,63,63],[201,159,159],[201,159,201],[201,159,21],[201,159,63],[201,201,159],[201,201,201],[201,201,21],[201,201,63],[201,21,159],[201,21,201],[201,21,21],[201,21,63],[201,63,159],[201,63,201],[201,63,21],[201,63,63],[21,159,159],[21,159,201],[21,159,21],[21,159,63],[21,201,159],[21,201,201],[21,201,21],[21,201,63],[21,21,159],[21,21,201],[21,21,21],[21,21,63],[21,63,159],[21,63,201],[21,63,21],[21,63,63],[220,127,127],[220,127,135],[220,127,220],[220,127,42],[220,135,127],[220,135,135],[220,135,220],[220,135,42],[220,220,127],[220,220,135],[220,220,220],[220,220,42],[220,42,127],[220,42,135],[220,42,220],[220,42,42],[235,109,109],[235,109,189],[235,109,235],[235,109,63],[235,189,109],[235,189,189],[235,189,235],[235,189,63],[235,235,109],[235,235,189],[235,235,235],[235,235,63],[235,63,109],[235,63,189],[235,63,235],[235,63,63],[255,255,255],[255,255,85],[255,85,255],[255,85,85],[42,127,127],[42,127,135],[42,127,220],[42,127,42],[42,135,127],[42,135,135],[42,135,220],[42,135,42],[42,220,127],[42,220,135],[42,220,220],[42,220,42],[42,42,127],[42,42,135],[42,42,220],[42,42,42],[46,0,0],[46,0,138],[46,0,184],[46,0,46],[46,138,0],[46,138,138],[46,138,184],[46,138,46],[46,184,0],[46,184,138],[46,184,184],[46,184,46],[46,46,0],[46,46,138],[46,46,184],[46,46,46],[63,109,109],[63,109,189],[63,109,235],[63,109,63],[63,159,159],[63,159,201],[63,159,21],[63,159,63],[63,189,109],[63,189,189],[63,189,235],[63,189,63],[63,201,159],[63,201,201],[63,201,21],[63,201,63],[63,21,159],[63,21,201],[63,21,21],[63,21,63],[63,235,109],[63,235,189],[63,235,235],[63,235,63],[63,63,109],[63,63,159],[63,63,189],[63,63,201],[63,63,21],[63,63,235],[63,63,63],[85,255,255],[85,255,85],[85,85,255],[85,85,85],[93,0,0],[93,0,186],[93,0,93],[93,186,0],[93,186,186],[93,186,93],[93,93,0],[93,93,186],[93,93,93]); sub parse_text { my($yo1,$text,$target, $yo1, $nick) = @_; my @uris; my $finder = URI::Find->new(sub { my($uri) = shift; push @uris, $uri; render_image($uri,$target,$nick,$text); }); $finder->find(\$text); } sub get_color { my($r,$g,$b) = @_; #@characters = (" ","░","▒","▓","█"); #return "%0%W".$characters[int(($r+$g+$b)/765.0*5)]; my $distance = 9999999; #some random high number my $index = 0; for($i = 0;$iRead($uri); ($x, $y) = $image->[0]->Get('width','height'); $image->Resize(width=>'80', height=>$y*80/$x/2,filter=>'Sinc'); ($xSize, $ySize) = $image->[0]->Get('width','height'); for ($y = 0; $y < $ySize; $y++) { $line = ""; for ($x = 0; $x < $xSize; $x++) { # look at the pixel colour $p = $image->Get("pixel[$x,$y]"); # split into RGBA components. discard alpha channel. ($r,$g,$b,$a) = split(/\,/, $p); # IMPORTANT: # Some versions of ImageMagic use 24-bit RGB, if this describes you, then # change the next line to read "if ( 1==0 ) {". if ( 1==1 ) { # ImageMagick is using 48-bit RGB, so divide through to get 24-bit. $r = $r >> 8; $g = $g >> 8; $b = $b >> 8; } # add these values to the array. $line = $line.get_color($r,$g,$b); } $window->print($line,MSGLEVEL_NEVER) if ($window); } $window->print(strftime(Irssi::settings_get_str('timestamp_format')." ",localtime).$target.": ".$nick.": ".$text,MSGLEVEL_NEVER) if ($window); }; if($@){ # print $@; } }