GD-Thumbnail
view release on metacpan or search on metacpan
lib/GD/Thumbnail.pm view on Meta::CPAN
my $self = {
DEFAULT_TEXT => undef,
DIMENSION => THUMBNAIL_DIMENSION,
DIMENSION_CONSTRAINT => FALSE, # don't exceed w/h?
FORCE_MIME => EMPTY_STRING, # force output type?
FRAME => FALSE, # add frame?
FRAME_COLOR => BLACK,
GD_FONT => GD_FONT, # info text color
INFO_COLOR => WHITE,
MIME => EMPTY_STRING,
OVERLAY => FALSE, # overlay info strips?
SQUARE => FALSE, # make square thumb?
STRIP_COLOR => BLACK,
STRIP_HEIGHT_BUFFER => STRIP_HEIGHT_BUFFER,
TTF_FONT => undef,
TTF_PTSIZE => DEFAULT_TTF_PTSIZE,
};
$self->{FRAME} = $o{frame} ? 1 : 0;
$self->{SQUARE} = $o{square} ? $o{square} : 0;
$self->{OVERLAY} = ($o{overlay} || $self->{SQUARE}) ? 1 : 0;
for my $name ( qw(
DEFAULT_TEXT
DIMENSION_CONSTRAINT
FORCE_MIME
TTF_PTSIZE
STRIP_HEIGHT_BUFFER
) ) {
next if ! defined $o{ lc $name };
$self->{ $name } = $o{ lc $name };
lib/GD/Thumbnail.pm view on Meta::CPAN
$d = ${$y_ref} * $ry;
${$dy_ref} = (${$y_ref} - $d) / 2;
${$y_ref} = $d;
}
}
if ( ! $opt->{square} || ( $opt->{square} && $opt->{xsmall} ) ) {
# does not work if square & y_is_small,
# since we may have info bars which eat y space
${$ty_ref} = 0; # TODO. test this more and remove from below
${$y_ref} = ${$y_ref} - ${$ty_ref} - $self->{STRIP_HEIGHT_BUFFER}/2 if $opt->{overlay};
}
return;
}
sub create {
my $self = shift;
my $image = shift || croak 'Image parameter is missing';
my $max = shift || DEFAULT_MAX_PIXELS;
my $info = shift || 0;
lib/GD/Thumbnail.pm view on Meta::CPAN
my $dx = 0;
my $dy = $yy2 || 0;
my $xsmall = $x < $def_y;
$self->_setup_parameters(
{
xsmall => $xsmall,
square => $square,
width => $w,
height => $h,
overlay => $o,
},
\$x, \$y, \$dx, \$dy, \$ty
);
$self->_alter_for_crop( $xsmall, \$x, \$y, \$dx, \$dy ) if $crop;
my $resize = $thumb->can('copyResampled') ? 'copyResampled' : 'copyResized';
$thumb->$resize($gd, $dx, $dy, 0, 0, $x, $y, $w, $h);
$thumb->copyMerge( @{$_} ) for @strips;
lib/GD/Thumbnail.pm view on Meta::CPAN
=head3 info_color
Sets the info strip text color. Default is white.
You must pass it as a three element array reference containing
the red, green, blue values:
$thumb = GD::Thumbnail->new(
info_color => [255, 255, 255]
);
=head3 overlay
If you want information strips (see L</create>), but you don't
want to get a longer image, set this to a true value, and
the information strips will not affect the image height
(but the actual thumbnail image will be smaller).
=head3 square
You'll get a square thumbnail, if this is set to true. If the
original image is not a square, the empty parts will be filled
with blank (color is the same as C<strip_color>) instead of
stretching the image in C<x> or C<y> dimension or clipping
it. If, however, C<square> is set to C<crop>, you'll get a
cropped square thumbnail.
Beware that enabling this option will also B<auto-enable> the
C<overlay> option, since it is needed for a square image.
=head3 strip_height_buffer
The y buffer for the strips in pixels.
=head3 strip_color
Sets the info strip background color. Default is black.
You must pass it as a three element array reference containing
the red, green, blue values:
lib/GD/Thumbnail.pm view on Meta::CPAN
| ........... |
| ...IMAGE... |
| ........... |
| ........... |
|_____________|
| 20x20 JPEG |
-------------
As you can see from the examples above, with the default options,
thumbnail image dimension is constant when adding information strips
(i.e.: strips don't overlay, but attached to upper and lower parts of
thumbnail). Each info strip increases thumbnail height by 8 pixels
(if the default tiny C<GD> font C<Tiny> is used).
But see the C<overlay> and C<square> options in L</new> to alter this
behavior. You may also need to increase C<max> value if C<square> is
enabled.
=head2 mime
Returns the thumbnail mime.
Must be called after L</create>.
=head2 width
( run in 0.941 second using v1.01-cache-2.11-cpan-49f99fa48dc )