Imagick can't load Chinese file name

Source: Internet
Author: User
Tags stack trace
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.