laziness, impatience, and hubris | |
PerlMonks |
Discipulus has asked for the wisdom of the Perl Monks concerning the following question:
I'm experimenting with images again but I'm stucked at image rotation using GD. Documentation says:
> $image->copyRotated($sourceImage,$dstX,$dstY,$srcX,$srcY,$width,$height,$angle) Like copyResized() but the $angle argument specifies an arbitrary amount to rotate the image clockwise (in degrees). In addition, $dstX and $dstY species the center of the destination image, and not the top left corner.
The following code seems to rotate counter clockwise instead (pass to the following program a jpg image and optionally a degrees value):
use strict; use warnings; use GD; print "GD version : $GD::VERSION\n"; print "libgd version: ",GD::VERSION_STRING,"\n"; my $original_jpg = $ARGV[0]; my $angle = $ARGV[1] ? $ARGV[1] : 90; my $gd = GD::Image->new( $original_jpg ); my $gdrot = new GD::Image($gd->width, $gd->height ); $gdrot->copyRotated( $gd, # source $gd->width/2, # X center of the destinat +ion image $gd->height/2, # Y center of the destinat +ion image 0, # X specify the upper left + corner of a rectangle in the source image 0, # Y specify the upper left + corner of a rectangle in the source image $gd->width, # final width $gd->height, # final height $angle # rotation angle clockwise + in degrees ); open my $fh,'>', "rotated_".$angle."_".$original_jpg or die $!; binmode $fh; print $fh $gdrot->jpeg;
Did you see the same result as me? I see the resulting image rotated 90° counter clockwise (I'd say counter documentwise ;). In early tests I got a warning about older version of gdlib (like: libgd 2.0.33 or higher required for copyRotated ) and I upgraded my GD.pm using cpan client and everything went fine.
I currently have: GD version : 2.66 libgd version: 2.2.4
Any insight appreciated.
L*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Image rotation with GD: counter or clockwise?
by rurban (Scribe) on Feb 23, 2021 at 15:59 UTC | |
Re: Image rotation with GD: counter or clockwise?
by LanX (Saint) on Feb 23, 2021 at 13:43 UTC | |
Re: Image rotation with GD: counter or clockwise? -- FIXED doc
by Discipulus (Canon) on Jan 26, 2022 at 09:59 UTC | |
Re: Image rotation with GD: counter or clockwise?
by karlgoethebier (Abbot) on Feb 23, 2021 at 20:17 UTC | |
by Discipulus (Canon) on Feb 23, 2021 at 21:18 UTC | |
by LanX (Saint) on Feb 23, 2021 at 21:31 UTC | |
by Aldebaran (Curate) on Feb 24, 2021 at 06:25 UTC | |
by marto (Cardinal) on Feb 24, 2021 at 09:52 UTC |