php读取中文图片文件读不了,编码有关问题

WBOY
Release: 2016-06-13 13:28:58
Original
1108 people have browsed it

php读取中文图片文件读不了,编码问题

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php $image='小图.jpg';
$percent=0.05;
$im=getimagesize($image);
$width=$im[0];
$hight=$im[1];
switch ($im[2]) {
    case 1:
        $im=@imagecreatefromgif($image);
        break;
    case 2:
        $im=@imagecreatefromjpeg($image);
        break;
    case 3:
        $im=@imagecreatefrompng($image);
        break;
}

$logo='1.jpg';
$im1=getimagesize($logo);
//print_r($im1);
switch ($im1[2]) {
    case 1:
        $im1=@imagecreatefromgif($logo);
        break;
    case 2:
        $im1=@imagecreatefromjpeg($logo);
        break;
    case 3:
        $im1=@imagecreatefrompng($logo);
        break;
}
imagecopy($im,    $im1,   700,-100,0,0,'440','771');
//       底下图     上面图        
$te=imagecolorallocate($im,255,255,255);

imagettftext($im,12,0,20,20,$te,'../simhei.ttf','新年快乐');
$newwidth=$width*$percent;
$newheight=$hight*$percent;
$new=imagecreatetruecolor($newwidth,$newheight);
imagecopyresized($new,$im,0,0,0,0,$newwidth,$newheight,$width,$hight);

header("Content-type: image/jpeg");
imagejpeg($new);//编译图片
//if(imagejpeg($im,'new.jpg')){
//    echo "水印成功";
//}
//imagejpeg($new,'小图.jpg');
//imagejpeg($im,'大图.jpg');
?>
Copy after login


创建中文名的图片结果是乱码。。php是utf-8的,

------解决方案--------------------
还是推荐用不要用中文命名。
------解决方案--------------------
推荐你使用iconv函数转换文件名称编码为gbk试试
------解决方案--------------------
php本身是不支持中文的,要转一下。
具体步骤如下:
$image=iconv("UTF-8", "gb2312", $image);
第一个参数是输入的字符编码,第二个是你想要转的字符编码,第三个是被转换的字符串。
------解决方案--------------------
将该php文件另存为。注意保存的编码
------解决方案--------------------
最好的办法就是别用中文
------解决方案--------------------
在window上最好都使用utf-8, 并且显性地声明,不管是不是静态页面,不要用中文名
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template