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

将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)

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大