简体   繁体   English

将ImageMagick命令转换为等效的PHP

[英]Convert ImageMagick Command To PHP equivalent

I wish to use the following ImageMagick SSH command in PHP: 我希望在PHP中使用以下ImageMagick SSH命令:

convert image_name.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB image_name.jpg

So the php ImageMagick version using: 因此,PHP ImageMagick版本使用:

$image = new Imagick('test.jpg');
$image->Functionhere()

您可以通过用反引号将bash命令包装起来来调用它,也可以使用php的exec

`convert image_name.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB image_name.jpg`

I suppose the first thing is to check if you have access to imagick: 我想第一件事是检查您是否可以使用imagick:

$version = Imagick::getVersion(); 
echo 'API version number: '.$version['versionNumber'].'<br />'; 
echo 'API version string: '.$version['versionString'].'<br />'; 

I do not like Imagick as there is not the support for it. 我不喜欢Imagick,因为没有对此的支持。 It does not support all the options of Imagemagick. 它不支持Imagemagick的所有选项。 It is a class and I have never had the need to learn how to use a class and so it is more complicated than exec( ). 这是一类,我从来不需要学习如何使用一类,因此它比exec()更复杂。

One thing a lot of people say is Imagick is more secure than Imagemagick; 很多人说的一件事是,Imagick比Imagemagick更安全。 but as long as you take precautions with user data I would have thought exec( ) was nearly as secure. 但是只要您对用户数据采取预防措施,我就认为exec()几乎是安全的。

exec( "convert image_name.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB image_name.jpg" );

The correct answer was: 正确答案是:

$im = new Imagick( $old_file );
$im->setImageCompression( Imagick::COMPRESSION_JPEG );
$im->stripImage();
$im->setSamplingFactors(array('2x2', '1x1', '1x1'));
$im->setCompressionQuality('85');

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

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