App-BlurFill

 view release on metacpan or  search on metacpan

lib/App/BlurFill.pm  view on Meta::CPAN


=back

=head2 process

  my $output = $blur_fill->process;
  print "Blurred image saved to: $output\n";

Processes the input image, applies a Gaussian blur, and saves the result as a
new image. Returns the path to the output image file.

=cut

package App::BlurFill; # For MetaCPAN

use v5.40;
use experimental 'class';

class App::BlurFill {
  our $VERSION = '0.1.0';

  use Imager;
  use File::Basename 'fileparse';
  use File::Temp 'tempdir';

  field $file    :param;
  field $width   :param = 650;
  field $height  :param = 350;

  field $imager  :param = do {
    Imager->new(file => $file)
      or die Imager->errstr;
  };

  field $output  :param = do {
    my ($name, $path, $ext) = fileparse($file, qr/\.[^.]*$/);
    $path =~ s[/$][];

    my $dir = caller eq 'App::BlurFill::CLI' ? $path : tempdir(CLEANUP => 1);

    my $filename = "${name}_blur$ext";

    "$dir/$filename";
  };

  method process {
    my $background = $imager->copy;

    $background = $background->scale(xpixels => $width);
    my $bg_height = $background->getheight;
    $background = $background->crop(
      top    => ($bg_height / 2) - ($height / 2),
      bottom => ($bg_height / 2) + ($height / 2),
    );
    $background->filter(type => 'gaussian', stddev => 15);

    my $img = $imager->scale(ypixels => $height);
    my $img_width = $img->getwidth;

    $background->compose(src => $img, left => ($width / 2) - ($img_width / 2));
    $background->write(file => $output, type => 'png') or die $background->errstr;

    return $output;
  }
}

=head1 WEB INTERFACE

The web interface previously included in this distribution was moved to the
separate L<App::BlurFill::Web> distribution in version 0.0.6. Installing
App::BlurFill now provides only the Perl API and the C<blurfill> command-line
program, without requiring Dancer2, Plack, or Starman.

=head1 SEE ALSO

L<App::BlurFill::CLI>, L<App::BlurFill::Web>

=pod

=head1 AUTHOR

Dave Cross <dave@perlhacks.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2025, Magnum Solutions Ltd. All rights reserved.

This is free software; you can redistribute it and/or modify it under the

=cut



( run in 2.875 seconds using v1.01-cache-2.11-cpan-788537b7465 )