imagecrop
Description
Syntax
imagecrop( GdImage $image, array $rectangle ): GdImage|false
Parameters
image
A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
rectangle
The cropping rectangle as array with keys x, y, width and height.
Return
Return cropped image object on success or false on failure.
Examples
1 · return
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $rectangle = array( 'x' => 0, 'y' => 0, 'width' => 50, 'height' => 50 ); $return = imagecrop($image, $rectangle); var_dump($return);
object(GdImage)#2 (0) { }
2 · base64
<? $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/png/Happy.png'; $image = imagecreatefrompng($filename); $rectangle = array( 'x' => 0, 'y' => 0, 'width' => 50, 'height' => 50 ); $image = imagecrop($image, $rectangle); ob_start(); imagepng($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,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABBElEQVRYhe3Y2wrDIBAE0Enp//+yfVgQafCyOnspzTw2IofRpIlXKQUxuQbX3m4KAGNKGx/WqqbGlKXW1Bix9kESOusUJCGyOCDJizQP0wRGW2SQ5LAtExPOWFYm7C6iIUiy0Za5CXqWhwlKlpMJGpafCcssVxPWWN4m8P58yJmyAqrCjBVjwpAVZsLP7a3IqtBhBZuQdhHvLzb0qtqv9hSfr/djBPlljvtaRGJVg6ONMrwKmO2t0+OWlsWqatE0Gpb0TqSzVMvXHVxZ8Y/QNv+yiJwIi7iCqqm6g1O3xc1iYaNhSdu6LI/le1PP63Q4aU73YiPZuc2T7q2HpcnD0uRhafIBK4YSj+JL/n4AAAAASUVORK5CYII="> </body> </html>
Links
Related
Image
- 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
- imagecopyresized
- imagecreate
- imagecreatefromavif
- imagecreatefrombmp
- imagecreatefromgif
- imagecreatefromjpeg
- imagecreatefrompng
- imagecreatefromstring
- imagecreatefromtga
- imagecreatefromwbmp
- imagecreatefromwebp
- imagecreatefromxbm
- imagecreatefromxpm
- imagecreatetruecolor
- 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