#!/usr/bin/perl
#
# Name:
#	im-hax-resize-1.pl.
#
# Purpose:
#	Demonstrate the Resize method.
#
# V 1.00 01-May-2002
# ------------------
# o Initial version
#
# Test environment:
#	OS: WinNT 4 SP 6a
#	Web server: Apache V 1.3.26
#	IM: V 5.4.7
#
# Input files:
#	smile.gif
#
# Output files:
#	96x96.png
#	144x240.png
#
# Note:
#	o tab = 4 spaces || die.
#	o Text reformatted to max 50 chars wide
#		so source can be converted to PDF
#
# Author:
#	Ron Savage <ron@savage.net.au>
#	http://savage.net.au/ImageMagick.html
#
# Licence:
#	Copyright (c) 1999-2002 Ron Savage
#
#	All Programs of mine are
#	'OSI Certified Open Source Software';
#	you can redistribute them and/or modify them
#	under the terms of the Artistic License,
#	a copy of which is available at:
#	http://www.opensource.org/licenses/index.html

use strict;
use warnings;

use Image::Magick;

# -----------------------------------------------

my($work_dir_name)	= '/temp';
my($im_version)		= $Image::Magick::VERSION;

chdir($work_dir_name)
|| die("Can't chdir($$work_dir_name): $!");

print "Image::Magick V $im_version. \n";
print "\n";

my($image_name)		= 'smile.gif';
my($image)			= Image::Magick -> new();
my($result)			=
	$image -> Read($image_name);
die $result if $result;
my($x, $y)			=
	$image -> Get('width', 'height');
print "Image: $image_name. Size: $x x $y. \n";
# 0 .. $image_count = 2 images.
my($image_count)	= 1;
my(@x)				= (2 * $x, 3 * $x);
my(@y)				= (2 * $y, 5 * $y);
# This code keeps all images in memory at once.
#my(@image)			=
#	map{$image -> Clone()} 0 .. $image_count;
#@image				=
#	map{$image[$_] -> Resize
#	(
#		width	=> $x[$_],
#		height	=> $y[$_]
#	) $image[$_]} 0 .. $image_count;
#my(@name)			=
#	map
#	{
#		"png:$x[$_]x$y[$_].png"
#	} 0 .. $image_count;
#
#for (0 .. $image_count)
#{
#	print "Saving image: $name[$_]. \n";
#	$result = $image[$_] -> Write($name[$_]);
#	die $result if $result;
#}

my($new_image, $new_name);

for (0 .. $image_count)
{
	$new_name	= "$x[$_]x$y[$_].png";
	$new_image	= $image -> Clone();
	$result		= $new_image -> Resize
	(
		width	=> $x[$_],
		height	=> $y[$_]
	);
	die $result if $result;
	print "Saving image: $new_name. \n";
	$result = $new_image -> Write($new_name);
	die $result if $result;
}
