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

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.

Replies are listed 'Best First'.
Re^3: Imager : read image from scalar (not from file)
by tonyc (Hermit) on Aug 21, 2018 at 06:16 UTC

    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;
Re^3: Imager : read image from scalar (not from file)
by LanX (Saint) on Aug 20, 2018 at 23:40 UTC
    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.