Skip to content

Instantly share code, notes, and snippets.

@madsen
Created November 22, 2011 00:07
Show Gist options
  • Save madsen/1384422 to your computer and use it in GitHub Desktop.
Save madsen/1384422 to your computer and use it in GitHub Desktop.
Join the tiles from http://xkcd.com/980/huge/ into a single image
#! /usr/bin/perl
#---------------------------------------------------------------------
# Join the tiles from http://xkcd.com/980/huge/ into a single image
# Copyright 2011 Christopher J. Madsen
#
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
# GNU General Public License or the Artistic License for more details.
#---------------------------------------------------------------------
# First:
# wget http://imgs.xkcd.com/money_tiles5/tile_000_0{00..48}_0{00..32}.png
use strict;
use warnings;
use Image::Magick;
my $tileWidth = 256;
my $tileHeight = 256;
my $img = Image::Magick->new(size => "12528x8352");
$img->ReadImage('xc:white');
$img->Set(units => 'PixelsPerInch');
$img->Set(density => '180x180'); # estimate
for my $r ('00' .. '32') {
print "Processing row $r...\n";
for my $c ('00' .. '48') {
my $i = Image::Magick->new;
$i->Read(filename => "tile_000_0${c}_0$r.png");
$img->Composite(image => $i, x => $c * $tileWidth, y => $r * $tileHeight,
compose => 'over');
} # end for each $c
} # end for each $r
print "Saving image...\n";
$img->Write('xkcd_980_huge.png');
@mseeley
Copy link

mseeley commented Nov 24, 2011

Is the wget command correct? Padding looks off.

$ wget http://imgs.xkcd.com/money_tiles7/tile_000_0{00..48}_0{00..32}.png
--2011-11-23 22:45:08-- http://imgs.xkcd.com/money_tiles7/tile_000_00_00.png
Resolving imgs.xkcd.com (imgs.xkcd.com)... 208.122.62.226
Connecting to imgs.xkcd.com (imgs.xkcd.com)|208.122.62.226|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2011-11-23 22:45:09 ERROR 404: Not Found.

I used Node instead of wget to grab the files, naming sequentially. It's a single line montage call to join. Correctly handles the narrower/shorter tiles at the right and bottom edges; see: https://gist.github.com/1384313

It would be entertaining to reduce this task to two commands and eschew perl and js completely.

@mseeley
Copy link

mseeley commented Nov 24, 2011

Ah, padded number expansion isn't available in Bash 3.2.

$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.
$ echo {0001..5}
1 2 3 4 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment