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 Imagick:转换ImageMagick命令行代码时出现问题_Php_Image Processing_Xampp_Imagemagick_Imagick - Fatal编程技术网

PHP Imagick:转换ImageMagick命令行代码时出现问题

PHP Imagick:转换ImageMagick命令行代码时出现问题,php,image-processing,xampp,imagemagick,imagick,Php,Image Processing,Xampp,Imagemagick,Imagick,我正在Windows 8.1上使用ImageMagick 7.0.8-66 Q16 x64 我的PHP在XAMPP上是7.4.1 我已经在PHP中使用exec()成功运行了以下命令: 它拍摄图像,调整大小以适应100x100的缩略图,并在中性背景画布上为图像添加阴影。它起作用了 我想重写它以使用Imagick PHP扩展,但在翻译它时遇到了困难。以下是我如何翻译它(带有注释),但它不起作用: // convert _temp_.jpg $im = new imagick(); $im->

我正在Windows 8.1上使用ImageMagick 7.0.8-66 Q16 x64 我的PHP在XAMPP上是7.4.1

我已经在PHP中使用exec()成功运行了以下命令:

它拍摄图像,调整大小以适应100x100的缩略图,并在中性背景画布上为图像添加阴影。它起作用了

我想重写它以使用Imagick PHP扩展,但在翻译它时遇到了困难。以下是我如何翻译它(带有注释),但它不起作用:

// convert _temp_.jpg 
$im = new imagick();
$im->readImage('_temp_.jpg');

// ( +clone -background black -shadow 88x3+2+2 ) 
$im_clone = clone $im;
$im_clone->setImageBackgroundColor('black');
$im_clone->shadowImage(88, 3, 2, 2);

// +swap -background none -layers merge 
$im->setImageBackgroundColor('none');
$im->addImage($im_clone);
$im->mergeImageLayers(imagick::LAYERMETHOD_MERGE);

// +repage -background #eeeeee -layers flatten 
$im->cropImage(88, 88, +5, +5);
$im->setImagePage(88, 88, 0, 0);
$im->setImageBackgroundColor('#eeeeee');
$im->mergeImageLayers(imagick::LAYERMETHOD_FLATTEN);

// +repage -shave 3x3 
$im->cropImage(88, 88, +5, +5);
$im->setImagePage(88, 88, 0, 0);
$im->shaveImage(3, 3);

// ( -size 100x100 xc:#eeeeee )
$im_pseudo = new Imagick();
$im_pseudo->newPseudoImage(100, 100, 'xc:#eeeeee');

// +swap -gravity northwest -geometry +5+5 -compose over -composite output.jpg
$im->setImageGravity(imagick::GRAVITY_NORTHWEST);
$im->compositeImage($im_pseudo, Imagick::COMPOSITE_OVER, 5, 5);

$im->writeImage('output.jpg');
我错过了什么

源图像:


结果图像:

正如我所说的,如果你循序渐进,你可以看到发生了什么。这来自php Imagick手册,创建了阴影:

/* Read the image into the object */ 
$im = new Imagick( 'DOqeZ.jpg' ); 
$im->setImageFormat("png"); 

/* Make the image a little smaller, maintain aspect ratio */ 
$im->thumbnailImage( 200, null ); 

/* Clone the current object */ 
$shadow = $im->clone(); 

/* Set image background color to black 
        (this is the color of the shadow) */ 
$shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 

/* Create the shadow */ 
$shadow->shadowImage( 80, 3, 5, 5 ); 

/* Imagick::shadowImage only creates the shadow. 
        That is why the original image is composited over it */ 
$shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 ); 

/* Display the image */ 
$shadow->writeImage('shadow.png');

更新: 我想我会让你看看你是否能做剩下的事

创建背景和合成背景应该可以,但范围应该更好。我还有其他事情要处理,但下面有一些更新的代码供您使用:

/* Read the image into the object */ 
$im = new Imagick( 'DOqeZ.jpg' ); 
$im->setImageFormat("png"); 

/* Make the image a little smaller, maintain aspect ratio */ 
$im->thumbnailImage( 80, null ); 

/* Clone the current object */ 
$shadow = $im->clone(); 

/* Set image background color to black 
        (this is the color of the shadow) */ 
$shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 

/* Create the shadow */ 
$shadow->shadowImage( 80, 3, 5, 5 ); 

/* Imagick::shadowImage only creates the shadow. 
        That is why the original image is composited over it */ 
$shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 ); 

