Imagick 無法載入中文檔案名稱
Imagick 無法載入中文檔案名稱
$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
------解決方案--------------------
那大哥您就別用中文檔案名稱成不
看這個情況應該是這個包只支援utf-8的檔案名稱,你在linux下跑估計就沒什麼問題了
------解決方案--------------------
參考一下這個吧
http://s.yanghao.org/program/viewdetail.php?i=91439
------解決方案--------------------
關於中文或其他多位元組檔案名稱的問題(僅限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,其他函數基本無力