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

Not sure why when working with any jpg image in this code that is supposed to draw a border around it according to the website: http://wdvl.internet.com/Authoring/Languages/Perl/Weave/auto1-1.html the image comes out corrupted. I am on a windows system and using GD.
use GD; my $image = GD::Image->newFromJpeg('d:\cards\test.jpg'); my $black = $image->colorResolve(0,0,0); my ($width,$height) = $image->getBounds(); $image->rectangle(0,0,($width-1),($height-1),$black); binmode FILE; open(FILE, ">border1.jpg"); print FILE $image->jpeg;

Replies are listed 'Best First'.
Re: Corrupt JPG image in Windows
by Sidhekin (Priest) on Dec 14, 2001 at 21:54 UTC

    Cut & paste from perldoc -f binmode:

    binmode() should be called after open() but before
    any I/O is done on the filehandle.

    So if you just move the binmode line to immediately after the open, you at least stand a better chance.
    (No guarantee; I don't know much about windows, GD, or jpeg. But I do know perldoc :-)

    The Sidhekin
    print "Just another Perl ${\(trickster and hacker)},"

Re: Corrupt JPG image in Windows
by cacharbe (Curate) on Dec 14, 2001 at 21:59 UTC
    swap your binmode and OPEN lines.

    C-.

    update sidhekin is faster.

Re: Corrupt JPG image in Windows
by stormwolfen (Acolyte) on Dec 14, 2001 at 22:11 UTC
    Thanks to the both of you. It worked. :)