Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用imagick扩展图像_Php_Imagick - Fatal编程技术网

Php 使用imagick扩展图像

Php 使用imagick扩展图像,php,imagick,Php,Imagick,我有一个尺寸为x和y的图像。 我想使用imagick将图像扩展到x和y+10。 这里有一个实现这一点的例子: 代码示例显示了如何水平扩展,而不是垂直扩展 当我使用该示例进行水平扩展时,它可以工作: function EdgeExtendHorizontal(&$img) { $originalWidth=$img->getImageWidth(); $desiredWidth=$originalWidth+120; $Factor=$originalWidth/$desiredW

我有一个尺寸为x和y的图像。 我想使用imagick将图像扩展到x和y+10。 这里有一个实现这一点的例子:

代码示例显示了如何水平扩展,而不是垂直扩展

当我使用该示例进行水平扩展时,它可以工作:

function EdgeExtendHorizontal(&$img)
{
$originalWidth=$img->getImageWidth();
$desiredWidth=$originalWidth+120;
$Factor=$originalWidth/$desiredWidth; 
$Offset=($desiredWidth-$originalWidth)/2;
$img->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_MIRROR);
$img->sampleimage($desiredWidth,$img->getImageHeight());
$points=array($Factor,0,0,1,$Offset,0);
$img->distortImage(Imagick::DISTORTION_AFFINEPROJECTION,$points,false);
}

但是,当我尝试切换参数以使图像垂直延伸时,它不起作用:

function EdgeExtendVertical(&$img)
{
global $LanguageName;
$originalHeight=$img->getImageHeight();
$desiredHeight=$originalHeight+100;
$Factor=$originalHeight/$desiredHeight; 
$Offset=($desiredHeight-$originalHeight)/2;
$img->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_MIRROR);
$img->sampleimage($img->getImageWidth(),$desiredHeight);
$points=array(0,$Factor,0,1,0,$Offset);
$img->distortImage(Imagick::DISTORTION_AFFINEPROJECTION,$points,false);
}

按以下方式修改点阵列会产生以下结果:

$points=array($Factor,0,0,1,0,$Offset);

但现在,图像被莫名其妙地垂直和水平延伸

如果有人能解释点阵列的结构,使图像仅垂直扩展,我将不胜感激

谢谢


Cymro是同时扩展宽度、高度或两者的最简单通用方法(PHP>=5.4):

对于PHP<5.4,将以$im->扭曲图像()开头的行替换为:


如果这不起作用,请告诉我!干杯,李

Prynhawn Da!我并没有和imagick玩太多,所以我不是一个大帮手,但主要是想评论一下,因为你是我在StackOverflow上看到的第一个威尔士人。无论如何,与第一个例子相比,这一行看起来很奇怪,在第一个例子中,参数是相反的<代码>$img->sampleimage($img->getImageWidth(),$desiredHeight)迪奥奇·亚历克斯。横向扩展:$img->sampleimage($desiredWidth,$img->getImageHeight());垂直扩展:$img->sampleimage($img->getImageWidth(),$desiredHeight);因此,您不仅要进行扩展,而且还希望在新的额外像素扩展中获得镜像效果?镜像只作为填充扩展空间的一种手段很重要。如上面的示例所示:phpimagick.com/Tutorial/edgeExtend。在最终版本中,镜像将不可见。我文章中的镜像只是为了说明我还不能让它正常工作的一点。
$im = new Imagick ("myfile.png");
$im->setImageVirtualPixelMethod (imagick::VIRTUALPIXELMETHOD_MIRROR);
list ($width, $height) = array_values ($im->getImageGeometry ());
$extend_width = 0;
$extend_height = 100;
$new_width = $width + $extend_width;
$new_height = $height + $extend_height;
$extend_width /= 2;
$extend_height /= 2;
$im->setImageArtifact ("distort:viewport", "{$new_width}x$new_height-$extend_width-$extend_height");
$im->distortImage (imagick::DISTORTION_SCALEROTATETRANSLATE, [0], false);
$im->writeImage (getcwd () . "/my_extended_image.png");
$im->distortImage (imagick::DISTORTION_SCALEROTATETRANSLATE, array (0), false);