Reputation: 5941
If I have an image 2048 x 2048 and I would like an image 1488x1488 450 pixels down from top and 280 pixels from left
is this the right code x.png is the 2048 x 2048 picture:
<?php
$imagesrc_location = 'x.png';
// Get new sizes
list($srcwidth, $srcheight) = getimagesize($imagesrc_location);
$imagedst = imagecreatetruecolor(1488, 1488);
$imagesrc = imagecreatefrompng($imagesrc_location);
if (imagecopyresampled($imagedst,$imagesrc,0,0,280,450,1488,1488,2048,2048)) {
// Output image
header('Content-type: image/png');
imagepng($imagedst);
} else {
echo "Could not resize file";
}
Here is a picture showing what I want, the grey part is the cropped picture.
Upvotes: 0
Views: 2245
Reputation: 5567
EDIT: I think the problem is, your source size will make the imagecopyresampled
scale it down. This may work for a crop:
imagecopyresampled($imagedst,$imagesrc,0,0,280,450,1488,1488,1488,1488)
But look here: http://www.johnconde.net/blog/cropping-an-image-with-php-and-the-gd-library/ I think that what you want is:
imagecopy($imagedst,$imagesrc,0,0,280,450,1488,1488)
https://www.php.net/manual/en/function.imagecopy.php
https://www.php.net/manual/en/function.imagecopyresampled.php
Upvotes: 1