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

将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 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