Plack-Middleware-Image-Scale

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    and convert to PNG format.

        ## example2.psgi
        use Plack::Builder;
        use Plack::App::File;
        use Plack::Middleware::Image::Scale;
        my $app = sub { return [200,['Content-Type'=>'text/plain'],['hello']] };
    
        my $thumber = builder {
            enable 'ConditionalGET';
            enable 'Image::Scale',
                width => 200, height => 100,
                flags => { fill => 'ff00ff' };
            Plack::App::File->new( root => 'images' );
        };
    
        builder {
            mount '/thumbs' => $thumber;
            mount '/' => $app;
        };

    A request to /thumbs/foo.png will use images/foo.(png|jpg|gif|jpeg) as
    original, scale it small enough to fit 200x100 px size, fill extra
    borders (top/down or left/right, depending on the original image aspect
    ratio) with cyan background, and convert to PNG format. Also clipping
    is available, see "CONFIGURATION".

DESCRIPTION

    Scale and convert images to the requested format on the fly. By default
    the size and other scaling parameters are extracted from the request
    URI. Scaling is done with Image::Scale.

    The original image is not modified or even accessed directly by this
    module. The converted image is not cached, but the request can be
    validated (If-Modified-Since) against original image without doing the
    image processing. This middleware should be used together a cache
    proxy, that caches the converted images for all clients, and implements
    content validation.

    The response headers (like Last-Modified or ETag) are from the original
    image, but body is replaced with a PSGI content filter to do the image
    processing. The original image is fetched from next middleware layer or
    application with a normal PSGI request. You can use
    Plack::Middleware::Static, or Catalyst::Plugin::Static::Simple for
    example.

    See "CONFIGURATION" for various size/format specifications that can be
    used in the request URI, and "ATTRIBUTES" for common configuration
    options that you can use when constructing the middleware.

ATTRIBUTES

 path

    Must be a RegexpRef, CodeRef, Str or Undef.

    The PATH_INFO is compared against this value to evaluate if the request
    should be processed. Undef (the default) will match always. PATH_INFO
    is topicalized by settings it to $_, and it may be rewritten during
    CodeRef matching. Rewriting can be used to relocate image paths, much
    like path parameter for Plack::Middleware::Static.

    If path matches, next it will be compared against "name". If path
    doesn't match, the request will be delegated to the next middleware
    layer or application.

 match

    Must be a RegexpRef, or CodeRef.

    The PATH_INFO, possibly rewritten during "path" matching, is compared
    against this value to extract name, size and ext. The default value is:

        qr{^(.+)(?:_(.+?))?(?:\.(jpe?g|png|image))$}

    The expression is evaluated in array context and may return three
    elements: name, size and ext. Returning an empty array means no match.
    Non-matching requests are delegated to the next middleware layer or
    application.

    If the path matches, the original image is fetched from
    name."orig_ext", scaled with parameters extracted from size and
    converted to the content type defined by ext. See also "any_ext".

 size

    Must be a RegexpRef, CodeRef, HashRef, Undef.

    The size extracted by "match" is compared against this value to
    evaluate if the request should be processed, and to map it into width,
    height and flags for image processing. Undef will match always and use
    default width, height and flags as defined by the "ATTRIBUTES". The
    default value is:

        qr{^(\d+)?x(\d+)?(?:-(.+))?$}

    The expression is evaluated in array context and may return three
    elements; width, height and flags. Returning an empty array means no
    match. Non-matching requests are delegated to the next middleware layer
    or application.

    Optionally a hash reference can be returned. Keys width, height, and
    any remaining keys as an hash reference, will be unrolled from the hash
    reference.

 any_ext

    If defined and request ext is equal to this, the content type of the
    original image is used in the output. This means that the image format
    of the original image is preserved. Default is image.

 orig_ext

    ArrayRef of possible original image formats. See "fetch_orig".

 memory_limit

    Memory limit for the image scaling in bytes, as defined in
    Image::Scale.



( run in 0.494 second using v1.01-cache-2.11-cpan-5511b514fd6 )