Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Rotated Cropping in ImageMagick?

by Lawliet (Curate)
on Nov 10, 2008 at 17:29 UTC ( [id://722692]=note: print w/replies, xml ) Need Help??


in reply to Re: Rotated Cropping in ImageMagick?
in thread Rotated Cropping in ImageMagick?

I think the OP was having trouble cropping the rotated image because it was...erm...rotated.

I'm so adjective, I verb nouns!

chomp; # nom nom nom

Replies are listed 'Best First'.
Re^3: Rotated Cropping in ImageMagick?
by Anonymous Monk on Nov 12, 2008 at 10:03 UTC
    Here's what I am planning to use.. This is to get the coordinates of the corners of the cropping box..
    #!/usr/bin/perl -w use strict; use Math::Complex; # box1 is the image my @box1 = (-150,-150,150,-150,150,150,-150,150); #box 2 is the cropping box my @box2 = (-300,-75,0,-75,0,75,-300,75); my @box2r = save_rotate_points(undef,45,@box2); print "Rotate BOX 2\n"; foreach my $x (@box2r) { print $x , "\n"; } my ($x1,$y1,$x2,$y2) = get_rotation_box(undef,@box2r); my @points = ($x1,$y1,$x2,$y1,$x2,$y2,$x1,$y2); print "Bounding Box:\n"; foreach my $x (@points) { print $x , "\n"; } sub save_rotate_points { my ($widget,$angle,@points) = @_; my $count = @points; my (@x, @y); $angle = $angle * pi() / 180; for(my $i = 0; $i < $count ; $i+=2){ my $xp = ($points[$i] * cos($angle)) - ($points[$i+1] * sin($a +ngle)); my $yp = ($points[$i] * sin($angle)) + ($points[$i+1] * cos($a +ngle)); push @x, $xp; push @y, $yp; } @points = ($x[0],$y[0],$x[1],$y[1],$x[2],$y[2],$x[3],$y[3]); return @points; } sub get_center_rectangle { my ($widget,@points) = @_; my $deltax = ($points[0]+$points[2]+$points[4]+$points[6])/4; my $deltay = ($points[1]+$points[3]+$points[5]+$points[7])/4; return $deltax,$deltay; } sub get_rotation_box { my ($widget,@points) = @_; # get smallest value my $i = 0; my ($smallx,$smally,$bigx,$bigy) = (0,0,0,0); foreach my $x (@points) { if($i == 0){ if($x <= $smallx){ $smallx = $x; } if($x >= $bigx){ $bigx = $x; } }else{ if($x <= $smally){ $smally = $x; } if($x >= $bigy){ $bigy = $x; } $i = -1; } $i++; } return $smallx,$smally,$bigx,$bigy; } sub move_points { my ($widget,$mx,$my,@points) = @_; my $i = 0; my @new_points; print $mx," ",$my,"\n"; foreach my $x (@points) { if($i == 0){ print $x , "+" , $mx , "\n"; $x+=$mx; }else{ $x+=$my; $i = -1; } push @new_points, $x; $i++; } return @new_points; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://722692]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-19 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found