duangong0690 2014-02-22 21:25
浏览 476
已采纳

将TIFF转换为PNG

Trying to convert a TIFF in PHP. We have ImageMagick installed on our server but we do not have the Imagick PECL extension (and we're on shared hosting on GoDaddy so I don't think it's possible to install).

I'm trying to find a workaround but no luck yet. Here's what I have so far (note that the TIFFs come to us in the form of a base64 string):

$tiff = base64_decode((string)$docsData);
try {
$cmd = "$tiff converted.png"; 
exec("/usr/local/bin/convert $cmd");
}
catch(Exception $e) {
die('Error when creating a file: ' . $e->getMessage());
}
  • 写回答

1条回答 默认 最新

  • dpnru86024 2014-02-22 21:28
    关注

    You can't just dump the raw binary "garbage" of a tiff as an argument on the command line. You're essentially trying to do

    /usr/local/bin/convert $@#Wrkjd;fgldhjesr;3qjw;aesrfkj   ....   converted.png
    

    Dump that "garbage" to a file, then use that file:

    $tempname = tempnam();
    file_put_contents($tempname, base64_decode($docsData);
    exec("/usr/loca/bin/convert $tempname converted.png");
    unlink($tempname);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