gpt4 book ai didi

PHP imagepng() 正在创建损坏的图像

转载 作者:搜寻专家 更新时间:2023-10-31 22:10:29 25 4
gpt4 key购买 nike

我到处搜索以找到解决我的问题的可能方法。不幸的是,我似乎无法弄清楚。我有一个 .php 文件,它根据其他图像创建图像。我让脚本完全按照现在的样子运行,没有任何缺陷。但在摆弄其他一些文件后,它突然停止工作,并且现在在 Firefox、Chrome 和 IE 上生成损坏的 .png 图像。

image.php

<?php
ini_set("display_errors", 1);
ini_set("error_reporting", 2047);
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
error_reporting("E_ALL");

include("GameEngine/Database.php");
if(isset($_GET['uid'])){
$uid = $_GET['uid'];
} else {
$uid = "1";
}
if(isset($_GET['size'])){
if($_GET['size']=='profile'){
$size = '31x40';
}elseif($_GET['size']=='inventory'){
$size = '64x82';
}elseif($_GET['size']=='sideinfo'){
$size = '119x136';
}
} else {
$size = "119x136";
}
$herodetail = $database->HeroFace($uid);
if($herodetail['color']==0){
$color = "black";
}
if($herodetail['color']==1){
$color = "brown";
}
if($herodetail['color']==2){
$color = "darkbrown";
}
if($herodetail['color']==3){
$color = "yellow";
}
if($herodetail['color']==4){
$color = "red";
}
$geteye = $herodetail['eye'];
$geteyebrow = $herodetail['eyebrow'];
$getnose = $herodetail['nose'];
$getear = $herodetail['ear'];
$getmouth = $herodetail['mouth'];
$getbeard = $herodetail['beard'];
$gethair = $herodetail['hair'];
$getface = $herodetail['face'];

// USAGE EXAMPLE:
$body = imagecreatefrompng('img/hero/head/'.$size.'/face0.png');
if($getbeard!=5){
$beard = imagecreatefrompng('img/hero/head/'.$size.'/beard/beard'.$getbeard.'-'.$color.'.png');
}
$ear = imagecreatefrompng('img/hero/head/'.$size.'/ear/ear'.$getear.'.png');
$eye = imagecreatefrompng('img/hero/head/'.$size.'/eye/eye'.$geteye.'.png');
$eyebrow = imagecreatefrompng('img/hero/head/'.$size.'/eyebrow/eyebrow'.$geteyebrow.'-'.$color.'.png');
if($gethair!=5){
$hair = imagecreatefrompng('img/hero/head/'.$size.'/hair/hair'.$gethair.'-'.$color.'.png');
}
$mouth = imagecreatefrompng('img/hero/head/'.$size.'/mouth/mouth'.$getmouth.'.png');
$nose = imagecreatefrompng('img/hero/head/'.$size.'/nose/nose'.$getnose.'.png');
$face = imagecreatefrompng('img/hero/head/'.$size.'/face/face'.$getface.'.png');

// SAME COMMANDS:
$database->imagecopymerge_alpha($body, $face, 0, 0, 0, 0, imagesx($face), imagesy($face),100);
$database->imagecopymerge_alpha($body, $ear, 0, 0, 0, 0, imagesx($ear), imagesy($ear),100);
$database->imagecopymerge_alpha($body, $eye, 0, 0, 0, 0, imagesx($eye), imagesy($eye),100);
$database->imagecopymerge_alpha($body, $eyebrow, 0, 0, 0, 0, imagesx($eyebrow), imagesy($eyebrow),100);
if($gethair!=5){
$database->imagecopymerge_alpha($body, $hair, 0, 0, 0, 0, imagesx($hair), imagesy($hair),100);
}
$database->imagecopymerge_alpha($body, $mouth, 0, 0, 0, 0, imagesx($mouth), imagesy($mouth),100);
$database->imagecopymerge_alpha($body, $nose, 0, 0, 0, 0, imagesx($nose), imagesy($nose),100);
if($getbeard!=5){
$database->imagecopymerge_alpha($body, $beard, 0, 0, 0, 0, imagesx($beard), imagesy($beard),100);
}

// OUTPUT IMAGE:
header("Content-Type: image/png");
imagesavealpha($body, true);
imagepng($body, NULL);
?>

我已经尝试注释掉 header() 以便我可以在渲染图像之前检查任何 PHP 中是否存在错误。不是这种情况。我已经尝试了标签中的所有 $variables 来检查这些是否正确呈现。他们做到了。我不知道问题出在哪里。

我现在唯一的猜测是有一个空格或回车以某种方式添加到最终渲染中导致它损坏。但是,我已经搜索了这个可能的空白多年,但似乎找不到。

非常感谢任何提示和/或建议!

已解决此脚本包含的文件之一已保存为带 BOM 的 UTF-8。这给了图像一个额外的字节使其损坏。将所有文件保存为不带 BOM 的 UTF-8 解决了我的问题。

最佳答案

我看不出问题所在(除非有一些错误报告在进行?),但如果您将图像从浏览器保存到文件,然后在文本编辑器中打开它,问题可能会很明显。

编辑:原来是utf-8文件中的byte-order-mark。

关于PHP imagepng() 正在创建损坏的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13494595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com