简体   繁体   English

图像魔术创建缩略图

[英]Image Magick create thumbnail

Hi i am creating a thumbnail using imagemagick by following command 嗨,我通过以下命令使用imagemagick创建缩略图

 convert -define jpeg:size=".$this->info[0]."x".$this->info[1]."  testi/".$this->filename."  -auto-orient  -thumbnail 200x200   -unsharp 0x.5 testi/".$this->filename

but this command only runs for jpack input file. 但是此命令仅对jpack输入文件运行。

Can anyone tell me the command for any file type? 谁能告诉我任何文件类型的命令? like if gif then output shuld gif ? 像如果gif则输出应为gif吗?

Here is code: 这是代码:

<?php 
// read page 1 
$im = new imagick( 'test.pdf' );

// convert to jpg 
$im->setImageColorspace(255); 
$im->setCompression(Imagick::COMPRESSION_JPEG); 
$im->setCompressionQuality(60); 
$im->setImageFormat('jpeg'); 

//resize 
$im->resizeImage(290, 375, imagick::FILTER_LANCZOS, 1);  

//write image on server 
$im->writeImage('thumb1.jpg'); 
$im->clear(); 
$im->destroy(); 
?>

What is a jpack file? 什么是jpack文件?

The -define will only work for jpg files but I thought if the output file was not a jpg it would be ignored; -define仅适用于jpg文件,但我认为如果输出文件不是jpg,它将被忽略; try removing that. 尝试删除它。

The output file should be the same name as the input file. 输出文件应与输入文件同名。

Try writing your code like this so you can see what the command actualy is; 尝试像这样编写代码,以便可以看到实际的命令。 you can comment the echo out when its working. 您可以在回声工作时将其注释掉。

$cmd = "-define jpeg:size={$this->info[0]}x{$this->info[1]}  testi/{$this->filename}  -auto-orient -thumbnail 200x200 -unsharp 0x.5 testi/{$this->filename}"; 
echo $cmd;
exec("convert $cmd");

I got a bit lost with the "$this->" business and so the code may not work as written. 我对“ $ this->”业务有些迷惑,因此代码可能无法按编写的方式工作。 I try and keep things simple in my commands and would have put the filenames etc. into a variable outside the Imagemagick command. 我尝试使命令中的内容保持简单,并将文件名等放入Imagemagick命令外部的变量中。

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

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