function LoadJpeg($w,$h,$filestring)
{
/* Attempt to open */
try{
$im = imagecreatefrompng($filestring) ;//or die("加载失败");
}
catch(Exception  $e){
/* Create a black image */
$im  = imagecreatetruecolor($w, $h); ////Returns an image resource identifier on success, FALSE on errors. 
$bgc = imagecolorallocate($im, 1, 145, 205);
$tc  = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, $w, $h, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $filestring, $tc);
}
/* See if it failed */
//if(!$im)
// {
// /* Create a black image */
// $im  = imagecreatetruecolor($w, $h); ////Returns an image resource identifier on success, FALSE on errors. 
// $bgc = imagecolorallocate($im, 1, 145, 205);
// $tc  = imagecolorallocate($im, 0, 0, 0);
// imagefilledrectangle($im, 0, 0, $w, $h, $bgc);
// /* Output an error message */
// imagestring($im, 1, 5, 5, 'Error loading ' . $filestring, $tc);
// }
return $im;
}  1.这个函数imagecreatefrompng()用于加载png类型的图片,同时也存在加载jpeg类型的这个同类型函数
但是唯独没有找到加载dwg格式的图片。我尝试过使用这些函数加载dwg格式的图片,但是失败了。我现在唯一想到的办法,就是通过文件流把dwg格式的图片转换成通俗的格式。请问大家,还有别的办法没有?
  
  2.大家有没有注意到try..catch. 因为当指定的文件不存在时,是会抛出异常的。这里希望捕获这个异常的同时,创建一个提示性的图片。但是上面的那段代码没有执行成功...待解救.....有思路也行,我自己尝试,附上代码最好不过了...PHP图片异常IM

解决方案 »

  1.   

    .dwg严格说不是图片。MIMIE类型为 application/x-dwg
      

  2.   

    你是说 AutoCAD的图形文件 ?php 的 GD 只能处理 网页图片
      

  3.   

    是的,或者我想把数据库中二进制存储的图片转换成dwg,当然,他们存进去的时候就是dwg,怎么弄,我读取出来的是jpg格式
      

  4.   

    或者文件读写也可以,但是我确实找不到指定的格式,
    就比如我用C#,对应的图片格式:ImageFormat:没有dwg?求指引