简体   繁体   中英

imagecopyresampled Cropping

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.

在此处输入图片说明

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)

http://us3.php.net/manual/en/function.imagecopy.php

http://us3.php.net/manual/en/function.imagecopyresampled.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM