<?php
GdImage|false imagescale ( GdImage $image,
int $width,
int $height = -1,
int $mode = IMG_BILINEAR_FIXED )
where,
$image = The image identifier
$width = The width to scale the image to
$height = The height to scale the image to
$mode = The mode to be used
( SEE the below TABLE )
?>
IMAGE INTERPOLATION CONSTANTS | ||
CONSTANT | VALUE | MEANING |
IMG_BELL | 1 | Bell filter |
IMG_BESSEL | 2 | Bessel filter |
IMG_BILINEAR_FIXED | 3 | Fixed point implementation of the bilinear interpolation |
IMG_BICUBIC | 4 | Bicubic interpolation |
IMG_BICUBIC_FIXED | 5 | Fixed point implementation of the bicubic interpolation |
IMG_BLACKMAN | 6 | Blackman window function |
IMG_BOX | 7 | Box blur filter |
IMG_BSPLINE | 8 | Spline interpolation |
IMG_CATMULLROM | 9 | Cubic Hermite spline interpolation |
IMG_GAUSSIAN | 10 | Gaussian function |
IMG_GENERALIZED_CUBIC | 11 | Generalized cubic spline fractal interpolation |
IMG_HERMITE | 12 | Hermite interpolation |
IMG_HAMMING | 13 | Hamming filter |
IMG_HANNING | 14 | Hanning filter |
IMG_MITCHELL | 15 | Mitchell filter |
IMG_NEAREST_NEIGHBOUR | 16 | Nearest neighbour interpolation |
IMG_POWER | 17 | Power interpolation |
IMG_QUADRATIC | 18 | Inverse quadratic interpolation |
IMG_SINC | 19 | Sinc function |
IMG_TRIANGLE | 20 | Triangle interpolation |
IMG_WEIGHTED4 | 21 | NOT YET SUPPORTED Weighting filter |
ed48 |
<?php
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$org_image01 = "jpeg/JPEG 035 01.jpg";
$dst_def01 = "jpeg/JPEG 035 01 imagescale.jpg";
$new_width01 = 480;
echo $org_image01; ?>
<br><br><img src="<?php echo $org_image01; ?>"
alt="<?php echo $org_image01; ?>"><br><br>
<?php
$id__org_img01 = imagecreatefromjpeg($org_image01);
echo '<br><br><br><br>';
$id__scl_def01 =
@imagescale($id__org_img01, $new_width01 );
if($id__scl_def01)
{
imagejpeg ($id__scl_def01, $dst_def01);
echo $dst_def01 . '<br><br><img src="' . $dst_def01 .
'" alt="' . $dst_def01 . '">';
}
else
{
echo 'The image could not be created.';
}
?>
<?php
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$org_image02 = "jpeg/JPEG 036 02.jpg";
$arr_mode02 = [
"IMG_BELL" => [IMG_BELL, 360],
"IMG_BESSEL" => [IMG_BESSEL, 350],
"IMG_BILINEAR_FIXED" => [IMG_BILINEAR_FIXED, 360],
"IMG_BICUBIC" => [IMG_BICUBIC, 340],
"IMG_BICUBIC_FIXED" => [IMG_BICUBIC_FIXED, 330],
"IMG_BLACKMAN" => [IMG_BLACKMAN, 320],
"IMG_BOX" => [IMG_BOX, 370],
"IMG_BSPLINE" => [IMG_BSPLINE, 350],
"IMG_CATMULLROM" => [IMG_CATMULLROM, 360],
"IMG_GAUSSIAN" => [IMG_GAUSSIAN, 330],
"IMG_GENERALIZED_CUBIC" => [IMG_GENERALIZED_CUBIC, 320],
"IMG_HERMITE" => [IMG_HERMITE, 310],
"IMG_HAMMING" => [IMG_HAMMING, 380],
"IMG_HANNING" => [IMG_HANNING, 360],
"IMG_MITCHELL" => [IMG_MITCHELL, 340],
"IMG_NEAREST_NEIGHBOUR" => [IMG_NEAREST_NEIGHBOUR, 320],
"IMG_POWER" => [IMG_POWER, 300],
"IMG_QUADRATIC" => [IMG_QUADRATIC, 280],
"IMG_SINC" => [IMG_SINC, 260],
"IMG_TRIANGLE" => [IMG_TRIANGLE, 260],
"IMG_WEIGHTED4" => [IMG_WEIGHTED4, 240] ];
$id_org_img02 = imagecreatefromjpeg($org_image02);
echo $org_image02;
$sx02 = imagesx($id_org_img02);
$sy02 = imagesy($id_org_img02);
echo '<br><br>( width = ' . $sx02 . 'px X ' . $sy02 . 'px )';
?>
<br><br><img src="<?php echo $org_image02; ?>"
alt="<?php echo $org_image02; ?>"><br><br>
<?php
foreach($arr_mode02 as $mod02 => $md02)
{
$img_scaled02 = 'jpeg/JPEG 036 02 ' . $mod02 . '.jpg';
$id_scaled02 =
imagescale($id_org_img02, $md02[1], -1, $md02[0]);
if($id_scaled02)
{
imagejpeg ($id_scaled02, $img_scaled02);
echo '<br>' . $img_scaled02 . '<br><br>( ' . $md02[0] . ' ) ' .
$mod02 . '<br>( width = ' . $md02[1] . 'px X height = ' .
imagesy($id_scaled02) . 'px )';
echo '<br><br><img src="' . $img_scaled02 . '"
alt="' . $img_scaled02 . ' " width="' . $md02[1] . '"><br><br>';
}
else
{
echo '( ' . $md02[0] . ' ) ' . $mod02 .
'<br>The image could not be created.';
}
}
?>
<?php
$org_image03 = "jpeg/JPEG 037 03.jpg";
$arr_mode03 = [
"IMG_BELL" => [IMG_BELL, 380],
"IMG_BESSEL" => [IMG_BESSEL, 370],
"IMG_BILINEAR_FIXED" => [IMG_BILINEAR_FIXED, 360],
"IMG_BICUBIC" => [IMG_BICUBIC, 340],
"IMG_BICUBIC_FIXED" => [IMG_BICUBIC_FIXED, 330],
"IMG_BLACKMAN" => [IMG_BLACKMAN, 320],
"IMG_BOX" => [IMG_BOX, 390],
"IMG_BSPLINE" => [IMG_BSPLINE, 380],
"IMG_CATMULLROM" => [IMG_CATMULLROM, 370],
"IMG_GAUSSIAN" => [IMG_GAUSSIAN, 330],
"IMG_GENERALIZED_CUBIC" => [IMG_GENERALIZED_CUBIC, 320],
"IMG_HERMITE" => [IMG_HERMITE, 310],
"IMG_HAMMING" => [IMG_HAMMING, 380],
"IMG_HANNING" => [IMG_HANNING, 360],
"IMG_MITCHELL" => [IMG_MITCHELL, 340],
"IMG_NEAREST_NEIGHBOUR" => [IMG_NEAREST_NEIGHBOUR, 320],
"IMG_POWER" => [IMG_POWER, 300],
"IMG_QUADRATIC" => [IMG_QUADRATIC, 280],
"IMG_SINC" => [IMG_SINC, 260],
"IMG_TRIANGLE" => [IMG_TRIANGLE, 260],
"IMG_WEIGHTED4" => [IMG_WEIGHTED4, 240] ];
$new_height03 = 100;
$id_org_img03 = imagecreatefromjpeg($org_image03);
echo basename($org_image03);
$sx03 = imagesx($id_org_img03);
$sy03 = imagesy($id_org_img03);
echo '<br><br>( width = ' . $sx03 . 'px X ' . $sy03 . 'px )';
echo '<br><br><img src="' . $org_image03 .
'" alt="' . $org_image03 . '"><br><br>';
?>
<?php
foreach($arr_mode03 as $mod03 => $md03)
{
$img_scaled03 = 'jpeg/JPEG 037 03 ' . $mod03 . '.jpg';
$id_scaled03 = imagescale($id_org_img03, $md03[1],
$new_height03, $md03[0]);
if($id_scaled03)
{
imagejpeg ($id_scaled03, $img_scaled03);
echo '<br>' . basename($img_scaled03) .
'<br><br>( ' . $md03[0] . ' ) ' .
$mod03 . '<br>( width = ' . $md03[1] . 'px X height = ' .
imagesy($id_scaled03) . 'px )';
echo '<br><br><img src="' . $img_scaled03 . '"
alt="' . $img_scaled03 .
' " width="' . $md03[1] . '"><br><br>';
}
else
{
echo '( ' . $md03[0] . ' ) ' . $mod03 .
'<br>The image could not be created.';
}
}
?>
<?php
$arr_mode04 = [
"IMG_BELL" => IMG_BELL,
"IMG_BESSEL" => IMG_BESSEL,
"IMG_BILINEAR_FIXED" => IMG_BILINEAR_FIXED,
"IMG_BICUBIC" => IMG_BICUBIC,
"IMG_BICUBIC_FIXED" => IMG_BICUBIC_FIXED,
"IMG_BLACKMAN" => IMG_BLACKMAN,
"IMG_BOX" => IMG_BOX,
"IMG_BSPLINE" => IMG_BSPLINE,
"IMG_CATMULLROM" => IMG_CATMULLROM,
"IMG_GAUSSIAN" => IMG_GAUSSIAN,
"IMG_GENERALIZED_CUBIC" => IMG_GENERALIZED_CUBIC,
"IMG_HERMITE" => IMG_HERMITE,
"IMG_HAMMING" => IMG_HAMMING,
"IMG_HANNING" => IMG_HANNING,
"IMG_MITCHELL" => IMG_MITCHELL,
"IMG_NEAREST_NEIGHBOUR" => IMG_NEAREST_NEIGHBOUR,
"IMG_POWER" => IMG_POWER,
"IMG_QUADRATIC" => IMG_QUADRATIC,
"IMG_SINC" => IMG_SINC,
"IMG_TRIANGLE" => IMG_TRIANGLE,
// "IMG_WEIGHTED4" => IMG_WEIGHTED4
];
echo '<pre>';
print_r($arr_mode04);
echo '</pre><br>';
$img04 = imagecreate(300, 300);
$bkg = imagecolorallocate($img04, 250, 5, 255);
$red = imagecolorallocate($img04, 255, 0, 0);
$img_name = "jpeg/JPEG 0037 04.jpg";
$bool04 = imagejpeg($img04, $img_name);
var_dump($img04);
if ($bool04 == true)
{
echo '<br><br>$bool04 = ' . $bool04 .
'<br><br>The image has been created!<br><br>';
echo '<img src="' . $img_name .
'" alt="' . $img_name . '" title="' . $img_name . '">';
foreach($arr_mode04 as $k04 => $v04)
{
$thumbnail = imagescale($img04, 64, -1, $v04);
$dst_name = "jpeg/JPEG 037 04 " . $k04 . "-imagescale.jpg";
imagejpeg($thumbnail, $dst_name);
echo '<br><br>' . $dst_name . '<br><br><img src="' . $dst_name .
'" alt="' . $dst_name . '"><br><br>';
}
}
else
{
echo '<br><br>$bool04 = ' . $bool04 .
'<br><br>The image was NOT created!';
}
// You must try to run this exercise to see the result
?>