首页 文章

PHP帮助:(图像“bla bla”无法显示,因为它包含错误

提问于
浏览
1

当我试图在我的网站上为全尺寸图像添加水印时,我在PHP中面临一个非常烦人的问题 . 水印工作正常数周,但突然间它开始出现这个错误:图片“bla bla”无法显示,因为它包含错误

我检查了一切,一切似乎工作得很好!我被困住了,我不知道该怎么做 .

这是我的水印php文件:

require_once "maincore.php";

if (isset($_GET['photo_id']) && isnum($_GET['photo_id'])) {

    $result = dbquery("SELECT td.*, tc.* FROM ".DB_PRODUCTS." td LEFT JOIN ".DB_PRODUCT_CATS." tc ON td.product_cat=tc.cat_id WHERE product_id='".$_GET['photo_id']."'");

    $data = dbarray($result);

        define("PHOTODIR", BASEDIR."downloads/images/");

        $parts = explode(".", $data['product_image']);

        $wm_file1 = $parts[0]."_w1.".$parts[1];

        $wm_file2 = $parts[0]."_w2.".$parts[1];

        if (!isset($_GET['full'])) {

            $wm_file = PHOTODIR.$wm_file1;

        } else {

            $wm_file = PHOTODIR.$wm_file2;

        }

        header("Content-type: image/jpg");

        $img = PHOTODIR.$data['product_image'];

        $cop = BASEDIR.$settings['photo_watermark_image'];

        if (preg_match("/.jpg/i", strtolower($img)) || preg_match("/.jpeg/i", strtolower($img))) {

            $image = imagecreatefromjpeg($img);

        } else if (preg_match("/.png/i", strtolower($img))) {

            $image = imagecreatefrompng($img);

        } else if (preg_match("/.gif/i", strtolower($img))) {

            $image = imagecreatefromgif($img);

            $sizeX = imagesx($image);

            $sizeY = imagesy($image);

            $image_tmp = imagecreatetruecolor($sizeX, $sizeY);

            $ica = imagecolorallocate($image_tmp, 255, 255, 255);

            imagefill($image_tmp, 0, 0, $ica);

            if ($settings['thumb_compression'] == "gd2") {

                imagecopyresampled($image_tmp, $image, 0, 0, 0, 0, $sizeX, $sizeY, $sizeX, $sizeY);

            } else {

                imagecopyresized($image_tmp, $image, 0, 0, 0, 0, $sizeX, $sizeY, $sizeX, $sizeY);

            }

            $tmp = PHOTODIR.md5(time().$img).'.tmp';

            imagejpeg($image_tmp, $tmp);

            imagedestroy($image_tmp);

            $image = imagecreatefromjpeg($tmp);

            unlink($tmp);

        }

        if (file_exists($cop) && preg_match("/.png/i", strtolower($cop)) && $settings['photo_watermark']) {

            $image2 = false;

            $image_dim_x = imagesx($image);

            $image_dim_y = imagesy($image);

            $copyright = imagecreatefrompng($cop);

            $copyright_dim_x = imagesx($copyright);

            $copyright_dim_y = imagesy($copyright);

            $where_x = $image_dim_x - $copyright_dim_x - 5;

            $where_y = $image_dim_y - $copyright_dim_y - 5;

            imagecopy ($image, $copyright, $where_x, $where_y, 0, 0, $copyright_dim_x, $copyright_dim_y);

            $thumb_w = 0; $thumb_h = 0;

            if (!isset($_GET['full'])) {

                if ($image_dim_x > $settings['photo_w'] || $image_dim_y > $settings['photo_h']) {

                    if ($image_dim_x  $image_dim_y) {

                        $thumb_w = $settings['photo_w'];

                        $thumb_h = round(($image_dim_y * $settings['photo_w']) / $image_dim_x);

                    } else {

                        $thumb_w = $settings['photo_w'];

                        $thumb_h = $settings['photo_h'];

                    }

                } else {

                    $thumb_w = $image_dim_x;

                    $thumb_h = $image_dim_y;

                }

                $image2 = imagecreatetruecolor($thumb_w, $thumb_h);

                if ($settings['thumb_compression'] == "gd2") {

                    imagecopyresampled($image2, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $image_dim_x, $image_dim_y);

                } else {

                    imagecopyresized($image2, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $image_dim_x, $image_dim_y);

                }

                imagedestroy($image);

            }

        }

        //create image

        if ($settings['photo_watermark_save']) { imagejpeg(($image2 ? $image2 : $image), $wm_file); }

        imagejpeg((isset($image2) && $image2 ? $image2 : $image));

        imagedestroy((isset($image2) && $image2 ? $image2 : $image));

        if (isset($copyright) && is_resource($copyright)) {  ImageDestroy($copyright); }

} else {

    redirect("index.php");

}

请帮我!谢谢!

1 回答

  • 0

    php.ini是否设置了display_errors?如果是这样,您的代码可能会发出警告或通知,该警告或通知会被合并到二进制图像数据中并破坏它 . 检查PHP错误日志以获取新条目 .

    另一种可能性是,包含文件通过在结束PHP标记下方的底部有多个空行来输出空白 .

相关问题