CGI-Uploader

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - Using 'transform_method' to tranform an upload in place was broken.
    - Now use File::Spec instead of hardcoding "/" as a path separator. (Ron Savage) 
    - Use binmode() on the right file handle (Ron Savage)
    - upload_id was hardcoded in one place instead of using up_table_map (Ron Savage)

    [DOCUMENTATION]
    - Quit recommending SQL::Abstract in the Cookbook (but we use it internally)

    [INTERNAL]
    - Mark "Image::Size" as a requirement, if only to get tests to stop failing.
      It's only really required if  you use the Image::Magick transformations. 


2.15 Sun Jul 15 07:21:24 EDT 2007
    - no functionality changes

    [INTERNAL]
    - improved importing code style.
    - Clarify docs regarding file_scheme vs. file_name (Jaldhar)

2.14 Thu May 24 13:19:27 EDT 2007

    [BUG FIXES]
    - Avoid SQL error when two column names are the same by giving explicit table name.

2.13 Mon Apr  9 22:39:54 EDT 2007

    [BUG FIXES]	
    - Better Mac OS X detection (Jeff MacDonald)
    - gen_thumb() now works if Image::Magick or Graphics::Magick
      is not already loaded. (Thanks to bug report by Jeff MacDonald,
      RT#20775).

2.12 Thu Feb 15 17:43:20 EST 2007

    [ENHANCEMENTS]
    - Explicitly call File::Temp::cleanup(). This reduces the amount of 
      disk space and file handles used.

    - A new 'temp_dir' option has been added to allow to you set your own

Changes  view on Meta::CPAN

      transform_methods has been introduced. The new syntax looks like this:

         transform_method => gen_thumb({ w => 100, h => 100 }),
   
      The old syntax is still supported.    

    - "gen_thumb()" can now return the Image/Graphics::Magick object as a
      second argument. This may not be useful outside of the test suite...

    [BUG FIXES]
    - Image::Magick is no longer required to install CGI::Uploader, just
      recommended.

    - If an uploaded was updated and had its MIME type changed in the process,
      the old file was left on the file system. Fixed. 

    - If 'up_table_map' was used to modify the name of the extension field, 
      then transform_meta() would return empty values for the extensions. Fixed.

    [INTERNALS]
    - Migrated Makefile.PL to use Module::Install. This allows me to keep the hairy 

Changes  view on Meta::CPAN

    image-specific code from the main package. In it's place a more general 
    "transform_method" option has been added. With this, you can specify 
    any arbitrary transformation you want to make to a file.  You might 
    choose to decrypt a file, compress it, append to it, or otherwise alter
    it. 

    The thumbnailing code still exists, but has been moved to
    CGI::Uploader::Transform::ImageMagick::gen_thumb().

    However, most of the examples and tests still do rely on "gen_thumb()" for
    examples, so test failures will occur if Image::Magick is not installed for
    now. I'd like some help to streamline this. 

    Along the way, I removed the regular expression support to simplify the
    refactoring. It may well come back. 

    Beyond these changes, things are pretty much the same. Let me know
    if you have any feedback on the API before this turns into a stable
    1.0 release.

    Mark Stosberg

Changes  view on Meta::CPAN

    - Added delete_thumbs() method
    - Started to do real 'updates' rather than delete/re-inserts
	- Cleaned up prequisites in Makefile.PL
	- Fixed bug and added test for proper thumbnail resizing
    - More API refactors

0.63_01
    - Removed some un-needed mentions of Data::FormValidator from tests
    - added test to verify thumbnail size
    - refactored resize code into gen_thumb(). This will make it easier 
      to support other resize modules besides Image::Magick. 
    - Added Image::Size as a dependency. It's a fast tool for size checking
      which does not depend on a graphics module being installed. 
    - Initial support for resizing with GD as a backup. It needs tested. 

0.62_01
    - Added File::Temp to Makefile.PL. 
    - Refactored to remove store_thumb(). This should help eventually support other
      graphics modules besides Image::Magick

0.61_02
    - Minor POD cleanups

0.61_01
    - Added custom_meta() method for more flexible meta data handled
    - clarified code and extended documentation
    - exposed 'build_loc' function, which may be useful as a utility function,
      or for a sub-class.
    - custom fields are now returned with meta_hashref() 

Makefile.PL  view on Meta::CPAN

use warnings;
use inc::Module::Install;

# Module::Install stuff
{
    no_index directory => 't/lib';
    no_index file => 'examples/friends_photos/FriendsPhotos.pm';

    license ('perl');

   # Graphics::Magick is recommended over Image::Magick, but isn't on CPAN
    recommends
        'Image::Magick'    => 0;

   # This could probably become a "test_requires"
   requires 'Image::Size' => 0;


}


use Config ();
use Getopt::Long();

lib/CGI/Uploader/Cookbook.pod  view on Meta::CPAN

     my_custom_prefix_url    => 'http://localhost/images/uploads/523.pdf',
	 my_custom_prefix_width  => 23,
	 my_custom_prefix_height => 46,
 }

