Skip to content

Instantly share code, notes, and snippets.

@stanaka
Created October 15, 2012 15:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stanaka/3892964 to your computer and use it in GitHub Desktop.
Save stanaka/3892964 to your computer and use it in GitHub Desktop.
Generate pdf for analyzing kindle paperwhite resolution
#!/usr/bin/env perl
use strict;
use warnings;
use GD;
sub draw_page {
my ($width, $height) = @_;
return unless $width && $height;
my $im = new GD::Image($width, $height);
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my $red = $im->colorAllocate(255,0,0);
my $blue = $im->colorAllocate(0,0,255);
$im->filledRectangle(0, 0, $width-1, $height-1, $white);
for(my $y = 0; $y < $height; $y += 2){
$im->line(0,$y,$width-1,$y,$black);
}
for(my $x = 0; $x < $width; $x += 2){
$im->line($x, 0, $x, $height-1, $black);
}
my $font_file = "/Library/Fonts/Osaka.ttf";
my ($pos_x, $pos_y) = (100, 100);
my $size = 50;
$im->filledRectangle($pos_x, $pos_y - $size * 1.1, $pos_x + $size * 7, $pos_y + $size * 0.1, $white);
$im->stringFT($black,
$font_file, $size,
0,
$pos_x, $pos_y,
"$width x $height");
open my $out, ">", "output-$width-$height.png";
binmode $out;
print $out $im->png;
close $out;
system("sam2p", "-j:quiet", "output-$width-$height.png", "output-$width-$height.pdf");
return "output-$width-$height.pdf";
}
my @pdfs;
for(my $y = 890; $y < 920; $y++){
push @pdfs, draw_page(560, $y);
};
for(my $x = 645; $x < 675; $x++){
push @pdfs, draw_page($x, 880);
};
push @pdfs, draw_page(659, 905);
push @pdfs, draw_page(658, 906);
push @pdfs, draw_page(658, 905);
system("pdftk", @pdfs, "cat", "output", "output.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment