On Tue, 2006-06-06 at 13:13 -0500, [EMAIL PROTECTED] wrote:
> "Mr. Shawn H. Corey" <[EMAIL PROTECTED]> writes:
>
> > use Data::Dumper;
> > print Dumper $self;
>
> Thanks for the pointers... I haven't read it all yet but still trying
> to get this script to run. It is inlined at the end.
>
> Introducing your code causes a new failure and nothing is printed.
>
> [What I'm asking here is quite a lot so if you want to just tell me to
> bug off, that would be taken in stride, and understood]
>
Learning to use Object-Oriented Perl is difficult. The problem is that
since we have seen your script, it's hard to tell you exactly what needs
to be done.
> ============
> errors before:
> Use of uninitialized value in split at ./gen_images line 39.
> Output path is '/var/www/locahost/htdocs/photo/data/'
> Use of uninitialized value in open at lib/Database.pm line 216.
> Use of uninitialized value in concatenation (.) or string at lib/Database.pm
> line 216.
> Cannot read database : No such file or directory at lib/Database.pm
> line 216.
> ===========
> ===========
> errors after introducing the dump:
>
> I inserted:
> use Data::Dumper;
> print Dumper $self;
> exit;
>
> Global symbol "$self" requires explicit package name at ./gen_images line 32.
> Execution of ./gen_images aborted due to compilation errors.
The line: print Dumper $self;
should be just before the line you posted in your earlier post:
$self->_read_file($self->{file});
> ===========
>
> I'm not making any sense of this.
>
> The error at 216 lib/Database.pm involves still more of the OOP
> heirogliphics, Leaving that alone for now. I'd like to just find out
> what is supposed to be getting passed into this script.
>
> I'll post only one of the two cfg files being read and you'll see it
> has very little in it. The documentation with this script appears to
> be out of sync with actual script so hasn't been much help. I suspect
> my problem revolve around miss placing parts of the package. I'm
> hoping if I can just get an idea what is supposed to be getting read
> in and shifted off, I can piece together where things are supposed to be.
>
> First the script, followed by one of two cfg files.
> =============================
> ./gen_images
>
> #!/usr/bin/perl -w
>
> # This script generates the differently sized images for the ShowArt gallery.
> # It needs ImageMagick installed.
>
> # See art/cfg/gen_images.cfg for options and settings.
>
> ##############################################################################
> # Nothing more needs to be changed below.
>
> # This should really use Getopt::Long...
>
> use lib 'lib';
> use strict;
> use File::Spec;
> use File::Find;
> use Database; # the database support
These two modules are not standard:
> use ArtShow::Config;
> use English;
>
> my $VERSION = '0.14';
>
> BEGIN
> {
> $|++; # output buffer off
Bad idea. Most OSes do the right thing without this. You will only want
to turn this on for a socket or a pipe, and only if the software on the
other side reads a character at a time and responds instantly to a
single character. See `perldoc perlvar` and search for
'$OUTPUT_AUTOFLUSH`
> }
>
> my $cfg = ArtShow::Config->new("art/cfg/gen_images.cfg");
> my $art_cfg = ArtShow::Config->new("art/cfg/artshow.cfg");
>
> my $first = shift || 1; # first ID to generate
> my $last = shift || 0; # last ID to generate
>
> my $sizes = shift || $cfg->{sizes}->[0];
> my $output = shift || $cfg->{output_dir}->[0];
> my $org_dir = $cfg->{org_dir}->[0];
> my $print = shift || 0;
>
> my @sizes = split (/\s*,\s*/ , $sizes);
>
> print "Output path is '$output'\n";
> # read the database
> my $db = Database->new( {
> file => $cfg->{database}->[0],
> } );
>
> my $id = $db->first() || 0; # set iterator to first item
>
> while ($id != $first)
> {
> $id = $db->next();
> die ("ID $first is not in the database") if !defined $id;
> }
>
> print "Running as user $UID, group $GID\n";
>
> while (defined $id)
> {
>
> # find the proper input file
> my $item = $db->item($id); my $name = $item->[2];
> $name .= '.jpg' unless $name =~ /\.(tif|jpg|png)$/;
>
> my $f = File::Spec->catfile ($org_dir, $id, $name);
>
> if (!-f $f)
> {
> `./copy_org`;
> }
>
> print "Extracting EXIF for image ID $id from:\n '$f'\n";
> my $image_exif = $f; $image_exif =~ s/\.(png|tif)$/.jpg/;
>
> # extract EXIF data
> my $exif_file = "$art_cfg->{exif_dir}->[0]/$id.txt";
> `./exif "$image_exif" $exif_file`;
>
> print "$id: ";
> my $qs = {
> 1280 => 90,
> 1024 => 77, 800 => 76, 640 => 75, 480 => 74, 320 => 73,
> 240 => 70, 200 => 70, 128 => 70, 100 => 69, 80 => 68,
> 64 => 67 };
>
> foreach my $size ( @sizes )
> {
> my $o = File::Spec->catfile( $output, $id, $id.'_' . $size . '.jpg');
> # make the dir where we need to put the file in
> my $o_dir = File::Spec->catdir( $output, $id);
> print "Creating $o_dir\n" and mkdir $o_dir unless -d $o_dir;
> chmod 0777, $o_dir;
>
> $item->[14] = '' if !defined $item->[14];
> my @sharp_factor = (split (/\s*,\s*/, $item->[14] || '1.2,1.2'));
>
> $sharp_factor[0] = '1.1' if $size < 240;
> $sharp_factor[0] = '1.05' if $size < 128;
> $sharp_factor[1] = '' if $size < 240;
>
> my $geo = $size;
> # rotation
> $item->[15] = '' if !defined $item->[15];
> my $rot = '';
> if (($item->[15]||'') ne '')
> {
> $rot = "-rotate $item->[15] ";
> $geo = int($size * 0.75 * 0.75) if $item->[15] =~ /^(90|270)$/;
> }
>
> my $scale = '';
> $scale = 'scale 0.8,0.8' if $size < 240;
> $scale = 'scale 1.1,1.1' if $size > 640;
> $scale = 'scale 1.2,1.2' if $size > 800;
> $scale = 'scale 2.5,2.5' if $size > 1024;
> my $fscale = ($size / 2400) * 1.6; # 2400 => 1.5,
> 4800 => 3
> $fscale = ($size / 2400) * 1.2 if $rot; # rotated images are
> smaller (75%)
> $scale = "scale $fscale,$fscale" if $print;
>
> my $sharp = "-unsharp $sharp_factor[0]";
> my $second_sharp = '';
> $second_sharp = "-unsharp $sharp_factor[1]" if $sharp_factor[1];
>
> # print "$sharp $second_sharp";
> my $coord = '8,20';
> $coord = '5,15' if $size < 480;
> $coord = '3,15' if $size < 240;
> $coord = '15,20' if $size > 1280;
> # 2400 * 0.02 = 48
> $coord = ($size * 0.015) . ',' . ($size * 0.020) if $print;
> $coord = ($size * 0.020) . ',' . ($size * 0.015) if $print && $rot;
>
> my $color = 'white';
> my $gravity = $item->[18] || '';
> if ($gravity ne 'none')
> {
> ($gravity,$color) = split (/,/, $gravity);
> $color ||= 'white';
> $gravity ||= 'NE';
> $gravity =~ s/S/South/i;
> $gravity =~ s/E/East/i;
> $gravity =~ s/W/West/i;
> $gravity =~ s/N/North/i;
> $gravity = " -gravity $gravity ";
> }
>
> my $gamma = '';
> $gamma = '-gamma ' . $item->[17] if ($item->[17] ||'') ne '';
>
> # get date the image was shot
> my $date = $db->get($item,'shot');
> foreach (qw/long internal short/)
> {
> $date =~ s/\s+\d\d:\d\d\s+//; # remove time
> $cfg->{'copyright_'.$_}->[0] =~ s/##date##/$date/g;
> $date =~ /^(\d\d\d\d)/;
> my $year = $1 || '2003';
> $cfg->{'copyright_'.$_}->[0] =~ s/##year##/$year/g;
> }
>
> # print "c: $cfg->{copyright_long}->[0]\n";
> my $text =
> "-font helvetica -fill $color -draw '$scale text $coord
> \"$cfg->{copyright_long}->[0]\"'";
> $text = "-font helvetica -fill $color -draw '$scale text $coord
> \"$cfg->{copyright_short}->[0]\"'"
> if $size < 240;
> $text = '' if $size < 128;
>
> $text = $gravity . $text
> if $text ne '' && $gravity !~ /^(none|)$/; # ne '' && ne 'none';
> $text = '' if $gravity eq 'none';
>
> my $crop = '';
> $crop = '-crop ' . $item->[16] if ($item->[16] ||'') ne '';
>
> # JPG quality no thumbnail nor exif
> my $quality = $qs->{$size} || 88;
> $quality = $print if $print;
>
> my $p = "$crop $gamma $rot -scale $geo +profile '*' -quality $quality
> $sharp $second_sharp $text" .
> # progressive
> " -interlace Plane -comment '$cfg->{copyright_internal}->[0]'";
> # apply additional parameters
> my $extra = ''; $extra = $item->[24] if ($item->[24] ||'') ne '';
> $p .= " $extra '$f' $o";
> unlink $o;
> print "Couldn't unlink '$o'\n" if -e $o;
> # print "Execute: convert $p\n";
> print "$size ";
> `convert $p`;
> `chmod 664 $o` if -f $o;
> print "Hm, output does not exist. Check permissions.\n" and sleep(10)
> unless -f $o;
> chmod 0664, $o if -f $o;
>
> }
> }
> continue
> {
> print "\n";
> $id = $db->next();
> last if !defined $id;
> last if defined $last && $last != 0 && $id > $last;
> }
>
> ===================
>
>
>
>
>
--
__END__
Just my 0.00000002 million dollars worth,
--- Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>