Image-Magick-Square
view release on metacpan or search on metacpan
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Image-Magick-Square
version: 1.003
version_from: lib/Image/Magick/Square.pm
installdirs: site
requires:
Image::Magick: 4
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.30
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Image::Magick::Square',
VERSION_FROM => 'lib/Image/Magick/Square.pm',
PREREQ_PM => {
'Image::Magick' => '4',
},
($] >= 5.005 ?
(AUTHOR => 'leo charre <leocharre@cpan.org>') : ()),
);
Image/Magick/Square version 0.01
=========================================
This module will take an existing Image::Magick object and crop as needed
to make a square. Useful for making square thumbnails together with
Image::Magick::Thumbnail
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make install
DEPENDENCIES
This module requires these other modules and libraries:
Image::Magick
COPYRIGHT AND LICENCE
Copyright (C) 2006 Leo Charre
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
lib/Image/Magick/Square.pm view on Meta::CPAN
package Image::Magick::Square;
use Carp;
use vars qw($VERSION);
use strict;
use warnings;
$VERSION = sprintf "%d.%03d", q$Revision: 1.3 $ =~ /(\d+)/g;
sub import {
*{Image::Magick::Trim2Square} = \&create;
}
# Image Magick Square
# square an image, chop as needed
sub create {
my $img = shift; # takes image magick object read into
if (not $img) {
warn "no image defined..".__PACKAGE__;
return undef;
lib/Image/Magick/Square.pm view on Meta::CPAN
}
1;
__END__
=pod
=head1 NAME
Image::Magick::Square - Takes image and crops trims to a square shape
=head1 SYNOPSIS
use Image::Magick;
use Image::Magick::Square;
# instance and read in image
my $src = new Image::Magick;
$src->Read('source.jpg');
# square it
my $square = Image::Magick::Square::create($src);
# Save it
$square->Write('square.jpg');
use Image::Magick;
use Image::Magick::Square;
my $i = new Image::Magick;
$i->Read('./my.jpg');
$i->Trim2Square;
$i->Write('./squared.jpg');
=head1 EXAMPLE
To make a square thumbnail:
use Image::Magick::Square;
# Load your source image
my $src = new Image::Magick;
$src->Read('source.jpg');
# resize it down some..
my ($thumb,$x,$y) = Image::Magick::Thumbnail::create($src,50);
# crop to biggest square that will fit inside image.
my ($square_thumb,$side) = Image::Magick::Square::create($thumb);
# Save it
$square_thumb->Write('square_thumb.jpg');
=head1 DESCRIPTION
The subroutine create() takes as argument an ImageMagick image object.
It returns an ImageMagick image object (the thumbnail), as well as the
lib/Image/Magick/Square.pm view on Meta::CPAN
according to the dimensions it already posseses.
This module is useful if you want to make square thumbnails. You should
first make the thumbnail, and then call create(), so as to use less of
the computer's resources.
You can run this conversion on any image magick object.
The subroutine is not exported.
A method is aliased onto Image::Magick::Trim2Square
=head1 SUBS
=head2 Image::Magick::Square::create()
Argument is Image::Magick object.
Trims top and bottom or sides as needed to make it into a square shape.
Returns object.
=head2 Trim2Square()
Is an alias for Image::Magick::Square::create(), it is placed inside the
Image::Magick namespace.
=head1 PREREQUISITES
L<Image::Magick>
=head2 NOTES
Yes, L<Image::Magick::Thumbnail::Fixed> will make a fixed size thumbnail.
It's great, I love it. Except for one thing, it does not take an existing
Image::Magick object to work on. It does too much. It doesn't return an
image object either.
Image::Magick::Square is more a specialized crop then a
"thumbnail subroutine".
This way, you can add more effects, like a shadow, a border, annotate- etc,
I<before> you save or display the image.
=cut
=head2 EXPORT
This basically adds a new method to Image::Magick.
use Image::Magick;
use Image::Magick::Square;
my $i = new Image::Magick;
$i->Read('./my.jpg');
$i->Trim2Square;
If you wish to avoid importing Trim2Square onto the Image::Magick namespace..
use Image::Magick::Square();
=head1 SEE ALSO
L<perl>, L<Image::Magick>, L<Image::GD::Thumbnail>,
L<Image::Magick::Thumbnail>, L<Image::Magick::Thumbnail::Fixed>.
=head1 AUTHOR
Leo Charre leocharre at cpan dot org
=head1 COPYRIGHT
Copyright (C) Leo Charre 2006-2008 all rights reserved.
Available under the same terms as Perl itself.
use Test::Simple 'no_plan';
use lib './lib';
use Image::Magick;
use Image::Magick::Square;
my $abs = './t/Hillary1.jpg';
my $abs1 = $abs.'.sq.jpg';
# 1
my $i = new Image::Magick;
$i->Read($abs);
ok( ! is_square($i),'is not square yet' );
ok( $i->Trim2Square, 'Trim2Square' );
ok( is_square($i),'is square now' );
$i->Write($abs1);
my $s = new Image::Magick;
$s->read($abs1);
ok( is_square($s),'saved is square');
# 2
my $i2 = new Image::Magick;
$i2->Read($abs);
ok( ! is_square($i2),'is not square yet' );
Image::Magick::Square::create($i2);
ok( is_square($i2) ,'is square now');
sub is_square {
my $o = shift;
my($w,$h) = $o->Get('Width','Height');
$h and $w or die;
( run in 0.342 second using v1.01-cache-2.11-cpan-beeb90c9504 )