Skip to content

Commit

Permalink
handle more generic pixel data structure for bin writes
Browse files Browse the repository at this point in the history
  • Loading branch information
bricas committed Aug 18, 2015
1 parent 33f9dd6 commit 87bfa0d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/Image/TextMode/Writer/Bin.pm
Expand Up @@ -6,11 +6,13 @@ extends 'Image::TextMode::Writer';

sub _write {
my ( $self, $image, $fh, $options ) = @_;
my ( $width, $height ) = $image->dimensions;

for my $row ( @{ $image->pixeldata } ) {
print $fh
join( '',
map { pack( 'aC', @{ $_ }{ qw( char attr ) } ) } @$row );
for my $y ( 0 .. $height - 1 ) {
for my $x ( 0 .. $width - 1 ) {
my $pixel = $image->getpixel( $x, $y ) || { char => ' ', attr => 7 };
print $fh pack( 'aC', $pixel->{ char }, $pixel->{ attr } );
}
}
}

Expand Down

0 comments on commit 87bfa0d

Please sign in to comment.