Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

imagecopyresampled

Description

The imagecopyresampled of Image for PHP copy and resize part of an image with resampling.

Syntax

imagecopyresampled(
    GdImage $dst_image,
    GdImage $src_image,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $dst_width,
    int $dst_height,
    int $src_width,
    int $src_height
): bool

Parameters

dst_image

Destination image resource.

src_image

Source image resource.

dst_x

x-coordinate of destination point.

dst_y

y-coordinate of destination point.

src_x

x-coordinate of source point.

src_y

y-coordinate of source point.

dst_width

Destination width.

dst_height

Destination height.

src_width

Source width.

src_height

Source height.

Return

Returns true on success or false on failure.

Examples

1 · return

<?

$width = 100;
$height = 100;
$dst_image = imagecreatetruecolor($width, $height);

$src_image = imagecreatetruecolor($width, $height);
$dst_x = 0;
$dst_y = 0;
$src_x = 0;
$src_y = 0;
$dst_width = $width;
$dst_height = $height;
$src_width = $width;
$src_height = $height;

$return = imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_width, $dst_height, $src_width, $src_height);

var_export($return);

?>
true

2 · base64

<?

$width = 100;
$height = 100;
$dst_image = imagecreatetruecolor($width, $height);

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/png/Happy.png';
$src_image = imagecreatefrompng($filename);

$dst_x = 50;
$dst_y = 50;
$src_x = 0;
$src_y = 0;
$dst_width = $width / 2;
$dst_height = $height / 2;
$src_width = $width;
$src_height = $height;
imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_width, $dst_height, $src_width, $src_height);

ob_start();

    imagepng($dst_image);

$output = ob_get_clean();

echo '<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';

?>
<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADp0lEQVR4nO3bv2vyQBgH8O/7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