#!/usr/bin/perl
#
# Name:
#	im-hax-composite-1.pl.
#
# Purpose:
#	Demonstrate the Composite method.
#
# V 1.02 06-Jun-2006
# ------------------
# o Upgrade ImageMagick from V 5.4.7 to V 6.2.8
# o Re-check all hax
#
# V 1.01 20-Feb-2002
# ------------------
# o Output to same dir as other hax
#
# V 1.00 1-Oct-2001
# -----------------
# o Initial version
#
# Test environment:
#	OS: WinXP SP2
#	Web server: Apache/2.0.54
#	ImageMagick: V 6.2.8
#
# Input files:
#	o /apache/htdocs/im/logo.jpg
#	o /apache/htdocs/im/im-hax-rotate-1.png
#	(Ie logo.jpg as output by im-hax-rotate-1.pl)
#
# Output files:
#	o /apache/htdocs/im-hax-composite-1.png
#	(Ie input to im-hax-visible-watermark-1.pl)
#
# 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($im_version) = $Image::Magick::VERSION;
print "Image::Magick V $im_version. \n";

my($doc_root_name)		= '/apache2/htdocs/im';
my($input_file_name_a)	=
	$doc_root_name . '/logo.jpg';
my($input_file_name_b)	=
	$doc_root_name . '/im-hax-rotate-1.png';
my($output_file_name)	=
	$doc_root_name . '/im-hax-composite-1.png';
my($image)				= Image::Magick -> new();
my($result)				=
	$image -> Read($input_file_name_a);
warn $result if $result;

my($j)	= Image::Magick -> new();
$result	= $j -> Read($input_file_name_b);
warn $result if $result;

my($i_w, $i_h)	=
	$image -> Get('width', 'height');
my($j_w, $j_h)	= $j -> Get('width', 'height');

print "$input_file_name_a: $i_w x $i_h. \n";
print "$input_file_name_b: $j_w x $j_h. \n";

my($out_w)		= $i_w + $j_w;
my($out_h)		= $i_h; # Assume $i_h == $j_h.
# Warning: No spaces allowed around the 'x'.
my($out_size)	= "${out_w}x$out_h";
my($out)		=
	Image::Magick -> new(size => $out_size);
$result			= $out -> Read('xc:white');
warn $result if $result;

print "$output_file_name: $out_w x $out_h. \n";

$result	= $out -> Composite
(
	compose	=> 'Over',
	image	=> $image,
	x		=> 0,
	y		=> 0,
);
warn $result if $result;

$result	= $out -> Composite
(
	compose	=> 'Over',
	image	=> $j,
	x		=> $i_w,
	y		=> 0,
);
warn $result if $result;

$result = $out -> Write($output_file_name);
warn $result if $result;
print "Success. Wrote $output_file_name. \n";
