You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Lee Goddard <ho...@LeeGoddard.com> on 2003/04/08 12:54:39 UTC

[mp2] Filter::CBC; ImageMagick

I'm sure it's to be advised against, but for perverted reasons of my
own I'm trying to use Filter::CBC with mp2. And on Win2k.

Has anyone done this and actually got it working?

I've been tweaking a bit, but no joy so far. Things that worked in
mod_perl1 and on the command line croak after a nasty "can't write to
memory" error.

Or, if you've managed to get the latest ImageMagick/PerlMagick dll
working on the same platform, I'd very much appreciate hearing from
you. Same problem as with Filter::CBC, above.

Thanks in anticipation
lee


Re: [mod_perl2] ImageMagick 'convert'

Posted by Stas Bekman <st...@stason.org>.
> SB> Your case still includes things that I don't have, references to some 
> SB> images... can you trim it down to something that can be used as is? it'd be 
> SB> nice to add this test to mp2 test suite. Some heavy apps are good for testing.
> 
> I'm afraid I can't trim it down to exclude the images, as
> this is an image-based test. But any image will do, and I've
> tried to make it easy by putting the paths in obvious variables at the top.

You can always inline image using uuencoded or similar ascii friendly encoding.

cat /usr/share/doc/perl-IO-stringy-2.108/icons/itembullet.gif | perl -0777 -e 
'print pack("u", <>)' | perl -0777 -e 'print unpack "u", <>' > out.gif

so you convert the binary image into a uuencoded string:

$ cat foo.gif | perl -0777 -e 'print pack("u", <>)'
M1TE&.#=A#P`.`*$``/CX^/C\^*@L4.#DX"P`````#P`.```"'801J7JV'QJ$
7;KYJ<Q):B=]]8B:6V8"F0\>V+-(6`#L`

(-0777 is the same as 'local $/' to slurp the whole thing in)


Now you inline this uuencoded string into a variable in your test and convert 
it to the binary format at run time:

...
$uuencoded = <<EOUU;
M1TE&.#=A#P`.`*$``/CX^/C\^*@L4.#DX"P`````#P`.```"'801J7JV'QJ$
7;KYJ<Q):B=]]8B:6V8"F0\>V+-(6`#L`
EOUU
$binary = unpack("u", $uuencoded);

then you can send this image as if it was a file on the disk.


> SB> Also you don't say anything about your perl build specifics, neither you
> 
> Beg pardon: now attached to the end of this mail.

perl -V is not enough, I ask people to follow the guidelines for a reason :)
http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems

also the next version of mp2 will sport mp2bug script (it's in cvs already).

> SB> mention which ImageMagic lib version do you use and which I::M Perl lib you
> SB> have the trouble with. See:
> SB> http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems
> 
> The very latest: 556 Q16, the official Windows distribution. Whilst
> this IM builds fine, I can't get PerlMagick to build (didn't try very
> hard) so can't say if it's okay with Q8. I do know that it's fine with
> Apache/mp 1, but then the problem only seems to be with multiple
> synchronous requests. Debug is not enabled on the official release.

Dunno if I get to build it. May be tomorrow. Meanwhile a self-containing test 
would be cool.

> SB> May be we will have a better luck, with Filter::CBC as it doesn't rely on any
> SB> external libs (I think).
> 
> Filter::CBC is okay with TwoFish, it's the default Rj that messes it
> up.

Is it hard to write a short test? I haven't used Filter::CBC yet. So I won't 
have to mess with the magic install.

> Also - in the logs quoted in that previous mail, there's an
> interesting warning about v-string not being portable...?

probably complaining about:

our $VERSION = 0.1;

does it help to use "0.1"?

> Thanks for your help and interest, Stas. If I ever get this thing
> working and earning money, there'll defiantly be donations to the
> foundation.

Cool!

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re[2]: [mod_perl2] ImageMagick 'convert'

Posted by Lee Goddard <ho...@LeeGoddard.com>.
Hi Stas,

On Friday, April 11, 2003 at 8:25:09 AM, you wrote:

