user
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion.

Bilinear interpolation is linear interpolation in 2 dimensions, and is typically used for image scaling and for 2D finite element analysis.

Task

Open an image file, enlarge it by 60% using bilinear interpolation, then either display the result or save the result to a file.
assistant
(formerly Perl 6)

```
#!/usr/bin/env perl6

use v6;
use GD::Raw;

# Reference:
# https://github.com/dagurval/perl6-gd-raw

my $fh1 = fopen('./Lenna100.jpg', "rb") or die;
my $img1 = gdImageCreateFromJpeg($fh1);

my $fh2 = fopen('./Lenna100-larger.jpg',"wb") or die;

my $img1X = gdImageSX($img1);
my $img1Y = gdImageSY($img1);

my $NewX = $img1X * 1.6;
my $NewY = $img1Y * 1.6;

gdImageSetInterpolationMethod($img1, +GD_BILINEAR_FIXED);

my $img2 = gdImageScale($img1, $NewX.ceiling, $NewY.ceiling);

gdImageJpeg($img2,$fh2,-1);

gdImageDestroy($img1);
gdImageDestroy($img2);

fclose($fh1);
fclose($fh2);

```

Output:

```
file Lenna100*
Lenna100.jpg:        JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, baseline, precision 8, 512x512, frames 3
Lenna100-larger.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 96x96, segment length 16, comment: "CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), default quality", baseline, precision 8, 820x820, frames 3
```