$image = <IN> ; only reads one line of the file. By default, a line is defined as ending with "\n". Undefining $/ before the read changes this definition and cause the file to be read as one line.
While you're at it, check for errors, and use the safer 3-arg open.
#! /usr/bin/perl open IN, "<", "abc.gif" or die "Unable to open input file: $!\n"; binmode IN ; local $/ ; $image = <IN> ; close IN ; open OUT, ">", "test.jpg" ; or die "Unable to open output file: $!\n"; binmode OUT ; print OUT $image ; close OUT ;
Update: You could also do it in blocks:
#! /usr/bin/perl open IN, "<", "abc.gif" or die "Unable to open input file: $!\n"; binmode IN ; open OUT, ">", "test.jpg" ; or die "Unable to open output file: $!\n"; binmode OUT ; local $/ = \1024; # Read in 1024 byte blocks. print OUT $_ while <IN>; close IN ; close OUT ;
In reply to Re: create image via binmode
by ikegami
in thread create image via binmode
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |