Page 1 of 1

Getting rid of white background after rotate

Posted: 2013-11-26T11:48:41-07:00
by DanEspen
I'm trying to take an input file with a shaped image (transparent background) and create a new image showing the original image rotated around the center axis. As this code stands, I only get clear background when the image is rotated an even multiple of 90 degrees.

This is the code I'm using:

Code: Select all

#!/usr/bin/perl
use Image::Magick;
my $image     = Image::Magick->new;
my $new_image = Image::Magick->new;
$image->Read("$ARGV[0]");
my ($my_w, $my_h) = $image->Get('columns', 'rows');
my $new_h = $my_h*16;
$new_image->Set(size=>"${my_w}x${new_h}");
$new_image->Read("xc:none");	# none=transparent

foreach my $i (0..15) {
    my $rot_image = Image::Magick->new;
    $rot_image->Set(size=>"${my_w}x${my_h}");
    $rot_image->Read("xc:none");
#   fixme, need a way to control the background area:
    $rot_image->Composite(
	image=>$image,
	rotate=>22.5*$i);
    $new_image->Composite(image=>$rot_image,y=>($my_h*$i));
    undef $rot_image;
}
my $x = $new_image->Write("$ARGV[1]");
warn "Write failed: $x" if "$x";
I've tried setting a background of none in the Composite command, but debug tells me background isn't a valid option.
I tried setting png:OutsideOverlay to false, but got nothing out of that either.

Clearly I need help. I would have included an image, but so far I don't see how to do that.
On request I'll upload the image to a sharing site.

Re: Getting rid of white background after rotate - solved.

Posted: 2013-11-26T19:15:57-07:00
by DanEspen
Looks like I'm going to answer my own question, the answer seem to be to include color=>'none' in the rotate command. Sorry I couldn't figure that out from the documentation. I just started wondering why color was an argument to the rotate command.