SB> Lee Goddard wrote:
>> LG> On Wednesday, April 9, 2003 at 1:34:34 AM, Stas wrote:
>> SB>> Lee Goddard wrote:
>> 
>>>>>I'm sure it's to be advised against, but for perverted reasons of my
>>>>>own I'm trying to use Filter::CBC with mp2. And on Win2k.
>>>>>
>>>>>Has anyone done this and actually got it working?
>>>>>
>>>>>I've been tweaking a bit, but no joy so far. Things that worked in
>>>>>mod_perl1 and on the command line croak after a nasty "can't write to
>>>>>memory" error.
>>>>>
>>>>>Or, if you've managed to get the latest ImageMagick/PerlMagick dll
>>>>>working on the same platform, I'd very much appreciate hearing from
>>>>>you. Same problem as with Filter::CBC, above.
>>>>
>> 
>> SB>> You probably want to check who writes "can't write to
>> SB>> memory" error  (perl or the module) and figure why.
>> 
>> LG> If only I could.
>> 
>> SB>> If that fails any chance you can isolate the shortest possible code that I can 
>> SB>> try to reproduce the problem with (I'm on linux, but the problem might be 
>> SB>> similar?)
>> 
>> LG> Yes, thanks: the attached file should explain how it happens.
>> 
>> LG> Thanks in anticipation
>> LG> lee
>> 
>> Attached is the script more pared down - sorry about that.
>> It looks like ImageMagick's composite method, but I don't
>> notice the problem on the command line -- could it still
>> be IM at fault?

SB> Your case still includes things that I don't have, references to some 
SB> images... can you trim it down to something that can be used as is? it'd be 
SB> nice to add this test to mp2 test suite. Some heavy apps are good for testing.

I'm afraid I can't trim it down to exclude the images, as
this is an image-based test. But any image will do, and I've
tried to make it easy by putting the paths in obvious variables at the top.

SB> Also you don't say anything about your perl build specifics, neither you

Beg pardon: now attached to the end of this mail.

SB> mention which ImageMagic lib version do you use and which I::M Perl lib you
SB> have the trouble with. See:
SB> http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems

The very latest: 556 Q16, the official Windows distribution. Whilst
this IM builds fine, I can't get PerlMagick to build (didn't try very
hard) so can't say if it's okay with Q8. I do know that it's fine with
Apache/mp 1, but then the problem only seems to be with multiple
synchronous requests. Debug is not enabled on the official release.

SB> May be we will have a better luck, with Filter::CBC as it doesn't rely on any
SB> external libs (I think).

Filter::CBC is okay with TwoFish, it's the default Rj that messes it
up.

Also - in the logs quoted in that previous mail, there's an
interesting warning about v-string not being portable...?

Thanks for your help and interest, Stas. If I ever get this thing
working and earning money, there'll defiantly be donations to the
foundation.

Cheers
lee

Summary of my perl5 (revision 5 version 8 subversion 0) configuration:
[Binary pre-built by Randy at theory5]
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release  -libpath:"C:\PhotoWebServer\Perl\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"C:\PhotoWebServer\Perl\lib\CORE"  -machine:x86'


Re: [mod_perl2] ImageMagick 'convert'

Posted by Stas Bekman <st...@stason.org>.
Lee Goddard wrote:
> LG> On Wednesday, April 9, 2003 at 1:34:34 AM, Stas wrote:
> 
> SB>> Lee Goddard wrote:
> 
>>>>I'm sure it's to be advised against, but for perverted reasons of my
>>>>own I'm trying to use Filter::CBC with mp2. And on Win2k.
>>>>
>>>>Has anyone done this and actually got it working?
>>>>
>>>>I've been tweaking a bit, but no joy so far. Things that worked in
>>>>mod_perl1 and on the command line croak after a nasty "can't write to
>>>>memory" error.
>>>>
>>>>Or, if you've managed to get the latest ImageMagick/PerlMagick dll
>>>>working on the same platform, I'd very much appreciate hearing from
>>>>you. Same problem as with Filter::CBC, above.
>>>
> 
> SB>> You probably want to check who writes "can't write to
> SB>> memory" error  (perl or the module) and figure why.
> 
> LG> If only I could.
> 
> SB>> If that fails any chance you can isolate the shortest possible code that I can 
> SB>> try to reproduce the problem with (I'm on linux, but the problem might be 
> SB>> similar?)
> 
> LG> Yes, thanks: the attached file should explain how it happens.
> 
> LG> Thanks in anticipation
> LG> lee
> 
> Attached is the script more pared down - sorry about that.
> It looks like ImageMagick's composite method, but I don't
> notice the problem on the command line -- could it still
> be IM at fault?

Your case still includes things that I don't have, references to some 
images... can you trim it down to something that can be used as is? it'd be 
nice to add this test to mp2 test suite. Some heavy apps are good for testing.

Also you don't say anything about your perl build specifics, neither you 
mention which ImageMagic lib version do you use and which I::M Perl lib you 
have the trouble with. See:
http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems

What I have is:
ImageMagick-5.4.8.3-2mdk
libMagick5-5.4.8.3-2mdk
perl-Magick-5.4.8.3-2mdk

neither compiled with debug enabled, and building other versions is not an 
option at this moment, since the dependencies list is too long to screw up my 
system.

May be we will have a better luck, with Filter::CBC as it doesn't rely on any 
external libs (I think).

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


