2011-04-27 36 views
1

我有一个PHP脚本,将收到一堆上传的图像。imagemagick - 缩小尺寸/裁剪/一次保存为jpeg?

我需要做的是创造每一个细小的缩略图,在使用ImageMagick的飞行。

我能做到这一点很容易,但我还需要裁剪,使缩略图始终是100×100。

供应将不会是相同的比例图像于是干脆裁员将无法正常工作。

我能缩小,作物为100x100并保存到jpeg只需一个步骤?

回答

2

我相信这应该做你想要什么:

convert 'just_uploaded/*' -resize 100x100^ -gravity center -extent 100x100 -set filename:f '%t' +adjoin 'just_uploaded_thumbs/%[filename:f].jpg' 

resize将缩小规模,extent(结合gravity)将裁剪,其余部分负责使用JPEG格式的修改名称在另一个目录中进行保存。

+0

工程请客感谢。 – gio 2011-04-27 02:02:05

0

我喜欢sfThumbnailPlugin。它包装了ImageMagick的或GD

各地

http://www.symfony-project.org/plugins/sfThumbnailPlugin

例子:

public function executeUpload() 
{ 
    // Retrieve the name of the uploaded file 
    $fileName = $this->getRequest()->getFileName('file'); 

    // Create the thumbnail 
    $thumbnail = new sfThumbnail(150, 150); 
    $thumbnail->loadFile($this->getRequest()->getFilePath('file')); 
    $thumbnail->save(sfConfig::get('sf_upload_dir').'/thumbnail/'.$fileName, 'image/png'); 

    // Move the uploaded file to the 'uploads' directory 
    $this->getRequest()->moveFile('file', sfConfig::get('sf_upload_dir').'/'.$fileName); 

    // Do whatever is next 
    $this->redirect('media/show?filename='.$fileName); 
} 
1

简短的回答:没有。这将是3步,不会少于3步。

较长的答案:您可以使用命令行界面。在PHP中,唯一的方法是编写一个能够完成你所要求的功能。然后,对于每个图像,您可以调用您的函数。我不知道这是怎么比只使用3 Imagick功能分开更有利于...