=item * Image Processor

While C<CGI::Uploader> works with all types of file uploads, it contains a number
of features to help with common tasks associated with image uploads.

C<Image::Magick> is the preferred image processing module for to use when
creating the thumbnails. Support for C<GD> is in progress. C<GD> supports many
fewer formats, but also has much fewer dependencies to get installed than
C<Image::Magick> does. Another providers could be used by extending or
overriding the C<gen_thumb()> method.

=back

=head2 Just Three Essential Methods to Learn

A goal of <CGI::Uploader> is to provide a high-level interface to make managing
file uploads easy. Only three methods are needed to manage all the functions needed
to store, update, delete and view the uploads attached to some database entity. Those
methods are C<store_uploads()>, C<delete_checked_uploads()> and C<fk_meta>.

lib/CGI/Uploader/Transform/ImageMagick.pm  view on Meta::CPAN


Looking for a different syntax? See L<BACKWARDS COMPATIBILITY>

This function creates a copy of given image file and resizes the copy to the
provided width and height.

C<gen_thumb> can be called as object or class method. As a class method,
there there is no need to call C<new()> before calling this method.

L<Graphics::Magick> is used as the first choice image service module.
L<Image::Magick> is tried next.

Input:

    filename - filename of source image
    w        - max width of thumbnail
    h        - max height of thumbnail

One or both  of C<w> or C<h> is required.

Output:

lib/CGI/Uploader/Transform/ImageMagick.pm  view on Meta::CPAN

    else {
        ($orig_filename, $params) = validate_pos(@_,1,{ type => ARRAYREF });
        # validate handles a hash or hashref transparently
        %p = validate(@$params,{
                w => { type => SCALAR | UNDEF, regex => qr/^\d*$/, optional => 1, },
                h => { type => SCALAR | UNDEF, regex => qr/^\d*$/, optional => 1 },
            });
    }
    die "must supply 'w' or 'h'" unless (defined $p{w} or defined $p{h});

    # Having both Graphics::Magick and Image::Magick loaded at the same time
    # can cause very strange problems, so we take care to avoid that
    # First see if we have already loaded Graphics::Magick or Image::Magick
    # If so, just use whichever one is already loaded.
    my $magick_module;
    if (exists $INC{'Graphics/Magick.pm'}) {
        $magick_module = 'Graphics::Magick';
    }
    elsif (exists $INC{'Image/Magick.pm'}) {
        $magick_module = 'Image::Magick';
    }

    # If neither are already loaded, try loading either one.
    elsif ( _load_magick_module('Graphics::Magick') ) {
        $magick_module = 'Graphics::Magick';
    }
    elsif ( _load_magick_module('Image::Magick') ) {
        $magick_module = 'Image::Magick';
    }
    else {
        die "No graphics module found for image resizing. Install Graphics::Magick or Image::Magick: $@ "
    }

    my ($thumb_tmp_fh, $thumb_tmp_filename) = tempfile('CGIuploaderXXXXX', UNLINK => 1, DIR => $self->{'temp_dir'});
    binmode($thumb_tmp_fh);

    my $img = $magick_module->new();

    my $err;
    eval {
        $err = $img->Read(filename=>$orig_filename);

lib/CGI/Uploader/Transform/ImageMagick.pm  view on Meta::CPAN

    $target_h = sprintf("%.1d", ($orig_h * $target_w) / $orig_w) unless $target_h;
    $target_w = sprintf("%.1d", ($orig_w * $target_h) / $orig_h) unless $target_w;

    return ($target_w,$target_h);

}




# load Graphics::Magick or Image::Magick if one is not already loaded.
sub _load_magick_module {
    my $module_name = shift;
    return eval "require $module_name";
}

=head2 BACKWARDS COMPATIBILITY

These older, more awkward syntaxes are still supported:

As a class method:

t/gen_thumb.t  view on Meta::CPAN

use lib 't/lib';
use DBI;
use Carp::Assert;
use CGI::Uploader::Test; # provides setup() and read_file()
use strict;

use CGI::Uploader;
use File::Path;

my $found_module = 0;
eval { require Image::Magick; };
$found_module = !$@;
if ($found_module) {
    plan (qw/no_plan/)
}
else {
    eval { require Graphics::Magick; };
    $found_module = !$@;
    if ($found_module) {
        plan (qw/no_plan/)
    }
    else {
        plan skip_all => "No graphics module found for image resizing. Install Graphics::Magick or Image::Magick: $@ ";
    }
}

use CGI::Uploader::Transform::ImageMagick;

 # This should work, even if we don't preload either one
 delete $INC{'Image/Magick.pm'};
 delete $INC{'Graphics/Magick.pm'};

 my ($tmp_filename, $img)  = CGI::Uploader::Transform::ImageMagick->gen_thumb( 't/20x16.png', [ w => 5 ]);



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