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


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!


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »