View Single Post
Old 03-31-2009, 11:23 AM   #2
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,546
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Yes, look at this thread.

Though I'm afraid the link given there is not available anymore... Here are the files I use:

t2b.pl
Code:
#!/usr/bin/perl

use GD;

my $palette = $0;
$palette =~ s/[^\/]+$/palette.ppm/;

while ( my $file = shift @ARGV )
  {
  if ( $file =~ /\.pdf$/ )
    { open IN, "pdftops -f 1 -l 1 -paper match \"$file\" - | convert -resize 96x144 -map \"$palette\" -dither PNM:- | pnmtopng 2>/dev/null |"; }
  else
    { open IN, "convert -resize 96x144 -map \"$palette\" -dither \"$file\" PNM:- | pnmtopng 2>/dev/null |"; }
  my $in = join( '', <IN> );
  close IN;

  $image = GD::Image->new( $in );

  $k = 3;
  @px = ( );

  $left = int( ( 96 - $image->width ) / 2 );
  $right = 96 - $image->width - $left;
  $top = int( ( 144 - $image->height ) / 2 );
  $bottom = 144 - $image->height - $top;

  $file =~ s/\..+?$/_6090.t2b/;
  open OUT, "> $file";

  for ( $i = - $top; $i < 144 - $top; $i ++ )
    {
    for ( $j = - $left; $j < 96 - $left; $j ++ )
      {
      $px[$k --] = ( ( $i >= 0 and $i < $image->height and $j >= 0 and $j < $image->width ) ? $image->getPixel( $j, $i ) : 3 );
      if ( $k < 0 )
        {
        # this line can be here because 4 divides 96
        print OUT chr( $px[0] + 4 * $px[1] + 16 * $px[2] + 64 * $px[3] );
        $k = 3;
        }
      }

    }

  close OUT;
  }
palette.ppm
Code:
P3
2 2
255
0 0 0 85 85 85 170 170 170 255 255 255
Jellby is offline   Reply With Quote