imagecopyresized

Copy and resize part of an image

Syntax

imagecopyresized(
    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 = imagecopyresized($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;
imagecopyresized($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/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACmElEQVR4nO3aPU7DMBQH8AfsJR1Z2pyg9ARVehHUE6DegJ6g4gQVJ6jCyAJl69RKHCBHiCwWxjCkgqqE54/4I67+P70BISe2H3awnRABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIDEfE5FQVXFRZ5TmoZuaEDzuSRBjVEUlCShm+7T05NJmk7i/Aea2Wj6L8oydH/cKUubmfqJ2Sx0x+xKEidp+ondLnQPbRmP3WbqfKakn0ydQ75cz76/URQNzbjy3nETX1++a+z3aTik52ff9bbl6H+fSkS2BLu/D5apOo51fRput0rF3t5ICLq5Ub2tevnra3p5Ub1tSKuV/C9/sr/b7SyXPxlc3aWbqRrzjNMtX8dq5bqjrak8rRox64xGaRr/4JJ2YLPRu1a3/HGMx0REl7b76I/P06j12l9d2hRXDI1mM73yi4V5XZ0gPR1mZhZTPs/1yseRLMUOVBUJ8TsfmTHVWF5xTNUxmdBFqHTwOviXfHiI+QHvWZZhZOnAyNKAZGlAslTt90iWMiGQLGXM1jKwUCtp5sSi13Nbtbn1Okyy8jzC7c5g8G+jFwuH9Ua5N6QQ7Wa2isulq0rtYA4eGg8P2ot1WBFRr8e13vrJnxAxJ4tkBzUW8R/FDQY263KFecxbzJf0FCwa0vdULUk/tOzu8qoR35mqoiwzvDP/nKoqen212REf7u7k+To+LFYR/UsKhspL9jr470KThFujSzPV0ZPSv8qS+n29S97fDz+kKQ2Hetfe3tLHh94l3eLtQ63RKHRXrVB8n4hMHah8h2QcZ0i6WDWI+FYJWpZLa5mKbOVprOWsjGPfZ9dopPfsNzufimadpW4yoSyjLKPp9PCb/Z6EoM2GHh/p89P8zt8yNPuQkh59uwAAAABJRU5ErkJggg==">
</body>
</html>

gd_info

getimagesize

getimagesizefromstring

image_type_to_extension

image_type_to_mime_type

imageaffine

imageaffinematrixconcat

imageaffinematrixget

imagealphablending

imageantialias

imagearc

imageavif

imagebmp

imagechar

imagecharup

imagecolorallocate

imagecolorallocatealpha

imagecolorat

imagecolorclosest

imagecolorclosestalpha

imagecolorclosesthwb

imagecolordeallocate

imagecolorexact

imagecolorexactalpha

imagecolormatch

imagecolorresolve

imagecolorresolvealpha

imagecolorset

imagecolorsforindex

imagecolorstotal

imagecolortransparent

imageconvolution

imagecopy

imagecopymerge

imagecopymergegray

imagecopyresampled

imagecreate

imagecreatefromavif

imagecreatefrombmp

imagecreatefromgif

imagecreatefromjpeg

imagecreatefrompng

imagecreatefromstring

imagecreatefromtga

imagecreatefromwbmp

imagecreatefromwebp

imagecreatefromxbm

imagecreatefromxpm

imagecreatetruecolor

imagecrop

imagecropauto

imagedashedline

imagedestroy

imageellipse

imagefill

imagefilledarc

imagefilledellipse

imagefilledpolygon

imagefilledrectangle

imagefilltoborder

imagefilter

imageflip

imagefontheight

imagefontwidth

imageftbbox

imagefttext

imagegammacorrect

imagegetclip

imagegetinterpolation

imagegif

imageinterlace

imageistruecolor

imagejpeg

imagelayereffect

imageline

imageloadfont

imageopenpolygon

imagepalettecopy

imagepalettetotruecolor

imagepng

imagepolygon

imagerectangle

imageresolution

imagerotate

imagesavealpha

imagescale

imagesetbrush

imagesetclip

imagesetinterpolation

imagesetpixel

imagesetstyle

imagesetthickness

imagesettile

imagestring

imagestringup

imagesx

imagesy

imagetruecolortopalette

imagettfbbox

imagettftext

imagetypes

imagewbmp

imagewebp

imagexbm

iptcembed

iptcparse

HomeMenu