my $white;
# Create background
my $image = new GD::Image(600, 450);
$white = $image->colorAllocate(255, 255, 255);
$image->filledRectangle(0, 0, 600, 450, $white);
####
$white = $image->colorAllocate(127, 127, 127);
$image->filledRectangle(0, 0, 600, 450, $white);
##
##
open my $fh, '>' ,"$root/images/property/unit/$filename.png";
binmode $fh;
print $fh $image->png;
close $fh;
##
##
# Resize uploaded image to 600 wide
my $picture = GD::Image->new($file{'image', 'file'});
my ($srcw, $srch) = $picture->getBounds();
$newh = int ($srch * 600 / $srcw);
my $resize = GD::Image->new(600, $newh);
$resize->copyResized($picture, 0, 0, 0, 0, 600, $newh, $srcw, $srch);
##
##
open my $fh, '>' ,"$root/images/property/unit/$filename.png";
binmode $fh;
print $fh $resize->png;
close $fh;
##
##
# Copy onto background image offset to crop or center
$image->copy($resize, 0, 0, 0, ($newh - 450) / 2, 600, 450);
##
##
open my $fh, '>' ,"$root/images/property/unit/$filename.png";
binmode $fh;
print $fh $image->png;
close $fh;