Imagick cannot load Chinese file name
Imagick cannot load Chinese file name
$filepath = ' f:\\ ';
$filename = "Kazakhstan 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 ();
$width 800 = 1200;
$height = 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);
You will get an error at this step:
Uncaught exception ' imagickexception ' with message ' Unable to open image ' F:\. tif ': No such file or directory @ Error/blo b.c/openblob/2638 ' in F:\workspace\test\1.php:12
Stack Trace:
#0 F:\workspace\test\1.php: Imagick->__construct (' F:\??. TIF ')
#1 {main}
Thrown
------Solution--------------------
The Big Brother you do not use the Chinese file name
Look at this situation should be this package only support Utf-8 file name, you run in Linux under the estimate there is no problem
------Solution--------------------
Please refer to this.
http://s.yanghao.org/program/viewdetail.php?i=91439
------Solution--------------------
Questions about Chinese or other multibyte file names (Windows only)
This is php certain--php cannot read the Unicode file name inside windows, but other systems can
Because the Unicode filenames of other systems are mostly UTF-8 encoded, Windows is a special hybrid encoding
However, PHP can read the file name that conforms to the local system codepage, such as simplified Windows read kanji (commonly used, limited to GB2312/GBK, if there is Unicode extent kanji because more than 936 of codepage is not this column) file name is not a problem, But why the web PHP does not, because Apache ... Again no solution
So PHP processing multi-byte windows conforms to the local codepage file name can only be absolute path, processing Unicode file name can only be used trickery (short path) +com, other functions basically weak