Created
March 12, 2015 04:45
-
-
Save gray/2c9f540ddeef81d023ba to your computer and use it in GitHub Desktop.
Solves image jigsaw puzzles created by http://flash-gear.com/puzzle/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.012; | |
use warnings; | |
use File::Temp; | |
use IPC::System::Simple qw(capture system); | |
use LWP::UserAgent; | |
use URI; | |
use URI::QueryParam; | |
my $url = shift || die 'missing url'; | |
my $ua = LWP::UserAgent->new; | |
my $res = $ua->get($url); | |
die $res->status_line unless $res->is_success; | |
my $content = $res->decoded_content // $res->content // die 'no content'; | |
my @url = $content =~ m[<embed(?: [^>]*?)? src="([^"]+)"]gi; | |
die 'no swf urls found' unless @url; | |
for my $url (@url) { | |
my $uri = URI->new($url); | |
my ($h, $w, $id) = map $uri->query_param($_), qw(h w id); | |
next unless $h and $w and $id; | |
$uri->query_param(c => 'z'); | |
my $swf = File::Temp->new(suffix => '.swf'); | |
my $res = $ua->get($uri, ':content_file' => $swf->filename); | |
my $out = capture swfextract => $swf; | |
my ($ids) = $out =~ /^\s*\[-j\] \d+ JPEGs: ID\(s\) (\d+,.*)/m; | |
$ids // next; | |
my $dir = File::Temp->newdir; | |
system swfextract => '-j', $ids, '--outputformat', "$dir/%05d.%s", $swf; | |
my @jpg = glob "$dir/*.jpg"; | |
$out = capture identify => $jpg[0]; | |
my ($x, $y) = $out =~ / JPEG (\d+)x(\d+)/; | |
next unless $x and $y and $x == $y; | |
$_ = int $_ / $x * 2 for $w, $h; | |
# The edges of each puzzle piece image need to be overlapped. | |
$_ = int $_ / 4 for $x, $y; | |
my $img = "$id.jpg"; | |
system montage => '-tile', "${w}x$h", '-geometry', "-$x-$y", @jpg, $img; | |
} |
I have updated the script and a short how to as a comment in a fork of this one
how do i even use this
I made a fork with updated code that works with all the puzzles, has an user interface so you dont need to manually change the code and has an easy installer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does anybody know how to get this to work?