Try this. Supply an image name on the command line and it will produce an image (junk.jpg) the same size as the original that looks roughly like this:
_____
|\___/|
| | | |
| | | |
| |_| |
|/___\|
where each of the 3 walls, the floor and ceilng are the original image "perspectivated" to fit.
You'll probably have to prefix the filename in the system command with your local favorite image viewer if your on *nix.
#! perl -slw
use strict;
use GD;
my $img = GD::Image->new( $ARGV[ 0 ] );
my( $ox, $oy ) = $img->getBounds();
my $im2 = GD::Image->new( $ox, $oy, 1 );
$im2->copyResampled(
$img,
$ox/4, $oy/4, ## dstXY
0, 0, ## srcXY
$ox/2, $oy/2, ## dstWH
$ox, $oy ## srcWH
);
my( $ys, $ye, $dy ) = ( 0, $oy, $oy/$ox );
for my $x ( 0 .. $ox/4 ) {
$im2->copyResampled(
$img,
$x, $ys+=$dy,
$x*4, 0,
1, $ye-=($dy*2),
4, $oy
);
}
( $ys, $ye, $dy ) = ( $oy/4, $oy/2, $oy/$ox );
for my $x ( 0 .. $ox/4 ) {
$im2->copyResampled(
$img,
$ox*3/4+$x, $ys-=$dy,
$x*4, 0,
1, $ye+=$dy*2,
4, $oy
);
}
my( $xs, $xe, $dx ) = ( 0, $ox, $ox/$oy );
for my $y ( 0 .. $oy/4 ) {
$im2->copyResampled(
$img,
$xs+=$dx, $y,
0, $y*4,
$xe-=$dx*2, 1,
$ox, 4,
);
}
( $xs, $xe, $dx ) = ( $ox/4, $ox/2, $ox/$oy );
for my $y ( 0 .. $oy/4 ) {
$im2->copyResampled(
$img,
$xs-=$dx, $oy*3/4+$y,
0, $y*4,
$xe+=$dx*2, 1,
$ox, 4,
);
}
open IMG, '>:raw', 'junk.jpg' or die $!;
print IMG $im2->jpeg;
close IMG;
system 'junk.jpg';
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
|