Imagick 无法载入中文文件名<?php
$filepath = 'F:\\';
$filename="哈.tif";$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_filename);//$filename =  iconv('utf-8', 'gb2312', $filename);
$jpgfilename = substr($filename,0,strrpos($filename,'.')).'.jpg';
$im = new Imagick($filepath.$filename);
$im->thumbnailImage(1200, 0);$width = $im->getImageWidth() ;
$height = $im->getImageHeight();
$width800 = 1200;
$height800 = 1200*$height/$width;
$canvas = new Imagick();
$canvas->newImage($width, $height, '');
$canvas->setImageFormat("jpeg");
$canvas->compositeImage($im, imagick::COMPOSITE_OVER, 20, 10);
$canvas->writeImage($filepath.$jpgfilename);
?>
$im = new Imagick($filepath.$filename);
到这一步就会报错:
Uncaught exception 'ImagickException' with message 'unable to open image `F:\哈.tif': No such file or directory @ error/blob.c/OpenBlob/2638' in F:\workspace\test\1.php:12
Stack trace:
#0 F:\workspace\test\1.php(12): Imagick->__construct('F:\??.tif')
#1 {main}
  thrown

解决方案 »

  1.   

    也不能使用
    $file_read = iconv('utf-8', 'gb2312', $file_read);
    $file_read =iconv('utf-8', 'gb2312//IGNORE', $file_read);
    这样的方法
      

  2.   

    header("Content-type: text/html; charset=gb2312");
      

  3.   

    那大哥您就别用中文文件名成不看这个情况应该是这个包只支持utf-8的文件名,你在linux下跑估计就没什么问题了
      

  4.   

    参考一下这个吧
    http://s.yanghao.org/program/viewdetail.php?i=91439
      

  5.   

    关于中文或其他多字节文件名的问题(仅限windows)
    这是php的死症——php不能读取windows里面的unicode文件名,但其他系统可以
    因为其他系统的unicode文件名多为utf-8编码,windows是特殊的混合编码但php可以读取符合本地系统codepage的文件名,例如简体windows读取汉字(常用,限gb2312/GBK以内,如果有unicode extent汉字因为超出936的codepage也不属此列)的文件名没有问题,但为何web的php不行,因为apache……再次无解所以php处理多字节windows符合本地codepage文件名只能绝对路径方式,处理unicode文件名只能用取巧的方式(短路径)+com,其他函数基本无力