Likeless has asked for the wisdom of the Perl Monks concerning the following question:
The second piece, (an excerpt from a module), is this:#!/usr/bin/perl -- use File::Spec; use Image::Magick; my $imbase = Image::Magick->new(magick=>'png') or die("Image creation +failed."); # Read the predefined letter PNG for each letter my $x = $imbase->Read(map { File::Spec->catfile('/my/web/httpd/htdocs/ +mt/images/captcha-source/',$_.'.png') } (a..z)); if ($x) { die($x); }
The first piece runs from the command line without error.require Image::Magick; my $imbase = Image::Magick->new(magick=>'png') or return $app->error($app->translate("Image creation failed.")); # Read the predefined letter PNG for each letter in $code my $x = $imbase->Read(map { File::Spec->catfile($base, $_ . '.png') } +split(//, $code)); if ($x) { return $app->error($app->translate("Image error: [_1]", $x)); }
sub _generate_captcha { my $self = shift; my ($app, $code, $format) = @_; $format ||= 'png'; my $len = LENGTH(); my $cfg = $app->config; my $base = $cfg->CaptchaSourceImageBase; unless ($base) { require File::Spec; $base = File::Spec->catfile(MT->instance->config_dir, 'mt-stat +ic', 'images', 'captcha-source'); $base = undef unless (-d $base); } return $app->error($app->translate('You need to configure CaptchaS +ourceImageBase.')) unless $base; require Image::Magick; my $imbase = Image::Magick->new(magick=>'png') or return $app->error($app->translate("Image creation failed." +)); # Read the predefined letter PNG for each letter in $code my $x = $imbase->Read(map { File::Spec->catfile($base, $_ . '.png' +) } split(//, $code)); if ($x) { return $app->error($app->translate("Image error: [_1]", $x)); } # Futz with the size and blurriness of each letter foreach my $i (0..($len - 1)) { my $a = int rand int(WIDTH() / 14); my $b = int rand int(HEIGHT() / 12); $imbase->[$i]->Resize(width => $a, height => $b, blur => rand( +3)); } # Combine all the individual tiles into one block my $tile_geom = join('x', $len, 1); my $geometry_str = join('x', WIDTH(), HEIGHT()); my $im = $imbase->Montage(geometry => $geometry_str, tile => $tile_geom); $im->Blur(); # Add some lines and dots to the image for my $i (0..($len * WIDTH() * HEIGHT() / 14+200-1)) { my $a = int rand($len * WIDTH()); my $b = int rand HEIGHT(); my $c = int rand($len * WIDTH()); my $d = int rand HEIGHT(); my $index = $im->Get("pixel[$a, $b]"); if ($i < ($len * WIDTH() * HEIGHT() / 14+200) / 100) { $im->Draw(primitive => 'line', stroke => $index, points => "$a, $b, $c, $d"); } elsif ($i < ($len * WIDTH() * HEIGHT() / 14+200) / 2) { $im->Set("pixel[$c, $d]" => $index); } else { $im->Set("pixel[$c, $d]" => "black"); } } # Read in the background file my $a = int rand(5) + 1; my $background = Image::Magick->new(); $background->Read(File::Spec->catfile($base, 'background' . $a . ' +.png')); $background->Resize(width => ($len * WIDTH()), height => HEIGHT()) +; $im->Composite(compose => "Bumpmap", tile => 'False', image => $background); $im->Modulate(brightness => 105); $im->Border(fill => 'black', width => 1, height => 1, geometry => join('x', WIDTH() * $len, HEIGHT())); my @blobs = $im->ImageToBlob(magick=>$format); return $blobs[0]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange behaviour from two pieces of similar code in different running environments
by starbolin (Hermit) on May 15, 2008 at 00:26 UTC | |
|
Re: Strange behaviour from two pieces of similar code in different running environments
by psini (Deacon) on May 14, 2008 at 22:06 UTC | |
|
Re: Strange behaviour from two pieces of similar code in different running environments
by moritz (Cardinal) on May 14, 2008 at 22:09 UTC | |
by Likeless (Acolyte) on May 14, 2008 at 22:38 UTC | |
by moritz (Cardinal) on May 15, 2008 at 08:24 UTC | |
|
Re: Strange behaviour from two pieces of similar code in different running environments
by ysth (Canon) on May 15, 2008 at 07:13 UTC | |
|
Re: Strange behaviour from two pieces of similar code in different running environments
by starbolin (Hermit) on May 16, 2008 at 05:56 UTC |