PHP image_jpeg dont' work if file is UTF-8, works if it's ANSI

半腔热情 提交于 2019-12-24 08:21:05

问题


I use this class to crop, resize my image: http://www.phpclasses.org/package/4268-PHP-Resize-crop-rotate-flip-flop-and-grey-images.html

It uses GD. The problem is that I for example do this:

$img = new ImageTransform;
$img->view('resize', 'foo.jpg', '500x400', true); // true argument is $cache = true

Now I can just point

<img src="that_script.php" alt="" />
and it will show that image resized. But it doesn't if all my files are UTF-8! Only if they ALL are ANSI encoded. The image simply won't display if some or all files are encoded UTF-8. If i remove headers.. and just let it print all the things... I can see all funny characters... so it's printing something! But it just won't print the actual image with headers...

In the PHP documentation I found someone write this: http://no.php.net/manual/en/function.imagejpeg.php#96796

WARNING for those who use utf-8 scripts: Before going crazy like me for a whole day and digging around configuration files etc.

DIRECT BROWSER OUTPUT using image_jpeg worked only after i have saved my script in ANSI instead of utf-8

So it must be something wrong with PHP? I use PHP version: 5.3.2

Nobody at PHPClasses complains about something wrong, so I don't think it's the class. But something with PHP. The question is how can I make it work with UTF-8?

Thanks for help!


回答1:


Are you possibly saving the files as UTF8 BOM? That would likely screw up image output, since the BOM character is always output first. Try saving it as UTF8 No-BOM, that should be identical to ANSI files.



来源:https://stackoverflow.com/questions/3170000/php-image-jpeg-dont-work-if-file-is-utf-8-works-if-its-ansi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!