stormwolfen has asked for the wisdom of the Perl Monks concerning the following question:

I have been trying to get code posted under the heading Re: How to handle Tk::Photo-data()?

But when I try to run it, the image always comes back black. I have done a literal cut & paste of the code. I am on a windows system. I have also printed the encoded jpg and decoded it using a different application and it still comes back black.

I use this code using the same file that is being encoded and resized in the above link, and it shows fine.

my $mw = MainWindow->new; my $button = $mw->Button()->pack(); my $photo = $button->Photo( -format => 'jpeg', -file => 'found.jpg' ); + $button->configure( -image => $photo ); MainLoop;
Any ideas??

Replies are listed 'Best First'.
Re: Tk::Photo-data() error?
by Albannach (Monsignor) on Dec 16, 2001 at 10:35 UTC
    I tried the code Jouke posted in Re: How to handle Tk::Photo-data()? and actually had to make one change to get it to work on this box (Win95). The GD::Image->new('feather.jpg') causes an error as that form is looking for numeric arguments (being the dimensions of a new image). If you look in the console window you should see the message:
    Use of uninitialized value in concatenation (.) or string at C:/Perl/s +ite/lib/Tk.pm line 350. Argument "feather.jpg" isn't numeric in subroutine entry at tkphoto.pl + line 17.
    If you replace that line of code with:
    my $im = GD::Image->newFromJpeg('feather.jpg');
    You should see an image (provided you have a file of that name of course ;-). It worked for me.

    --
    I'd like to be able to assign to an luser

      Thank you, the line you suggested cleared up my problem. I didn't see the error though. I guess I need to check to see where those errors go when you are using the Open Perl IDE.
(ichimunki) Re: Tk::Photo-data() error?
by ichimunki (Priest) on Dec 16, 2001 at 09:15 UTC
    Nope. No idea. :)

    Your code is missing the lines I would have at the beginning for both use Tk; and use Tk::JPEG;, so that's my first question: are they both there?

    Normally if there is a problem with invalid image data, the script will kick information about that out to STDERR (usually tied to the console while a Tk app is running), so if you're not seeing anything there, then I'm really stumped.

    So if you have both of those use statements, and no errors get reported in the command window, then you're absolutely certain the JPEG is valid and not supposed to be black? :)