perlimagemagickmontageperlmagick

How do I "read" from an existing image object instead of a file path with PerlMagick?


The following code generates a 300x100 image using a 100x100 tile as a source image:

for (my $i = 0; $i < 3; $i++) {
    $image->Read("filepath/100x100.png");
}

$result = $image->Montage(geometry=>'100x100',tile=>'3x1');

How do I reach the same result while only reading once from disk?


Solution

  • It's not obvious from the docs, but you can add clones to the image sequence like this:

    $image->Read("filepath/100x100.png");
    $image->[1] = $image->[0]->Clone();
    $image->[2] = $image->[0]->Clone();
    
    $result = $image->Montage(geometry=>'100x100',tile=>'3x1');