Issue
I am using the following code snippet in order to crop a image?
function crop($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $width, $height );
$this->image = $new_image;
}
Here, $this->image
is the original image $this->getWidth()
and $this->getHeight()
holds the original dimensions of the picture, where as $width
and $height
, is the crop area.
But for some reason, the crop image is resized(we can almost say it is resized).
How to fix this?
Solution
Well, the problem is giving the source dimensions. Giving the dimensions of entire image will re size instead of cropping.
This should solve the problem
function crop($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $width, $height );
$this->image = $new_image;
}
Answered By - Starx Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.