#!/usr/bin/perl -w
use strict;
use Image::Magick;

my $image = Image::Magick->new();
$image->ReadImage("/home/mdaoh/Dolls.psd");
my $i = 0;
while (my $layer = $image->[$i]) {
    for my $prop (('[layer-name]', '[layer-xpos]', '[layer-ypos]', '[layer-opacity]')) {
	print STDERR "Layer $i: ", $prop, "='", $layer->Get($prop), "'\n";
    }
    # set  compression
    $layer->Set(magick=>'jpeg', compression=>'jpeg', quality=>'75', density=>"72x72", depth => '8', colorspace => 'rgb');
    # resize
    # $layer->Resize(geometry=>'640x480');

    my $name = $layer->Get('[layer-name]');
    $name =~ s/[^\w]/_/g;
    my $filename = 'dolls-' . $i . '-' . $name . '.jpeg';
    $filename = '/var/www/html/dolls/' . $filename;

    my $x = $layer->Write($filename);

    warn "$x" if "$x";
    $i++;
}