/* Create the background image 100x100 with a background colour */
/* Gravity seems to have no effect  */
/* $shadow->setImageGravity(imagick::GRAVITY_CENTER);*/
$shadow->setImageBackgroundColor( '#eeeeee' );
$height = $shadow->getImageHeight();
$width =  $shadow->getImageWidth();
$shadow->extentImage( 100, 100, (((100 - $width)/2)*-1 ), (((100 - $height)/2)*-1 ));    

$shadow->writeImage('shadow.jpg');

****更新代码以使图像居中,并使用十六进制值作为颜色****

正如我所说,如果你循序渐进,你可以看到发生了什么。这来自php Imagick手册,创建了阴影:

/* Read the image into the object */ 
$im = new Imagick( 'DOqeZ.jpg' ); 
$im->setImageFormat("png"); 

/* Make the image a little smaller, maintain aspect ratio */ 
$im->thumbnailImage( 200, null ); 

/* Clone the current object */ 
$shadow = $im->clone(); 

/* Set image background color to black 
        (this is the color of the shadow) */ 
$shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 

/* Create the shadow */ 
$shadow->shadowImage( 80, 3, 5, 5 ); 

/* Imagick::shadowImage only creates the shadow. 
        That is why the original image is composited over it */ 
$shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 ); 

/* Display the image */ 
$shadow->writeImage('shadow.png');

更新: 我想我会让你看看你是否能做剩下的事

创建背景和合成背景应该可以,但范围应该更好。我还有其他事情要处理,但下面有一些更新的代码供您使用:

/* Read the image into the object */ 
$im = new Imagick( 'DOqeZ.jpg' ); 
$im->setImageFormat("png"); 

/* Make the image a little smaller, maintain aspect ratio */ 
$im->thumbnailImage( 80, null ); 

/* Clone the current object */ 
$shadow = $im->clone(); 

/* Set image background color to black 
        (this is the color of the shadow) */ 
$shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 

/* Create the shadow */ 
$shadow->shadowImage( 80, 3, 5, 5 ); 

/* Imagick::shadowImage only creates the shadow. 
        That is why the original image is composited over it */ 
$shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 ); 

/* Create the background image 100x100 with a background colour */
/* Gravity seems to have no effect  */
/* $shadow->setImageGravity(imagick::GRAVITY_CENTER);*/
$shadow->setImageBackgroundColor( '#eeeeee' );
$height = $shadow->getImageHeight();
$width =  $shadow->getImageWidth();
$shadow->extentImage( 100, 100, (((100 - $width)/2)*-1 ), (((100 - $height)/2)*-1 ));    

$shadow->writeImage('shadow.jpg');

****更新代码以使图像居中,并使用十六进制值作为颜色****

什么不起作用?我会完成每一步,并在进入下一步之前让它工作。我会尝试将“”改为“”我已经这样做了。当我只处理“convert temp.jpg(+clone-background black-shadow 88x3+2+2)+swap-background none-layers merge”对应的部分时,结果不一样。此外,使用单引号和双引号没有区别。您应该将输入图像和预期的输出图像以及您所做的结果附加在一起。看上面。也许你可以加上它的外观。什么不起作用?我会完成每一步,并在进入下一步之前让它工作。我会尝试将“”改为“”我已经这样做了。当我只处理“convert temp.jpg(+clone-background black-shadow 88x3+2+2)+swap-background none-layers merge”对应的部分时,结果不一样。此外,使用单引号和双引号没有区别。您应该将输入图像和预期的输出图像以及您所做的结果附加在一起。请参见上文。也许您可以添加它的外观。我不知道您是否理解所需的结果是,输入图像的大小调整为保留纵横比,但仍适合100x100灰色背景(顶部)。你在上面创造的是可爱的,除了它只是一个带有阴影的图像。我的例程的目标(以及它在命令行版本中得到的正确结果)是保留原始的高宽比大小调整,带有浮动在中性灰色背景之上的阴影,因此我的命令行过程中的所有步骤……以及“浮动在中性灰色背景之上”我的意思是背景是合成图片的一部分。保存我上面提供的第二幅图像,您就会看到。我无法判断您是否理解所需的结果是,输入图像的大小调整为保留纵横比,但仍适合100x100灰色背景(在其上)。你在上面创造的是可爱的,除了它只是一个带有阴影的图像。我的例程的目标(以及它在命令行版本中得到的正确结果)是保留原始的高宽比大小调整,带有浮动在中性灰色背景之上的阴影,因此我的命令行过程中的所有步骤……以及“浮动在中性灰色背景之上”我的意思是背景是合成图片的一部分。保存上面我提供的第二张图片,您将看到。