我试图使用 php 将以下 rgb 图像转换为 dithering 图像,当尝试通过浏览器中的 xampp 服务器进行编译时,它不会显示任何图像 . 以下是要转换的图像

以下是 php 代码

<?php
// $src = imagecreatefromjpeg('download.jpg');

$image = imagecreatefromstring(file_get_contents($_FILES["download.jpg"]["out.jpg"]));

$info = getimagesize($_FILES["download.jpg"]["out.jpg"]);

$height = $info[1];
$width = $info[0];

$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

$red = imagecolorallocate($image, 255, 0, 0);
$green = imagecolorallocate($image, 0, 255, 0);

for ($j=0; $j < $height; $j++) { 
    for ($i=0; $i < $width; $i++) { 
        // save the current color value of the pixel
        $prevVal = imagecolorat($image, $i, $j);
        // check if pixel is set to white or black
        if ($prevVal < ($black + $white / 2)) {
            imagesetpixel($image, $i, $j, $black);
        } else{
            imagesetpixel($image, $i, $j, $white);
        }
// error calculation
        $error = $prevVal - imagecolorat($image, $i, $j);
// error propagation and
 // intercept the last line and column
        if($i < $width - 1){
            imagesetpixel($image, $i + 1, $j, imagecolorat($image, $i+1, $j)+(7 * $error/16));
        }
        if($j < $height - 1){
            imagesetpixel($image, $i, $j + 1, imagecolorat($image, $i, $j+1)+(5 * $error/16));
        }
        if($i < $width - 1 && $j < $height - 1){
            imagesetpixel($image, $i + 1, $j + 1, imagecolorat($image, $i+1, $j+1)+(1 * $error/16));
        }
        if($i > 0 && $j < $height-1){
            imagesetpixel($image, $i - 1, $j +1, imagecolorat($image, $i-1, $j+1)+(3* $error/16));
        }
    }
    }
    header("Content-Type: image/jpeg");
imagejpeg($image);
    ?>

以下是预期的图像格式