JPEG::Comment - add comment to JPEG file


JPEG-Comment documentation Contained in the JPEG-Comment distribution.

Index


Code Index:

NAME

Top

JPEG::Comment - add comment to JPEG file

SYNOPSIS

Top

 use JPEG::Comment;

 $commented_image = jpegcomment($uncommented_image, $comment);

DESCRIPTION

Top

The JPEG::Comment package allows you to add comment to jpeg file. It is may be useful in web environment to mark downloaded images in your site. The $commented_image and $uncommented_image is simple strings with image data.

AUTHOR

Top

Ivan Frolcov ifrol@cpan.org


JPEG-Comment documentation Contained in the JPEG-Comment distribution.

package JPEG::Comment;
use Exporter;

use strict;

use vars qw(@ISA $VERSION @EXPORT);
@ISA = qw(Exporter);
@EXPORT=qw(jpegcomment);
$VERSION='0.2';


sub jpegcomment($$){
    my ($image, $comment)=@_;
    $comment.="\0";
    my $i=2; # ¯à®¯ãáâ¨âì «¨¤¨àãî騥 FF SOI
    my(@datas);

    while(1){
      my $data;
      my $pre=unpack('n',substr($image,$i,2));
      if ( $pre == 0xFFDA ){ #ᮡá⢥­­® ª à⨭ª 
         push @datas, substr($image,$i,length($image)-$i);
         last;
      }      
      my $cnt=unpack('n',substr($image,$i+2,2));
      $i+=$cnt+2, next if ( $pre == 0xFFFE ); # ¨§­ ç «ì­ë© ª®¬¬¥­â à¨©. ­ ä¨£ 
      die if ( $pre == 0xFFD8 );              #¨«¨ ª®­¥æ, ª®â®à®£® ¡ëâì ­¥ ¤®«¦­®
      push @datas, substr($image,$i,$cnt+2);
      $i+=$cnt+2;
      last if $i >= length($image);
    }
    @datas= ($datas[0],
             (pack('n n', 0xFFFE, length($comment)+2).$comment),
             @datas[1..$#datas]);

    return pack('n',0xFFD8) . join('', @datas) ;
}

1;
__END__