doulanyan6455
2014-07-19 11:32
浏览 240
已采纳

将tiff(带路径)转换为png并删除背景(透明) - 使用PHP中的Imagemagick

So, i have a lot of tiff files and I want to generate thumbnails of them. This thumbnails must have a transparent background.

All tiffs have: a white background and a path along the object (e.g. a can of a coke) and are saved as CMYK.

So i tried a lot of convert commands (like these and also php Imagick::clipPath but nothing worked very well (background still there/corrupt image).

convert a.tif -clip -resize 800x600 a.png
convert a.tif -clip -alpha transparent +clip -channel A -resize 800x600 a.png

also this php code:

<?php
$image = new Imagick('a.tif');
$image->clipPath();    
$image->setImageFormat('png');    
$image->thumbnailImage(800, 600, true);
$image->writeImage('a.png');

here is an example tif file

Maybe somebody knows how to solve this.

EDIT:

The best result returns this: convert test.tif -clip -alpha transparent 1.png

But it saves the background and not the clipped object. (png)

图片转代码服务由CSDN问答提供 功能建议

所以,我有很多tiff文件,我想生成它们的缩略图。 此缩略图必须具有透明背景。

所有tiff都有:白色背景和沿着对象的路径(例如一罐可乐)并保存为 CMYK。

所以我尝试了很多 convert 命令(比如这些以及php Imagick :: clipPath 但没有任何效果很好(背景仍然存在/损坏图像)。

 转换a.tif -clip -resize 800x600 a.png 
convert a.tif -clip -alpha transparent + clip -channel A -resize 800x600 a.png 
  <  / pre> 
 
 

这个php代码:

 &lt;?php 
 $ image = new Imagick('a.tif'); 
  $ image-&gt; clipPath(); 
 $ image-&gt; setImageFormat('png'); 
 $ image-&gt; thumbnailImage(800,600,true); 
 $ image-&gt; writeImage('a  .png'); 
   
 
 

此处 是一个示例tif文件

也许有人知道如何解决这个问题。

编辑:

最佳结果将返回: convert test.tif -clip -alpha transparent 1.png

但它会保存背景而不是剪切的对象。 ( png

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanquannan0593 2014-07-20 16:38
    已采纳

    Found it after trying it for hours.

    convert can.tif -alpha transparent -clip -alpha opaque result.png

    So it must be executed with e.g. shell_exec - I didn't found any possible solution to do it with the Imagick-PHP class.

    The problem was an old imagemagick version and also the wrong order of command attributes.

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题