Imagick 沒法載入中文檔案名稱

來源:互聯網
上載者:User
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,其他函數基本無力
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.