[mod_perl2] ImageMagick 'convert'

Posted by Lee Goddard <ho...@LeeGoddard.com>.
LG> On Wednesday, April 9, 2003 at 1:34:34 AM, Stas wrote:

SB>> Lee Goddard wrote:
>>> I'm sure it's to be advised against, but for perverted reasons of my
>>> own I'm trying to use Filter::CBC with mp2. And on Win2k.
>>> 
>>> Has anyone done this and actually got it working?
>>> 
>>> I've been tweaking a bit, but no joy so far. Things that worked in
>>> mod_perl1 and on the command line croak after a nasty "can't write to
>>> memory" error.
>>> 
>>> Or, if you've managed to get the latest ImageMagick/PerlMagick dll
>>> working on the same platform, I'd very much appreciate hearing from
>>> you. Same problem as with Filter::CBC, above.

SB>> You probably want to check who writes "can't write to
SB>> memory" error  (perl or the module) and figure why.

LG> If only I could.

SB>> If that fails any chance you can isolate the shortest possible code that I can 
SB>> try to reproduce the problem with (I'm on linux, but the problem might be 
SB>> similar?)

LG> Yes, thanks: the attached file should explain how it happens.

LG> Thanks in anticipation
LG> lee

Attached is the script more pared down - sorry about that.
It looks like ImageMagick's composite method, but I don't
notice the problem on the command line -- could it still
be IM at fault?

Thanks
Lee

#! perl

=head1 HOW TO CRASH APACHE2/mp2 WITH IMAGE MAGICK

Just use a handler that makes use of
ImageMagick's C<composite> method.

=head1 IN httpd.conf:

Nothing special intended, just link mod_perl,
Test and the URI /test :

        <Location /test>
                SetHandler perl-script
                PerlResponseHandler Test
                PerlOptions +GlobalRequest
                Options +ExecCGI
                allow from all
        </Location>

=head1 IN test.html:

Just a bunch of HTML image elements whose source
is the above '/test' URI, with anything added -
in this test the filename is just present to ensure
we get different requests.

        <html>
        <head><title>Test</title></head>
        <body>
                <img src='/test/1'/>
                <img src='/test/2'/>
                <img src='/test/3'/>
                <img src='/test/4'/>
                <p>
                        Sometimes it'll take five of the above, sometimes three,
                        to produce the following:
                </p>
                <blockquote><code>
                        [notice] Parent: child process exited with status 3221225477 -- Restarting.
                </code></blockquote>
                <p>
                        Tests were run on a 1.4 gHz Athalon running
                        Win2k SP3, Apache 2.
                </p>
        </body>
        </html>

=head1 LOGS

I have, for reasons unknown, two error logs generated:

>From a fresh start, doing nothing but calling the above
HTML doc once, one reads:

        [Thu Apr 10 18:43:01 2003] [notice] Parent: Created child process 2496
        GNU tar version 1.11.2
        gzip 1.2.4 (18 Aug 93)
        Compilation options:
        NO_DIR SYS_UTIME STDC_HEADERS NO_CHOWN PROTO

        *** Test server starting ... ***
        *** Okay ***
        [Thu Apr 10 19:09:00 2003] [notice] Parent: child process exited with status 3221225477 -- Restarting.

The other sometimes reads like this below, though varies in the
number of requests it manages to handle:

        [Thu Apr 10 18:44:14 2003] [notice] Child 2496: Child process is running
        [Thu Apr 10 18:44:14 2003] [notice] Child 2496: Acquired the start mutex.
        [Thu Apr 10 18:44:14 2003] [notice] Child 2496: Starting 25 worker threads.
        [Thu Apr 10 19:08:52 2003] [error] __PACKAGE__ handling request ...
        [Thu Apr 10 19:08:52 2003] [error] __PACKAGE__ handling request ...
        [Thu Apr 10 19:08:53 2003] [error] About instantiate a new IM object ...
        [Thu Apr 10 19:08:53 2003] [error] About to read watermark ...
        [Thu Apr 10 19:08:53 2003] [error] About to compose first overlay ...
        [Thu Apr 10 19:08:53 2003] [error] About to compose second overlay ...
        [Thu Apr 10 19:08:53 2003] [error] About to write composite to C:/temp/1.jpg ...
        [Thu Apr 10 19:08:54 2003] [error] __PACKAGE__ handling request ...
        [Thu Apr 10 19:08:54 2003] [error] About instantiate a new IM object ...
        [Thu Apr 10 19:08:54 2003] [error] About to read watermark ...
        [Thu Apr 10 19:08:54 2003] [error] About to compose first overlay ...
        [Thu Apr 10 19:08:54 2003] [error] About to compose second overlay ...
        [Thu Apr 10 19:08:54 2003] [error] About to write composite to C:/temp/1.jpg ...

