File-Properties

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

			    Fcntl => 0,
			    File::Type => 0,
			    File::Basename => 0,
			    Digest::SHA => 0,
			    IO::File => 0,
			    File::Temp => 0,
			    Compress::Bzip2 => 0,
			    Compress::Zlib => 0,
			    Storable => 0,
			    Image::ExifTool => 0,
			    Image::Magick => 0,
			    Time::HiRes => 0,
			    Test::More => 0},
    'NO_META'           => 1
);

README  view on Meta::CPAN

  Fcntl
  File::Type
  File::Basename
  Digest::SHA
  IO::File
  File::Temp
  Compress::Bzip2
  Compress::Zlib
  Storable
  Image::ExifTool
  Image::Magick
  Time::HiRes
  Test::More

COPYRIGHT AND LICENCE

Copyright (C) 2010-2011 Brendt Wohlberg  <wohl@cpan.org>

This library is available under the terms of the GNU General Public
License (GPL), version 2, described in the GPL file included in this
distribution.

lib/File/Properties/Image.pm  view on Meta::CPAN

package File::Properties::Image;
our $VERSION = 0.02;

use File::Properties::Error;
use File::Properties::Media;

require 5.005;
use strict;
use warnings;
use Error qw(:try);
use Image::Magick;


our $DCRawBin = 'dcraw'; # DCRaw utility binary
our $RawBufferSize = 1048576; # Buffer size for use in raw image handling
our $CacheTableName = 'ImageFileCache';
our $CacheTableCols = ['ContentDigest TEXT','ImageDigest TEXT'];


# ----------------------------------------------------------------------------
# Constructor

lib/File/Properties/Image.pm  view on Meta::CPAN

# ----------------------------------------------------------------------------
sub _imagedigest {
  my $fhnd = shift; # File handle

  # Ensure that $fhnd is an IO::Handle object
  throw File::Properties::Error("Argument is not an IO::Handle",$fhnd)
    if (not defined $fhnd or not $fhnd->isa('IO::Handle'));
  # Ensure that file handle position is at the start of the file
  _seek0($fhnd) or
    throw File::Properties::Error("Seek on file handle failed",$fhnd);
  ## Initialise Image::Magick object, read in image pointed to by
  ## $fhnd, and check for errors
  my $imgk = Image::Magick->new;
  my $err = $imgk->Read(file=>$fhnd);
  throw File::Properties::Error("ImageMagick error: $err") if 0+$err < 1;
  ## Construct temporary file and write image data to it
  my $tmp = File::Temp->new;
  $err = $imgk->Write(file=>$tmp,filename=>"rgb:");
  # Return file handle position to start of file
  _seek0($tmp) or
    throw File::Properties::Error("Seek on file handle failed",$tmp);
  ## Compute SHA-512 digest on file containing image data
  my $sha = Digest::SHA->new(512);

lib/File/Properties/Image.pm  view on Meta::CPAN

  File::Properties::Image::_cacheinit($fpc);

Initialise the image properties cache table in the cache referred to
by the File::Properties::Cache reference argument.

=back

=head1 SEE ALSO

L<File::Properties>, L<File::Properties::Cache>, L<File::Properties::Media>,
L<Image::Magick>

=head1 AUTHOR

Brendt Wohlberg E<lt>wohl@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2010,2011 by Brendt Wohlberg

This library is available under the terms of the GNU General Public

t/05media.t  view on Meta::CPAN

# `make test'. After `make install' it should work as `perl 05media.t'

#########################

use Test::More tests => 10;
BEGIN { use_ok('File::Properties::Cache');
        use_ok('File::Properties::Media') };
use Error qw(:try);
use Time::HiRes qw(gettimeofday tv_interval);
use File::Temp;
use Image::Magick;

#########################

## Create a File::Properties::Cache object attached to a temporary
## database file
my $tmpdb = File::Temp->new(EXLOCK => 0, SUFFIX => '.db');
my $opts = {};
ok(my $fpc = File::Properties::Media->cache($tmpdb->filename, $opts));

# Create a temporary test image file

t/05media.t  view on Meta::CPAN


exit 0;


# Create a temporary image file of the specified dimensions
sub tmpimgfile {
    my $hdim = shift;
    my $vdim = shift;

    my $fh = File::Temp->new;
    my $im = Image::Magick->new(size=>$hdim."x".$vdim,depth=>8);
    $im->ReadImage("xc:gray");
    $im->AddNoise(noise=>'Gaussian', channel=>'All');
    $im->Write(file=>$fh, filename=>"png:");
    $fh->seek(0,0);
    return $fh;
}

t/06properties.t  view on Meta::CPAN

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 06properties.t'

#########################

use Test::More tests => 9;
BEGIN { use_ok('File::Properties') };
use Error qw(:try);
use Time::HiRes qw(gettimeofday tv_interval);
use File::Temp;
use Image::Magick;
use Compress::Bzip2;

#########################

## Create a File::Properties::Cache object attached to a temporary
## database file
my $tmpdb = File::Temp->new(EXLOCK => 0, SUFFIX => '.db');
my $opts = {};
ok(my $fpc = File::Properties->cache($tmpdb->filename, $opts));

t/06properties.t  view on Meta::CPAN


exit 0;


# Construct a temporary bzip2 compressed image file
sub tmpbz2imgfile {
    my $hdim = shift;
    my $vdim = shift;

    my $fh1 = File::Temp->new;
    my $im = Image::Magick->new(size=>$hdim."x".$vdim,depth=>8);
    $im->ReadImage("xc:gray");
    $im->AddNoise(noise=>'Gaussian', channel=>'All');
    $im->Write(file=>$fh1, filename=>"tif:");
    $fh1->seek(0,0);

    my $fh2 = File::Temp->new;
    my $bz = bzopen($fh2, "wb") or return undef;
    my $buf;
    while ($buf = <$fh1>) {
      $bz->bzwrite($buf);



( run in 0.386 second using v1.01-cache-2.11-cpan-beeb90c9504 )