Getting rid of white background after rotate

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
DanEspen
Posts: 2
Joined: 2013-11-26T11:30:11-07:00
Authentication code: 6789

Getting rid of white background after rotate

Post 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.
DanEspen
Posts: 2
Joined: 2013-11-26T11:30:11-07:00
Authentication code: 6789

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

Post 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.
Post Reply