1

I have an image error when i try to generate a jpeg image but php doesn't retrieve me any errors

<?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);  
        }
    }

This code shows the default avatar if user's avatar not exist. If user's avatar exist and image extension is PNG, the code converts image PNG to JPG

The problem is that the image have error. This is the image jpeg code:

ÿØÿà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 dont return me any errors and gd functions return bool(true). The default image shows fine in my S.O

50l3r
  • 1,549
  • 4
  • 16
  • 27
  • 2
    Are you expecting us to spot an error in a (corrupted) dump of a binary file format? Wouldn't be easier to just read those errors you've discarded? – Álvaro González Jan 20 '14 at 15:20
  • I suggest you step through your code and try to see what part is giving you the error. Also, how do you know there is an error at all? By what means are you outputting the image? You know you must also set the `header("Content-Type: image/jpg");` in order for the browser to render an image. – user1477388 Jan 20 '14 at 15:30
  • Aren't you going to end up trying to output 2 images if the image file can't be found? – Raad Jan 20 '14 at 15:32
  • i comment the header and error reporting for retrieve all errors but i dont recieve anymore. I refresh the code to prevent 2 image output. – 50l3r Jan 20 '14 at 15:49
  • I don't think there is an error - what you are seeing in the image jpeg code is the EXIF data. GD tags the files it makes so people can see how they were made. – madebydavid Jan 21 '14 at 02:02
  • But if I try to display the image, it gives error: ( – 50l3r Jan 21 '14 at 11:38

1 Answers1

0

Finally, the problem was a space in front of all code

50l3r
  • 1,549
  • 4
  • 16
  • 27