简体   繁体   English

从Convert命令转换为ImageMagick的直接PHP

[英]Moving from convert command to straight PHP for ImageMagick

I am moving to a new hosting company that will not allow me to exec a convert command for ImageMagick. 我要搬到一家新的托管公司,该公司不允许我执行ImageMagick的convert命令。 So I now have to attempt to do it through straight PHP. 因此,我现在不得不尝试通过直接的PHP来实现。 I have spent quite a bit of time trying to figure it out and every where that I look, people recommend using the convert command like I am. 我花了很多时间试图弄清楚它的位置以及所见之处,人们建议像我一样使用convert命令。 I would appreciate any help or guidance in writing the following commands in straight PHP. 在直接用PHP编写以下命令时,我将不胜感激。

# Applies overlay $filter_image to the original $image
convert $image ( -clone 0 -alpha off $filter_image -compose SoftLight -composite ) -compose SrcIn -composite $output_image

and

# Apply a blur to an image
convert $image -blur 0x$blur_radius $output_image

UPDATE : 更新

I have figured out the syntax and posted it as an answer. 我已经弄清楚了语法并将其发布为答案。

Best of luck Joe; 祝你好运乔; I would recomend changing to a host that will let you use exec. 我建议将主机更改为允许您使用exec的主机。

I have some examples of the imagick functions on my site that you may be able to cobble something together with: http://www.rubblewebs.co.uk/imagick/functions/function.php 我的网站上有一些imagick函数的示例,您也许可以将它们拼凑在一起: http ://www.rubblewebs.co.uk/imagick/functions/function.php

I have just noticed I posted the Imagemagick code not the Imagick ! 我刚刚注意到我发布了Imagemagick代码而不是Imagick! This is as you now know the blur code for Imagick: 这就是您现在知道的Imagick的模糊代码:

bool blurImage ( float $radius , float $sigma [, int $channel ] ) bool blurImage(float $ radius,float $ sigma [,int $ channel])

<?php  
$im = new Imagick($input); 
$im->blurImage( 0, 3 ); 
$im->writeImage('blurImage.jpg');  
$im->destroy(); 
?> 

Might be worth adding an Imagick tag to your post as that is what you want to use? 可能值得在您的帖子中添加Imagick标签,因为这就是您要使用的标签?

I finally figured it out on my own. 我终于自己解决了。 Here is the solution in case anyone else runs into this. 这是万一其他人遇到的解决方案。

Blur an image... 模糊图像...

$imagick = new Imagick($image);
$imagick->blurImage(0,$blur_radius);
$imagick->writeImage($output_image);

Add an overlay to an image... 将叠加层添加到图像...

$imagick = new Imagick($image);
$overlay = new Imagick($filter_image);

$imagick->compositeImage($overlay, imagick::COMPOSITE_SOFTLIGHT, 0, 0);
$imagick->writeImage($output_image);

You can easily combine the two methods as well and blur the image and then add a composite overlay to it. 您也可以轻松地将这两种方法结合起来并模糊图像,然后向其添加合成覆盖。

$imagick = new Imagick($image);
$imagick->blurImage(0,$blur_radius);

$overlay = new Imagick($filter_image);
$imagick->compositeImage($overlay, imagick::COMPOSITE_SOFTLIGHT, 0, 0);

$imagick->writeImage($output_image);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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