App-BlurFill

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


### Command line program - `blurfill`

The `blurfill` program is a standard command line program. You run it like
this:

    blurfill [-w width] [-h height] [-o output_filename] image_filename

If width or height are omitted, they default to 650 pixels and 350 pixels
respectively. If the output filename is omitted, then one will be generated
for you. For example, if you start with `picture.png`, then your output will
be written to `picture_blur.png`.

### Web application

There is also a web application bundled in the standard distribution. You can
run it locally using the standard Perl web application runner, `plackup`.

    plackup bin/app.psgi

Once that program is running you can visit the application in your browser by
going to http://localhost:5000/.

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

    $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;
  }
}

=pod

=head1 AUTHOR

Dave Cross <dave@perlhacks.com>

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

  image: <binary image data>
  width: 800
  height: 600

=head2 Using C<curl>

  # This will return HTML with the results page
  curl -X POST -F "image=@path/to/image.jpg" -F "width=800" -F "height=600" http://localhost:3000/blur
  
  # To download the image directly
  curl -OJ http://localhost:3000/download/image_blur.png

=head1 RESPONSE

The POST /blur response will be an HTML page displaying the blurred image with
download options. The GET /download/:filename response will be the actual image file.

=cut

use v5.40;

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

  </style>
</head>
<body>
  <div class="container">
    <h1>BlurFill</h1>
    <p class="subtitle">Perfect crops, zero letterboxing: smart blur-fill from your source image.</p>
    
    <form action="/blur" method="POST" enctype="multipart/form-data">
      <div class="form-group">
        <label for="image">Select Image</label>
        <input type="file" id="image" name="image" accept="image/jpeg,image/jpg,image/png,image/gif" required>
      </div>
      
      <div class="form-group">
        <label>Output Dimensions</label>
        <div class="dimensions">
          <div>
            <label for="width">Width (px)</label>
            <input type="number" id="width" name="width" value="650" min="1" max="4000">
          </div>
          <div>

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


  return status 400, { error => 'Uploaded file must have a file extension' }
    unless $ext;

  my $format = lc $ext;
  $format =~ s/^\.//;

  my %mime = (
    jpg  => 'image/jpeg',
    jpeg => 'image/jpeg',
    png  => 'image/png',
    gif  => 'image/gif',
  );

  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;

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

  return status 404, { error => 'File not found' }
    unless -f $filepath;
  
  # Determine content type from extension
  my $ext = lc($filename);
  $ext =~ s/.*\.//;
  
  my %mime = (
    jpg  => 'image/jpeg',
    jpeg => 'image/jpeg',
    png  => 'image/png',
    gif  => 'image/gif',
  );
  
  my $content_type = $mime{$ext} || 'application/octet-stream';
  
  send_file(
    $filepath,
    system_path => 1,
    content_type => $content_type,
  );



( run in 2.143 seconds using v1.01-cache-2.11-cpan-df04353d9ac )