Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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 ImageMagick扩展中的图像周围添加白色框_Php_Image Processing_Imagemagick - Fatal编程技术网

在PHP ImageMagick扩展中的图像周围添加白色框

在PHP ImageMagick扩展中的图像周围添加白色框,php,image-processing,imagemagick,Php,Image Processing,Imagemagick,多年来,我一直在使用exec在PHP上进行ImageMagick工作。但是,我现在转到了PHP ImageMagic扩展。但是,我无法在其中复制我的命令 我想拍摄一张图像,调整其大小,并在其周围添加额外的空白,使其符合这些尺寸 我最初的imagemagic执行代码是: exec("convert -define jpeg:size=100x100 test.jpg -thumbnail '480x360>' -background white -gravity center -extent

多年来,我一直在使用exec在PHP上进行ImageMagick工作。但是,我现在转到了PHP ImageMagic扩展。但是,我无法在其中复制我的命令

我想拍摄一张图像,调整其大小,并在其周围添加额外的空白,使其符合这些尺寸

我最初的imagemagic执行代码是:

exec("convert -define jpeg:size=100x100 test.jpg -thumbnail '480x360>' -background white -gravity center -extent  480x360  output.jpg");
这非常有效,但我现在想在ImageMagick PHP扩展中复制它。我试过下面的方法,但不起作用

$im = new Imagick('input.jpg');
$im->setImageFormat('jpeg');
$im->setGravity('Imagick::GRAVITY_CENTER');
$im->setImageBackgroundColor('white');
$im->extentImage( 480, 360);

$im->writeImage('output.jpg');

我希望输出是一个适合480x360的框并在其周围添加空白的图像。图像将100%可见,区域周围有空白。因此,如果我上传了一张100x300的图像,它将是一个白色框中的信箱。

在使用API时,
扩展图像要求您计算页面(x,y)偏移量

Imagick::extentImage(int$width,int$height,int$x,int$y):bool
在这里设置重力没有效果,应该会发出PHP警告(检查日志)

试试下面的

$im = new Imagick('rose:');
$im->setImageBackgroundColor('GREEN');
$offsetX = 240 - $im->getImageWidth() / 2;
$offsetY = 180 - $im->getImageHeight() / 2;
$im->extentImage( 480, 360, -$offsetX, -$offsetY);
$im->writeImage('output.jpg');

使用API时,
extentImage
要求您计算页面(x,y)偏移量

Imagick::extentImage(int$width,int$height,int$x,int$y):bool
在这里设置重力没有效果,应该会发出PHP警告(检查日志)

试试下面的

$im = new Imagick('rose:');
$im->setImageBackgroundColor('GREEN');
$offsetX = 240 - $im->getImageWidth() / 2;
$offsetY = 180 - $im->getImageHeight() / 2;
$im->extentImage( 480, 360, -$offsetX, -$offsetY);
$im->writeImage('output.jpg');