The error logs were produced by the httpd.conf directive:

ErrorLog "|C:/perl58/apache2/bin/rotatelogs.exe C:/perl58/apache2/logs/error.log 1M"

The access log was requested as below, but arrived very late:

TransferLog "|C:/perl58/apache2/bin/rotatelogs.exe C:/perl58/apache2/logs/access.log 1M"

Access log contents:

        127.0.0.1 - - [10/Apr/2003:19:08:52 +0200] "GET /test.html HTTP/1.1" 304 0
        v-string in use/require non-portable at ../../Test.pm line 4.
        v-string in use/require non-portable at ../../Test.pm line 4.
        127.0.0.1 - - [10/Apr/2003:19:08:52 +0200] "GET /test/1 HTTP/1.1" 200 2445
        127.0.0.1 - - [10/Apr/2003:19:08:54 +0200] "GET /test/3 HTTP/1.1" 200 2445

=cut

# Notes at the end
package Test;
our $VERSION = 0.1;
use strict;
use 5.8.0;      # Line 4
use mod_perl 1.99;
use Apache2;

our $IMAGEPATH = "D:/imagearchive/0.jpg";
our $WATERMARK_PATH = "C:/perl58/www/pws/watermarks/northfoto_logo.jpg";
our $PREVIEW_DIR = "C:/temp/";
our ($ID) = $IMAGEPATH =~ /[^\\\/]+$/;

use Apache::Const qw(OK);

sub handler { my $req = shift;
        ;;;$req->log_error("__PACKAGE__ handling request ...");
        $req->send_http_header('image/jpeg');
        my $out_path  = $PREVIEW_DIR.$ID.(time).".jpg";
        my $orig = new Image::Magick;
        my $e = $orig->Read($IMAGEPATH);
        ;;;$req->log_error("Can't read $IMAGEPATH") if $e;
        ;;;$req->log_error("Cloning original ...");
        my $composite = $orig->Clone();
        ;;;$req->log_error("About instantiate a new IM object ...");
        my $watermark = new Image::Magick();
        ;;;$req->log_error("About to read watermark ...");
        $e = $watermark->Read( $WATERMARK_PATH );
        ;;;$req->log_error("About to compose first overlay ...");
        $e = $composite->Composite(
                image=>$watermark,
                compose => 'Multiply',
                x=>0, y=>0,
        );
        ;;;$req->log_error("About to write composite to $out_path ...");
        $e = $composite->Write($out_path);
        ;;;$req->log_error("Can't write composite $e") if $e;
        my $subr = $req->lookup_file($out_path);
        $subr->run;
        return OK;
}

1;
__END__


Re[2]: [mp2] Filter::CBC; ImageMagick

Posted by Lee Goddard <ho...@LeeGoddard.com>.
On Wednesday, April 9, 2003 at 1:34:34 AM, Stas wrote:

SB> Lee Goddard wrote:
>> I'm sure it's to be advised against, but for perverted reasons of my
>> own I'm trying to use Filter::CBC with mp2. And on Win2k.
>> 
>> Has anyone done this and actually got it working?
>> 
>> I've been tweaking a bit, but no joy so far. Things that worked in
>> mod_perl1 and on the command line croak after a nasty "can't write to
>> memory" error.
>> 
>> Or, if you've managed to get the latest ImageMagick/PerlMagick dll
>> working on the same platform, I'd very much appreciate hearing from
>> you. Same problem as with Filter::CBC, above.

SB> You probably want to check who writes "can't write to
SB> memory" error  (perl or the module) and figure why.

If only I could.

SB> If that fails any chance you can isolate the shortest possible code that I can 
SB> try to reproduce the problem with (I'm on linux, but the problem might be 
SB> similar?)

Yes, thanks: the attached file should explain how it happens.

Thanks in anticipation
lee

Re: [mp2] Filter::CBC; ImageMagick

Posted by Stas Bekman <st...@stason.org>.
Lee Goddard wrote:
> I'm sure it's to be advised against, but for perverted reasons of my
> own I'm trying to use Filter::CBC with mp2. And on Win2k.
> 
> Has anyone done this and actually got it working?
> 
> I've been tweaking a bit, but no joy so far. Things that worked in
> mod_perl1 and on the command line croak after a nasty "can't write to
> memory" error.
> 
> Or, if you've managed to get the latest ImageMagick/PerlMagick dll
> working on the same platform, I'd very much appreciate hearing from
> you. Same problem as with Filter::CBC, above.

You probably want to check who writes "can't write to
memory" error  (perl or the module) and figure why.

If that fails any chance you can isolate the shortest possible code that I can 
try to reproduce the problem with (I'm on linux, but the problem might be 
similar?)

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com