App-BlurFill-Web
view release on metacpan or search on metacpan
# App::BlurFill::Web
A Dancer2 web interface for
[App::BlurFill](https://metacpan.org/dist/App-BlurFill). It lets a user upload
an image, choose output dimensions, preview the processed result and download
it.
The image-processing API and command-line program live in the separate
App-BlurFill distribution. Keeping the web application here means users of the
API and CLI do not need to install Dancer2, Plack or Starman.
## Running locally
Install the distribution's dependencies, then run:
lib/App/BlurFill/Web.pm view on Meta::CPAN
=head1 SYNOPSIS
# In a PSGI environment
use App::BlurFill::Web;
App::BlurFill::Web->to_app;
=head1 DESCRIPTION
App::BlurFill::Web is a web interface for the App::BlurFill module. It allows users
to upload an image file, specify the desired width and height, and receive a blurred
image file in response.
=head1 ROUTES
=head2 GET /
This route displays a web form where users can upload an image and specify
the desired width and height for the output. The form submits to the POST /blur
route.
=head2 POST /blur
This route accepts an image file upload and optional width and height parameters.
It processes the image and returns an HTML page displaying the blurred image with
a download link and an option to create another image.
=head2 GET /download/:filename
This route serves the processed image file for download. The filename parameter
should match a previously processed image stored in the temporary directory.
=head1 PARAMETERS
lib/App/BlurFill/Web.pm view on Meta::CPAN
Made by <a href="https://links.davecross.co.uk/">Dave Cross</a> /
Code <a href="https://github.com/davorg-cpan/app-blurfill-web">on GitHub</a>
</div>
</div>
</body>
</html>
HTML
};
post '/blur' => sub {
my $upload = upload('image')
or return status 400, { error => 'Missing image file' };
my $orig_name = $upload->filename;
my ($name, $path, $ext) =
File::Basename::fileparse($orig_name, qr/\.[^.]*$/);
return status 400, { error => 'Uploaded file must have a file extension' }
unless $ext;
my $format = lc $ext;
$format =~ s/^\.//;
my %mime = (
lib/App/BlurFill/Web.pm view on Meta::CPAN
);
return status 400, { error => "Unsupported file format: .$format" }
unless exists $mime{$format};
my $width = query_parameters->get('width') || 650;
my $height = query_parameters->get('height') || 350;
my $in_dir = File::Temp::tempdir;
my $in_path = "$in_dir/$name$ext";
$upload->copy_to($in_path);
my $outfile;
eval {
my $blur = App::BlurFill->new(
file => $in_path,
width => $width,
height => $height,
);
$outfile = $blur->process;
} or return status 500, { error => "Processing failed: $@" };
( run in 0.916 second using v1.01-cache-2.11-cpan-b16cb0d3907 )