in reply to Imager : read image from scalar (not from file)

Tldr, but did you try to open from a scalar ref instead of a filename?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re: Imager : read image from scalar (not from file)

Replies are listed 'Best First'.
Re^2: Imager : read image from scalar (not from file)
by bliako (Abbot) on Aug 20, 2018 at 23:19 UTC

    I did ... but not in the way it is specified in the manual of Imager::Files. Thanks for hinting it is possible as I was convinced it wasn't and did not perservere with the manuals ... (maybe they should put this important info under the heading read() or in the Description section of mod:://Imager). The following works for me:

    use strict; use warnings; use Imager; use Imager::Filter::Autocrop; my $imgdata = undef; open(IN, '<', 'example.jpg'); binmode(IN); { local $/ = undef; $imgdata = <IN> } close(IN); my $img = Imager->new(); # possible params are 'file', 'data' and 'fd' $img->read(data=>\$imgdata) or die "read: ".$img->errstr(); $img->filter(type=>'autocrop', fuzz=>20) or die "autocrop: ".$img->err +str(); $img->write(file=>'out.jpg') or die "writing: ".$img->errstr();

    Edit: actually it is not documented in Imager::Files that data is a recognised input param name for read(). It is only mentioned in the write(). Anyway, all well now.

      The section on Input and output in Imager::Files describes the I/O options you can supply for read(), write(), read_multi() and write_multi().

      There's an example using read() from a scalar in the Imager::Files SYNOPSIS.

        I have totally missed the one in the SYNOPSIS, sorry. Should I use a scalar for read and a ref for write?:

        $img->read(data => $data) or die; or $img->write(data => \$data, type => $type) or die;
      It's documented for open °

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      °) i.e. I was guessing.