我尝试生成jpeg图像时出现图像错误,但php没有检索到任何错误
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Avatar extends Geopack_Controller{
public function __construct() {
parent::__construct();
}
public function getAvatar($UsuarioId){
error_reporting(0);
if(!is_numeric($UsuarioId)){exit;}
header("Content-type: image/jpeg");
$image_p = imagecreatetruecolor(150, 150);
$gen = false;
$avatar_image = $this->config->item('imgrack_apath')."/avatares/".$UsuarioId.".".$this->config->item('img_config_avatar')['sext'];
$avatar_default = $this->config->item('imgrack_apath')."/recursos/noavatar.jpg";
if(file_exists($avatar_image)){
if(@GetImageSize($avatar_image)){
$image = imagecreatefromjpeg($avatar_image);
}else{
$image = imagecreatefromjpeg($avatar_default);
}
}else{
$image = imagecreatefromjpeg($avatar_default);
}
if(!$image){$gen = true;$image = imagecreatefrompng($avatar_image);}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 150, 150, 150, 150);
if($gen){imagejpeg($image_p,$avatar_image);}else{imagejpeg($image_p);}
imagedestroy($image_p);
}
}
如果用户的头像不存在,此代码会显示默认头像。如果存在用户的头像并且图像扩展名为PNG,则代码将图像PNG转换为JPG
问题是图像有错误。这是图片jpeg代码:
ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC 2!!22222222222222222222222222222222222222222222222222ÿÀ––"ÿÄ ÿĵ}!1AQa"q2‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ?é(¢Š(¢Š(<š)¤F #È‘¡w`w¨ÅÜ%Q·`>B“ëYF"¢¸e4Ðì#hóò7$ÚûD^a˜+ŽÍÆi>Ó¹0s¼ûÄ<õ9úÒ†!ƒwhz9T½=ûS«*Ö쬮€“žÁªýµÂÜE¸pÃïC@QEQEQEQEQEQE ÅÊ[ -’O@;Ö\÷rÏÁ;Wû«N¿”Ks…èƒn}MV Š( Š( ¦µŸìÒ—+¸ƒŠ†ŠÝŠd™7#dwö©+3OEf,®Ë"ýáÔ0:(¢Š(¢Š(¢Š(¢Š*ɼ‹va÷õ©ë;TÎbôæ€3袎$ô×uK;¾¦ª¾ ü‘“îN*¬óä,~èû£ÐT`@’{ ¸5ïþ¬Eu§nJ·£VsE"º2R)”µEV³œÊ…å׿¨«4$˜&Y;¿JÝé\õlÙ1k8Éì1@(¢Š(¢Š(¢Š(¢Š*ž¤›ÃuªåQ¼»Ug€¦àW“šÌ¨®w b1RÑ@_fŸþy?åWlá1FY”«±ï×bŠ:ŒAê+"dÎè:ÅjK*Ãvü©¬–bÌYº““@Y]/¸"´ë>ÅL_²Œ~&´(ËdÙmÿ²+5ß" þ"oô Š( Š( Š( Š( ±¯†/$üé[5—©¦&GìËÊ€)QERNäšZ«~åaUÄy —™äÏEtSG£“M+HDQ?}ÆO°ô cbŒ"ôýiôQ@GhÜ:œ0èq[VÎÏm¿Þ#šÄU.ꃫVú€ªè-Q@Q@Q@Q@W¼·7¸FjŃ,FLlA#¸¦U½E6ÝþòÕJ*9`I‚‡Ï0jJ¯spÐÚ îÏZO°ÃþßçVÀvª?ÚÏ4ýjê6èÕR QE€.X@Æà;) £##©Zlk¶5_@:€ (¢€ (¢€ (¢€ (¢€ (¢€*ß@f‡*2éȾՑ] fjQ":ȸÝG¯½QªZ‡Xÿ»EböxÔGþè§Ñ@Z±·2Ê$aò!üÍUèURT ¨Þ€EPEPEPEPEPEP&™ Œ»ž?c\N×ïaÐJ›QµÎÎÈ8üj¥QEQEfÒìÛ¶ÖÉŒõžâ«Q@°e¤zKXQ\KÜr§QW#ÔÈâXóî´£ECÜýÙ>‡ƒSPEPEPE#:¢–bI¬ùõ,å`ð#þzIc…wHÁEgÍ©3qÚ?¼zÕ&fvÜìY½M%+1f,Ä’z“IEQEQEQEQET‘ÜKÜèy~=M‡FºÕ¸ï —€àFâ±h ‡‚’É #(ôŠF.ç,Ź¤Á¢Š0hÁ¢Š0hÁ¢Š0hÁ¢Š0hÁ¢Š0hÁ¢Š0hÁ¢Š0hÁ¢Š0hÁ¢Š9¢Š(ÿÙ
PHP不会返回任何错误,gd函数返回bool(true)。我的S.O
中的默认图像显示正常答案 0 :(得分:0)
最后,问题是所有代码前面的空格