0

I have a code that dinamically resizes an image and sends it to the browser.

But it doesn't work properly... only if I ask it to output the image to a file instead of the browser.

I don't think the problem is my code, because this problem only occurs on the real server; in my computer its working perfectly.

Code:

$img = $_GET['img'];

ini_set('allow_url_fopen', 'on');

$info = getimagesize($img);
header('Content-type: '.image_type_to_mime_type($info[2]));
Fotos::redimensiona($img, null, Fotos::MINIGAL_WIDTH, Fotos::MINIGAL_HEIGHT, false);

Fotos::redimensiona():

//[...] a whole bunch of code calculating dimensions, they just works
// $funcImage is like 'imagejpeg'/'imagepng'/'imagegif', depends on file
if ($arquivo) {
    $funcImage($thumb, "$final.$ext");
    return "$final.$ext";
}
else {
    $funcImage($thumb);
}

Remember: it works on local development, but doesn't on remote web server.

[EDIT]
if I comment the header line, the binary code is printed; and this code changes when i change the original image, as expected.
But with the header Firefox shows me the URL of the page (like http://www.sabianoar.com.br/novosabia/inc/phpImg.php?img=awful_escaped_long_path.jpeg), and if I do CTRL+I it tells me it is an JPEG of 0x0 size, and like 10kb.
Opera shows me an empty image, as it would do if I had placed an <img> with the wrong src, i.e.

[EDIT2] EyeOfGnome says "Not a JPEG file: starts with 0xef 0xbb" when I try to save and then open the output (it saves to a .jpeg file normally).

4

4 回答 4

3

Your code outputs BOM at the beginning. Open your code from remote web server and check (using hex editor, for example xxd) if it contains BOM before <?php. If BOM isn't in a file you're looking at, it might be in includes.

Some editors add BOM and apache outputs it. That's probably what breaks your images.

于 2009-08-28T12:36:29.993 回答
0

Check the permissions of the image/directory where the image is located.

于 2009-08-28T05:01:39.430 回答
0

This probably isn't the cause, but why are you echoing the result of Fotos::redimensional()? The functions like imagejpeg() etc. all return a bool (not the image data) after outputting the image, so you will end up printing a '1' to the end of the image. I just tested this though and it doesn't seem to break jpeg images.

于 2009-08-28T07:58:58.543 回答
0

Have you tried comparing your local machine to the server? Compare the output of phpinfo(); Are they different platforms?

于 2009-08-28T13:54:21.800 回答