Created
December 19, 2012 10:30
-
-
Save jasdeepkhalsa/4335807 to your computer and use it in GitHub Desktop.
How to crop an image using PHP compiled with the GD library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example from http://php.net/manual/en/function.imagecopy.php | |
// Usage: | |
// bool imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h ) | |
// Copy a part of src_im onto dst_im starting at the x,y coordinates src_x, src_y with a width of src_w and a height of src_h. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y. | |
// Create image instances | |
$src = imagecreatefromgif('php.gif'); | |
$dest = imagecreatetruecolor(80, 40); | |
// Copy | |
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40); | |
// Output and free from memory | |
header('Content-Type: image/gif'); | |
imagegif($dest); | |
imagedestroy($dest); | |
imagedestroy($src); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment