Why not adopt me?
NAME
GD::Image::CopyIFS - fractal-based image copying and resizing
SYNOPSIS
# zoom in on an area of an image
use GD::Image::CopyIFS;
my $width = 64;
my $height = 60;
my $scale = 4;
my $neww = $scale * $width;
my $newh = $scale * $height;
my $src_file = 'src.jpeg';
my $src_img = GD::Image->newFromJpeg($src_file, 1);
my $dst_img = GD::Image->new($neww, $newh, 1);
my @opts = ($src_img, 0, 0, 110, 120,
$neww, $newh, $width, $height);
$dst_img->copyIFS(@opts);
my $dst_file = 'dst.jpeg';
open(my $fh, '>', $dst_file) or die "Cannot open $dst_file: $!";
binmode $fh;
print $fh $im->jpeg;
close $fh;
# create a resized image scaled by a factor $scale
use GD::Image::CopyIFS;
my $src_file = 'src.jpeg';
my $src_img = GD::Image->newFromJpeg($src_file, 1);
my $scale = 2.45;
my $dst_img = GD::Image->thumbIFS($src_img, scale => $scale);
my $dst_file = 'dst.jpeg';
open(my $fh, '>', $dst_file) or die "Cannot open $dst_file: $!";
binmode $fh;
print $fh $im->jpeg;
close $fh;
DESCRIPTION
This module adds to the GD::Image
module of GD
two methods: copyIFS
, used to copy and resize an area of one image onto another image, and thumbIFS
, used to create a rescaled image from an original. The copyIFS
method is used analagously to the copyResized
or copyResampled
methods of the GD
module.
The algorithm employed uses what is known as a fractal interpolating function, which uses an Iterated Function System (IFS) to interpolate functions specified at discrete points. The basic procedure is to create an IFS based on the pixel colors of an image, and then from this construct a new IFS based on the parameters specified when rescaling an area of the image. A random iteration algorithm is then used to construct an image from this new IFS. For details, see http://ecommons.uwinnipeg.ca/archive/00000026/.
Note that this algorithm may give good results for images of natural objects, as there is generally a fractal nature present in most such shapes. It typically will not give good results for more geometric shapes, such as lettering.
FUNCTIONS
$dst_img->copyIFS(@opts)
-
This method, which is used analagously to the
copyResized
andcopyResampled
methods of theGD
module, copies an area of one image onto another image. The options are specified as$dst_img->copyIFS($srcImg, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH, $min_factor, $max_factor);
which takes the source of the image contained in the
GD::Image
object$srcImg
and copies an area starting at($srcX, $srcY)
, of size($srcW, $srcH)
, to the destination$dst_img
, starting at($dstX, $dstY)
, of size($dstW, $dstH)
. Two optional paramaters,$min_factor
and$max_factor
, may also be specified:- min_factor
-
This number, between 0 and 1, determines the minimum fraction of the destination points to be colored by the IFS algorthm. The remainder simply use the nearest available pixel to determine the colour. Values very close to 1 will produce better looking images, but will take longer. A default of 0.999999 is used if not specified.
- max_factor
-
This number, greater than 1, determines the maximum number of iterations that the IFS algorithm uses. A value of 1 will have this iteration number equal to the number of pixels in the destination; increasing this value will produce better looking images, but at the expense of speed. Reasonable values are around 5-10. A default of 7 is used if not specified.
The default values of
min_factor
andmax_factor
will be used if these are not passed tocopyIFS
, but if you want to specify them, both must be given. $dst_img->thumbIFS($src_img, %args)
-
This method created a resized image from the source image specified in the
GD::Image
object$src_img
, according to the arguments specified. These may be one of the following:scale => $scale
-
This will scale the image by an amount specified by
$scale
. x => $x, y => $y
-
This will create a resized image of size
($x, $y))
. If the specifications of either$x
or$y
are omitted, it will be calculated from the proportional scaling specified by the other coordinate. max => $max
-
This will create an image of maximum size
$max
pixels. This will, respectively, be either be the width or the height of the resized image, depending on if the original image has a larger width or height.
SEE ALSO
AUTHOR
Copyright (c) 2005, by Randy Kobes <r.kobes@uwinnipeg.ca>. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.