我试图找到一个PHP图像库脚本,允许我从大图像中选择特定区域(x, y),然后裁剪/调整大小到较小的图像。
它不能扭曲图像(通过拉伸和扭曲图片来调整大小)。如果有必要,它可能需要"放大"(或其他什么?)来克服这个问题。
哪个PHP图像库脚本可以做到这一点?
WideImage
这里是作物演示。
。
WideImage::load('a.png')->crop(50, 50, 30, 20)->saveToFile('b.jpg');
GD (http://php.net/manual/en/book.image.php)或ImageMagick (http://php.net/manual/en/book.imagick.php)都可以进行裁剪操作。
在前端,Jcrop (http://code.google.com/p/jcrop/)是一个很好的jQuery插件,如果你想通过一个页面做到这一点。
您可以使用GD来实现这一点。我猜可以这样做:
/**
*@param string $pathToImage The original image (jpg)
*@param string $outputImage The name of the output image (jpg)
*@param int $x The top x coordinate of the portion you want to grab
*@param int $y The top y coordinate of the portion you want to grab
*@param int $width the width of the portion you want to grab
*@param int $height the height of the portion you want to grab
*@return void
*/
function getImagePortion($pathToImage, $outputImage, $x, $y, $width, $height)
{
$im = imagecreatefromjpeg($pathToImage);
$portion = imagecreatetruecolor($width, $height);
imagecopyresampled($portion, $im, 0, 0, $x, $y, $width, $height, imagesx($im), imagesy($im));
imagejpeg($portion, $outputImage, 100);
}
我碰巧喜欢这门课http://www.verot.net/php_class_upload.htm
我知道它说的是上传,但你也可以处理本地文件,如果它们是图像,它会给你很多很酷的功能。你可以在http://www.verot.net/php_class_upload_samples.htm
找到它们GL