
\section{im-hax-1-13}
\filbreak \subsubsection{readme.txt}
.\newline{}
\begin{verbatim}

# Name:
#   readme.txt
#
# Author:
#   Ron Savage <ron@savage.net.au>
#
# Home:
#   http://savage.net.au/ImageMagick.html

Overview
--------
o   ImageMagick Hax are a set of Perl scripts aimed at people beginning to use
    the Perl module Image::Magick. The aim is to get you up and running as
    quickly as possible.

o   You are expected to study the scripts before running them. Hence the
    promise: No surprises.

o   Each hax is deliberately designed to be trivial, so as to help focus on
    one feature of ImageMagick. The name of the hax tells you the point of
    the exercise. Eg: im-hax-crop-1.pl demonstrates Crop(...).
    It's that simple. This helps deliver on the promise: No surprises.

o   *.cgi are CGI scripts, and *.pl are command line scripts. A simple menu
    script, im-hax-menu.cgi, is supplied to help run the CGI scripts.

o   Comments at the start of each hax list the assumed directory structure,
    input files and output files. These are also stored in variables at the
    start of each script, to facilitate installation anywhere.

o   All input files are either shipped with ImageMagick or output from a hax.
    Eg: The output of im-hax-rotate-1.pl is input to im-hax-composite-1.pl.

o   Only the generic TTF file, Generic.ttf is used to annotate images. Nothing
    would be gained here by using a different font file.

Files
-----
o   im-hax-1-13.tgz contains ImageMagick Hax 1 .. 13, as well as the CGI menu,
    licence.txt and this file, readme.txt.

o   im-hax-14-26.tgz contains ImageMagick Hax 14 .. 26, as well as the CGI menu,
    licence.txt and this file, readme.txt.

o   im-hax-27-39.tgz contains ImageMagick Hax 27 .. 39, as well as the CGI menu,
    licence.txt and this file, readme.txt.
\end{verbatim}
\filbreak \subsubsection{im-hax-annotate-1.cgi}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl -T
#
# Name:
#   im-hax-annotate-1.cgi.
#
# Purpose:
#   Demonstrate the Annotate method.
#
# V 1.03 30-Jul-2002
# ------------------
# o Loop over a number of fonts
#
# V 1.02 20-Jun-2002
# ------------------
# o Change stroke => 'red' to stroke => 'none'
#   to get sharper text.
#
# V 1.01 20-Feb-2002
# ------------------
# o Don't use $ENV{'TT_FONT_PATH'} in IM V 5.4.3.
#   Put font in same dir as script
# o Patch Apache httpd.conf to match. Ie:
#   PassEnv MAGICK_HOME
# o Remove TT_FONT_PATH from environment
#
# V 1.00 1-Oct-2001
# -----------------
# o Initial version
#
# Test environment:
#   OS: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   ./Generic.ttf.
#
# Output files:
#   /apache/htdocs/im-hax-annotate-1.gif.
#
# 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 CGI;
use CGI::Carp qw/fatalsToBrowser/;
use Image::Magick;

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

my($inner_table_color)  = '#80c0ff';
my($outer_table_color)  = '#80ffff';

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

delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS',
    'PATH', 'SHELL'}; # For security.

my($doc_root_name)  = '/apache/htdocs';
my($title)          = 'Test Annotate()';

my($q)      = CGI -> new();
my($html)   = [];
my($format) = 'png';

push(@$html, $q -> th('Image::Magick') .
    $q -> td("V $Image::Magick::VERSION") );
push(@$html, $q -> th('&nbsp;') .
    $q -> td('&nbsp;') );
push(@$html, $q -> th('Image format') .
    $q -> td($format) );
push(@$html, $q -> th('&nbsp;') .
    $q -> td('&nbsp;') );

# stroke => 'none', fill => 'red' produces
# sharper text than stroke => 'red',
# fill => 'red'.

my($font);

for $font ('Generic.ttf', 'Arial-Italic',
    'NewCenturySchlbk-Italic')
{
    my($output_file_name)   = "$font.$format";
    my($output_path)        =
        "$doc_root_name/$output_file_name";
    my($image)              =
        Image::Magick -> new(size => '300x36');
    my($result)             =
        $image -> Read('xc:white') || 'OK';

    $result = $image -> Annotate
    (
        text        => 'Annotation',
        x           => 10,
        y           => 34,
        stroke      => 'none',
        font        => $font,
        pointsize   => 32,
        fill        => 'red'
    ) || 'OK';

    push(@$html, $q -> th('Font') .
        $q -> td($font) );
    push(@$html, $q -> th('Annotate(...)') .
        $q -> td($result) );

    $result =
        $image -> Write($output_path) || 'OK';

    push(@$html, $q -> th("Write(...)") .
        $q -> td($result) );
    push(@$html, $q -> th('Image') .
        $q -> td
        (
            $q -> img
            ({src => "/$output_file_name"})
        ) );
    push(@$html, $q -> th($q -> hr() ) .
        $q -> td($q -> hr() ) );
}

push(@$html, $q -> th('&nbsp;') .
    $q -> td('&nbsp;') );
push(@$html, $q -> th('Main Menu') .
    $q -> td
    (
        $q -> a
        ({
class => 'submit',
href => '/cgi-bin/ImageMagick/im-hax-menu.cgi',
        }, 'im-hax-menu.cgi') ) );

print   $q -> header(),
        $q -> start_html($doc_root_name),
        $q -> center($q -> h1($title) ),
        $q -> table
        (
            {
                align   => 'center',
                bgColor => $inner_table_color,
            },
            $q -> Tr([@$html])
        ),
        $q -> end_html();
\end{verbatim}
\filbreak \subsubsection{im-hax-border-1.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-border-1.pl.
#
# Purpose:
#   Demonstrate the Border.
#
# 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: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   /apache/htdocs/smile.gif
#
# Output files:
#   /apache/htdocs/im-hax-border-1.gif
#
# 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)      = '/apache/htdocs';
my($input_file_name)    =
    $doc_root_name . '/smile.gif';
my($output_file_name)   =
    $doc_root_name . '/im-hax-border-1.gif';
my($image)              = Image::Magick -> new();
my($result)             =
    $image -> Read($input_file_name);
warn $result if $result;

$result = $image -> Border
(
    width   => 4,
    height  => 4,
    fill    => 'red',
);
warn $result if $result;

$result = $image -> Write($output_file_name);
warn $result if $result;
print "Success. Wrote $output_file_name. \n";
\end{verbatim}
\filbreak \subsubsection{im-hax-composite-1.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-composite-1.pl.
#
# Purpose:
#   Demonstrate the Composite method.
#
# 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: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   /apache/htdocs/smile.gif
#   /apache/htdocs/grin.gif
#   (Ie smile.gif output by im-hax-rotate-1.pl)
#
# Output files:
#   /apache/htdocs/im-hax-composite-1.gif
#
# 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)      = '/apache/htdocs';
my($input_file_name_a)  =
    $doc_root_name . '/smile.gif';
my($input_file_name_b)  =
    $doc_root_name . '/grin.gif';
my($output_file_name)   =
    $doc_root_name . '/im-hax-composite-1.gif';
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";
\end{verbatim}
\filbreak \subsubsection{im-hax-composite-2.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-composite-2.pl.
#
# Purpose:
#   Demonstrate the Composite method.
#
# 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: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   /apache/htdocs/smile.gif
#   /apache/htdocs/old-pix/*
#
# Output files:
#   /apache/htdocs/new-pix/*
#
# 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)  = '/apache/htdocs';
my($old_dir_name)   =
    $doc_root_name . '/old-pix';
my($new_dir_name)   =
    $doc_root_name . '/new-pix';

opendir(INX, $old_dir_name);
my(@pix) = grep{! /^\./} readdir(INX);
closedir(INX);

die("$old_dir_name does not contain any images")
    if ($#pix < 0);

my($composite_op)           = 'Over';
my($water_mark_file_name)   =
    $doc_root_name . '/smile.gif';
my($water_mark)             =
    Image::Magick -> new();
my($result)                 =
    $water_mark -> Read($water_mark_file_name);
print   "Error: Image: ",
        "$water_mark_file_name. $result. \n"
        if ($result);
my($m_width, $m_height, $m_size, $m_fmt) =
    $water_mark -> Ping($water_mark_file_name);

for (@pix)
{
    my($image)                          =
        Image::Magick -> new();
    my($width, $height, $size, $fmt)    =
        $image -> Ping("$old_dir_name/$_");

    print   "Reading $_ ",
            "(geometry => $width x $height, ",
            "size => $size, format => $fmt)",
            "... \n";
    $result = $image -> Read("$old_dir_name/$_");
    print   "Error: Image: $_. $result. \n"
            if ($result);

    my($x)  = int( ($width - $m_width) / 2);
    my($y)  = int( ($height - $m_height) / 2);
    $result = $image -> Composite
    (
        compose => $composite_op,
        image   => $water_mark,
        x       => $x,
        y       => $y,
    );
    print   "Error: Image: $_. $result. \n"
            if ($result);
    print   "Composed. Image: $_. ",
            "Operation: $composite_op. \n";

    $result = $image->Write("$new_dir_name/$_");
    print   "Error: Image: $_. $result. \n"
            if ($result);
    print "Success: Wrote $new_dir_name/$_. \n";
    print "\n";
}
\end{verbatim}
\filbreak \subsubsection{im-hax-contrast-1.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-contrast-1.pl.
#
# Purpose:
#   Demonstrate the Contrast method.
#
# 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: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   ./Generic.ttf
#   /apache/htdocs/model.gif
#
# Output files:
#   /apache/htdocs/im-hax-contrast-1.gif
#
# 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)      = '/apache/htdocs';
my($input_file_name)    =
    $doc_root_name . '/model.gif';
my($output_file_name)   =
    $doc_root_name . '/im-hax-contrast-1.gif';
my($count)              = 4;
my($i_before)           = Image::Magick -> new();
my($result)             =
    $i_before -> Read($input_file_name);
warn $result if $result;
my($i_true) = Image::Magick -> new();
$result     = $i_true -> Read($input_file_name);
warn $result if $result;
my($i_false)    = Image::Magick -> new();
$result         =
    $i_false -> Read($input_file_name);
warn $result if $result;
while ($count--)
{
    $result = $i_true -> Contrast
    (
        sharpen => 'true',
    );
    warn $result if $result;
    $result = $i_false -> Contrast
    (
        sharpen => 'false',
    );
    warn $result if $result;
}
my($stack)  = Image::Magick -> new();
push(@$stack, $i_false);
push(@$stack, $i_before);
push(@$stack, $i_true);
my($final) = $stack -> Montage
(
    title       => 'false + model + true',
    font        => 'Generic.ttf',
    pointsize   => 32,
    tile        => '3x1',
    stroke      => 'red',
    borderwidth => 2);
$result = $final -> Write($output_file_name);
warn $result if $result;
print "Success. Wrote $output_file_name. \n";
\end{verbatim}
\filbreak \subsubsection{im-hax-crop-1.cgi}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl -T
#
# Name:
#   im-hax-crop-1.cgi.
#
# Purpose:
#   Demonstrate the Crop method.
#
# V 1.01 20-Feb-2002
# ------------------
# o Don't use $ENV{'TT_FONT_PATH'} in IM V 5.4.3.
#   Put font in same dir as script
# o Patch Apache httpd.conf to match. Ie:
#   PassEnv MAGICK_HOME
# o Remove TT_FONT_PATH from environment
#
# V 1.00 1-Oct-2001
# ------------------
# o Initial version
#
# Test environment:
#   OS: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   /apache/htdocs/model.gif.
#
# Output files:
#   /apache/htdocs/modelette.gif.
#
# 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 CGI;
use CGI::Carp qw/fatalsToBrowser/;
use Image::Magick;

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

my($inner_table_color)  = '#80c0ff';
my($outer_table_color)  = '#80ffff';

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

delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS',
    'PATH', 'SHELL'}; # For security.

my($doc_root_name)      = '/apache/htdocs';
my($input_file_name)    = 'model.gif';
my($input_path)         =
    "$doc_root_name/$input_file_name";
my($output_file_name)   = 'modelette.gif';
my($output_path)        =
    "$doc_root_name/$output_file_name";
my($title)              = 'Test Crop()';

my($image, $result);

my($q)      = CGI -> new();
my($html)   = [];
$image      = Image::Magick -> new();

push(@$html, $q -> th('Image::Magick') .
    $q -> td("V $Image::Magick::VERSION") );
push(@$html, $q -> th('Image::Magick -> new()') .
    $q -> td('OK') );

$result = $image -> Read($input_path) || 'OK';
push(@$html, $q -> th($input_path) .
    $q -> td($result) );
push(@$html, $q -> th('Image before') .
    $q -> td
    (
        $q -> img
        ({
            name    => 'annotate',
            src     => "/$input_file_name",
        })
    ) );

my($g)  = '70x70+50+50';
$result = $image -> Crop(geometry => $g) || 'OK';
push(@$html, $q -> th("Crop(geometry => $g)") .
    $q -> td($result) );

$result = $image -> Write($output_path) || 'OK';
push(@$html, $q -> th("Write($output_path)") .
    $q -> td($result) );
push(@$html, $q -> th('Image after') .
    $q -> td
    (
        $q -> img
        ({
            name    => 'annotate',
            src     => "/$output_file_name",
        })
    ) );
push(@$html, $q -> th('&nbsp;') .
    $q -> td('&nbsp;') );
push(@$html, $q -> th('Main Menu') .
    $q -> td
    (
        $q -> a
        ({
class   => 'submit',
href    => '/cgi-bin/ImageMagick/im-hax-menu.cgi'
        }, 'im-hax-menu.cgi') ) );

print   $q -> header(),
        $q -> start_html({title => $title}),
        $q -> h1({align => 'center'}, $title),
        $q -> table
        (
            {
                align   => 'center',
                bgColor => $inner_table_color,
            },
            $q -> Tr($html)
        ),
        $q -> end_html();
\end{verbatim}
\filbreak \subsubsection{im-hax-gif2jpg-1.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-gif2jpg-1.pl.
#
# Purpose:
#   Demonstrate the output of JPGs.
#   The point of this demo is that ImageMagick
#   alone is all that is required to output JPGs.
#
# 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: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   /apache/htdocs/smile.gif
#
# Output files:
#   /apache/htdocs/im-hax-gif2jpg-1.jpg
#
# 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)      = '/apache/htdocs';
my($input_file_name)    =
    $doc_root_name . '/smile.gif';
my($output_file_name)   =
    $doc_root_name . '/im-hax-gif2jpg-1.jpg';
my($image)              = Image::Magick -> new();
my($result)             =
    $image -> Read($input_file_name);
warn $result if $result;
$result = $image -> Write($output_file_name);
warn $result if $result;
print "Success. Wrote $output_file_name. \n";
\end{verbatim}
\filbreak \subsubsection{im-hax-gradient-1.cgi}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl -T
#
# Name:
#   im-hax-gradient-1.cgi.
#
# Purpose:
#   Demonstrate the Read(gradient) method.
#
# Adapted from:
#   imagedemo1.pl by Dylan Beattie
#   http://dent.riviera.org.uk/~dylan//magick/
#
# V 1.01 20-Feb-2002
# ------------------
# o Don't use $ENV{'TT_FONT_PATH'} in IM V 5.4.3.
#   Put font in same dir as script
# o Patch Apache httpd.conf to match. Ie:
#   PassEnv MAGICK_HOME
# o Remove TT_FONT_PATH from environment
#
# V 1.00 1-Oct-2001
# -----------------
# o Initial version
#
# Test environment:
#   OS: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   None.
#
# Output files:
#   /apache/htdocs/im-hax-gradient-1a.png.
#   /apache/htdocs/im-hax-gradient-1b.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 CGI;
use CGI::Carp qw/fatalsToBrowser/;
use Image::Magick;

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

my($inner_table_color)  = '#80c0ff';
my($outer_table_color)  = '#80ffff';

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

delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS',
    'PATH', 'SHELL'}; # For security.

my($doc_root_name)      = '/apache/htdocs';
my($output_file_name_a) =
    'im-hax-gradient-1a.png';
my($output_file_name_b) =
    'im-hax-gradient-1b.png';
my($output_path_a)      =
    "$doc_root_name/$output_file_name_a";
my($output_path_b)      =
    "$doc_root_name/$output_file_name_b";
my($title)              = 'Test Read(Gradient)';

my($image, $result);

my($q)      = CGI -> new();
my($html)   = [];
$image      = Image::Magick -> new;
$result     =
    $image -> Set(size => '30x180') || 'OK';

push(@$html, $q -> th('Image::Magick') .
    $q -> td("V $Image::Magick::VERSION") );
push(@$html, $q -> th('Image::Magick -> new()') .
    $q -> td('OK') );
push(@$html, $q -> th("Set(size => '30x180')") .
    $q -> td($result) );

my($g)  = '#ff0000-#0000ff';
$result = $image -> Read("gradient:$g") || 'OK';
push(@$html, $q -> th("Read(gradient:$g)") .
    $q -> td($result) );

$result = $image -> Raise('3x3') || 'OK';
push(@$html, $q -> th("Raise('3x3')") .
    $q -> td($result) );

$result = $image -> Write($output_path_a)
    || 'OK';
push(@$html, $q -> th("Write($output_path_a)") .
    $q -> td($result) );
push(@$html, $q -> th('Image') .
    $q -> td
    (
        $q -> img
        ({
            name    => 'imagedemo1',
            src     => "/$output_file_name_a",
        })
    ) );

$result = $image -> Rotate(-90) || 'OK';
push(@$html, $q -> th('Rotate(-90)') .
    $q -> td($result) );

$result = $image -> Write($output_path_b)
    || 'OK';
push(@$html, $q -> th("Write($output_path_b)") .
    $q -> td($result) );
push(@$html, $q -> th('Image') .
    $q -> td
    (
        $q -> img
        ({
            name    => 'gradient',
            src     => "/$output_file_name_b",
        })
    ) );
push(@$html, $q -> th('&nbsp;') .
    $q -> td('&nbsp;') );
push(@$html, $q -> th('Main Menu') .
    $q -> td
    (
        $q -> a
        ({
class   => 'submit',
href    => '/cgi-bin/ImageMagick/im-hax-menu.cgi'
        }, 'im-hax-menu.cgi') ) );

print   $q -> header(),
        $q -> start_html($doc_root_name),
        $q -> h1({align => 'center'}, $title),
        $q -> table
        (
            {
                align   => 'center',
                bgColor => $inner_table_color,
            },
            $q -> Tr($html)
        ),
        $q -> end_html();
\end{verbatim}
\filbreak \subsubsection{im-hax-image2blob-1.cgi}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl -T
#
# Name:
#   im-hax-image2blob-1.cgi.
#
# Purpose:
#   Demonstrate the Image2Blob.
#
# V 1.01 20-Feb-2002
# ------------------
# o Don't use $ENV{'TT_FONT_PATH'} in IM V 5.4.3.
#   Put font in same dir as script
# o Patch Apache httpd.conf to match. Ie:
#   PassEnv MAGICK_HOME
# o Remove TT_FONT_PATH from environment
#
# V 1.00 25-Jun-2001
# ------------------
# o Initial version
#
# Test environment:
#   OS: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   /apache/htdocs/smile.gif.
#
# Output files:
#   none.
#
# 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 CGI;
use CGI::Carp qw/fatalsToBrowser/;
use Image::Magick;

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

delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS',
    'PATH', 'SHELL'}; # For security.

my($doc_root_name)  = '/apache/htdocs';
my($image_format)       = 'gif';
my($image_name)         = 'smile';
my($input_path)         =
"$doc_root_name/$image_name.$image_format";
my($title)              = 'Test Image2Blob()';

my($q)      = CGI -> new();
my($image)  = Image::Magick->new();
my($result) = $image -> Read($input_path) || 'OK';
my(@blob)   = $image -> ImageToBlob();

print   $q -> header
        ({
            type => "image/$image_format",
        }),
        $blob[0];
\end{verbatim}
\filbreak \subsubsection{im-hax-menu.cgi}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl -T
#
# Name:
#   im-hax-menu.cgi.
#
# Purpose:
#   Provide a simple menu system for the hax.
#
# V 1.01 20-Feb-2002
# ------------------
# o Restrict menu to *.cgi files
#
# V 1.00 17-Jan-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:
#   None.
#
# Output files:
#   None.
#
# 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 CGI qw/nobr/;
use CGI::Carp qw/fatalsToBrowser/;

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

my($inner_table_color)  = '#80c0ff';
my($outer_table_color)  = '#80ffff';

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

delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS',
    'PATH', 'SHELL'}; # For security.

my($q)          = CGI -> new();
my($html)       = [];
my($title)      = 'ImageMagick Hax Menu';
my($dir_name)   = '/apache/cgi-bin/ImageMagick';

opendir(INX, $dir_name) ||
    die("Can't opendir($dir_name): $!");
my(@menu) = sort grep
                {
                    /^im-hax.+\.cgi$/ &&
                    ! /im-hax-menu/
                } readdir(INX);
closedir(INX);

# Put an even # of items into @menu.

if ( ($#menu % 2) == 0)
{
    my($script) = $q -> url();
    $script     =~ s/.+\///;

    push(@menu, $script);
}

print   $q -> header(),
        $q -> start_html({title => $title}),
        $q -> table
        (
            {
                align   => 'center',
                bgColor => $inner_table_color,
            },
            $q -> caption($title),
            $q -> Tr
            ([
                map
                {
                    my($i) = 2 * $_;

                    $q -> td
                    (
                        $q -> a
                        ({
                            href    => $menu[$i],
                        }, $menu[$i])
                    ) .
                    $q -> td
                    (
                        $q -> a
                        ({
                            href => $menu[$i+1],
                        }, $menu[$i + 1])
                    ),
                    $q -> td('&nbsp;')
                } 0 .. int($#menu / 2)
            ])
        ),
        $q -> end_html();
\end{verbatim}
\filbreak \subsubsection{im-hax-montage-1.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-montage-1.pl.
#
# Purpose:
#   Demonstrate the Montage method.
#
# 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: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   ./Generic.ttf
#   /apache/htdocs/model.gif
#   /apache/htdocs/smile.gif
#
# Output files:
#   /apache/htdocs/im-hax-montage-1.gif
#
# 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)      = '/apache/htdocs';
my($input_file_name_1)  =
    $doc_root_name . '/model.gif';
my($input_file_name_2)  =
    $doc_root_name . '/smile.gif';
my($output_file_name)   =
    $doc_root_name . '/im-hax-montage-1.gif';
my($stack)              = Image::Magick -> new();
my($image)              = Image::Magick -> new();
my($result)             =
    $image -> Read($input_file_name_1);
warn $result if $result;

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

push(@$stack, $image);
push(@$stack, $j);

my($final) = $stack -> Montage
(
    title       => 'model + smile',
    label       => 'model,smile',
    font        => 'Generic.ttf',
    pointsize   => 32,
    tile        => '2x2',
    stroke      => 'red',
    shadow      => 'true',
    borderwidth => 2,
    frame       => '2x2',
);

$result = $final -> Write($output_file_name);
warn $result if $result;
print "Success. Wrote $output_file_name. \n";
\end{verbatim}
\filbreak \subsubsection{im-hax-rotate-1.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-rotate-1.pl.
#
# Purpose:
#   Demonstrate the Rotate method.
#
# 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: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   /apache/htdocs/smile.gif.
#
# Output files:
#   /apache/htdocs/grin.gif
#   (Ie: input to im-hax-composite-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)      = '/apache/htdocs';
my($input_file_name)    =
    $doc_root_name . '/smile.gif';
my($output_file_name)   =
    $doc_root_name . '/grin.gif';
my($image)              = Image::Magick -> new;
my($result)             =
    $image->Read($input_file_name);
warn $result if $result;

$result = $image->Rotate(-90);
warn $result if $result;

$result = $image->Write($output_file_name);
warn $result if $result;
print "Success. Wrote $output_file_name. \n";
\end{verbatim}
\filbreak \subsubsection{im-hax-transparent-1.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-transparent-1.pl.
#
# Purpose:
#   Demonstrate the Transparent method.
#
# V 1.01 20-Jun-2002
# ------------------
# o Output to current directory
# o Use stroke => 'none', not '#000000'.
#   You should try both, and other colors too.
#
# V 1.01 20-Feb-2002
# ------------------
# o Output to same dir as other hax
# o Put a border round the image
#
# V 1.00 1-Oct-2001
# -----------------
# o Initial version
#
# Test environment:
#   OS: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   ./Generic.ttf
#
# Output files:
#   im-hax-transparent-1.gif
#
# 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';

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

my($im_version) = $Image::Magick::VERSION;
print "Image::Magick V $im_version. \n";
print "\n";

my($output_file_name)   =
    'im-hax-transparent-1.gif';
my($image)              =
    Image::Magick -> new(size => '200x100');
# Try 'xc:black' or 'gradation:black-black'.
my($result)             =
    $image -> Read('xc:green');
warn $result if $result;

$result =
    $image -> Transparent(color => 'green');
warn $result if $result;

# stroke => 'none', fill => 'cyan' produces
# sharper text than stroke => 'black',
# fill => 'cyan'.

$result = $image -> Annotate
(
    text        => 'Transparent',
    x           => 10,
    y           => 50,
    stroke      => 'none',
    font        => 'Generic.ttf',
    pointsize   => 40,
    fill        => 'cyan',
);
warn $result if $result;

$result = $image -> Border
(
    width   => 2,
    height  => 2,
    fill    => 'cyan',
);
warn $result if $result;

$result = $image -> Write($output_file_name);
warn $result if $result;
print "Success. Wrote $output_file_name. \n";
\end{verbatim}
\filbreak \subsubsection{im-hax-visible-watermark-1.pl}
.\newline{}
\begin{verbatim}

#!/usr/bin/perl
#
# Name:
#   im-hax-visible-watermark-1.pl.
#
# Purpose:
#   Demonstrate the Composite method.
#
# 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: WinNT 4 SP 6a
#   Web server: Apache V 1.3.26
#   IM: V 5.4.7
#
# Input files:
#   /apache/htdocs/model.gif
#   /apache/htdocs/smile.gif
#
# Output files:
#   /apache/htdocs/im-hax-visible-watermark-1.gif
#
# 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)      = '/apache/htdocs';
my($input_file_name_1)  =
    $doc_root_name . '/model.gif';
my($input_file_name_2)  =
    $doc_root_name . '/smile.gif';
my($output_file_name)   = $doc_root_name .
    '/im-hax-visible-watermark-1.gif';
my($image)              = Image::Magick -> new();
my($result)             =
    $image -> Read($input_file_name_1);
warn $result if $result;
my($mark)   = Image::Magick -> new();
$result     = $mark -> Read($input_file_name_2);
warn $result if $result;
my($i_h, $i_w)          =
    $image -> Get('height', 'width');
my($mark_w, $mark_h)    =
    $mark -> Get('width', 'height');
my($x)                  = $i_w - $mark_w;
my($y)                  = 10;

# You can't use geometry:
#   $image -> Composite
#   (
#       image       => $mark,
#       geometry    => "${x}x$y",
#   );
$result                 = $image -> Composite
(
    image   => $mark,
    x       => $x,
    y       => $y,
);
warn $result if $result;

$result = $image -> Write($output_file_name);
warn $result if $result;
print "Success. Wrote $output_file_name. \n";
\end{verbatim}


