How to create image in php -


i creating image php

code

$src = array ("22.jpg","33.jpg","44.jpg","55.jpg","66.jpg","77.jpg");                     $imgbuf = array ();                  foreach ($src $link)                  {                     switch(substr ($link,strrpos ($link,".")+1))                     {                         case 'png':                             $itmp = imagecreatefrompng($link);                             break;                         case 'gif':                             $itmp = imagecreatefromgif($link);                             break;                                        case 'jpeg':                                    case 'jpg':                             $itmp = imagecreatefromjpeg($link);                             break;                                    }                     array_push ($imgbuf,$itmp);                  }                   $iout = imagecreatetruecolor ("35","210") ;                   imagecopy ($iout,$imgbuf[0],0,0,0,0,imagesx($imgbuf[0]),imagesy($imgbuf[0]));                  imagedestroy ($imgbuf[0]);                  imagecopy ($iout,$imgbuf[1],0,35,0,0,imagesx($imgbuf[1]),imagesy($imgbuf[1]));                  imagedestroy ($imgbuf[1]);                  imagecopy ($iout,$imgbuf[2],0,70,0,0,imagesx($imgbuf[2]),imagesy($imgbuf[2]));                  imagedestroy ($imgbuf[2]);                  imagecopy ($iout,$imgbuf[3],0,105,0,0,imagesx($imgbuf[3]),imagesy($imgbuf[3]));                  imagedestroy ($imgbuf[3]);                  imagecopy ($iout,$imgbuf[4],0,140,0,0,imagesx($imgbuf[4]),imagesy($imgbuf[4]));                  imagedestroy ($imgbuf[4]);                  imagecopy ($iout,$imgbuf[5],0,175,0,0,imagesx($imgbuf[5]),imagesy($imgbuf[5]));                  imagedestroy ($imgbuf[5]);                 imagepng($iout);               //header ( 'content-type:image/png' );                 // save img directory                   $char='0123456789';                 $length=10;                 $max_i=strlen($char)-1;                 $value='';                 for($j=0;$j<$length;$j++)                 {                 $value.=$char{mt_rand(0,$max_i)};                 }                 $imageid=$value; 

it giving error on page

‰png ihdr#Òouî² cidatxœíÖ]ŒdÇuðÿ9§êÞþ˜™]ïìÇlbc‚ÀІ(@dqž @"$ƒ”<°e‚xxy~ e d¼€"!Âi’;q$£°m¼ïzw½_3ÓÓÝ÷Ö×9<ô̬óÄrê§v«Õ·»ÿu]uÏ)jÙ ‚Ì€˜7€wâÕ½«¯^»Óçþå™åfȹ-š© *6›çŸù¹÷ðêðÌ[í‰%üÈ]؆0‡8@@Ùl3¼Än‘×ãÞ«·žxôñ»×69àôú©e?ÊóÙÊx™’w+Ü”˜c1vö4Üîowq÷zwë?ýi·u§,É~@½™@pf¼Ž'>ô»ÇýÚ‘áÊòêÒh8hëᬠŒ,eïÄ9îk ¡lº½4ëºÙüÖ7Óä¿ø—Ø–€‡(™€b’ »øØ¹ß\k÷o¾ãÌúi&*‚lÙÁr4p£ÄeÕ‰p¢ó!Î}ë:ëedÄ-gx_.߸òòök¯ûŸúöߣmp~1'ç($àßo½-­ÿÀÛï][z/1Ëlo‡paÕa#¥›{4Óɘ4—\Š9í%©fË'7ÓÕñÝîƒÅ_h¹@ønþÄû}ðØ­?6nslªêü0ö¡q%ö#fÖ2²Óbð’´¨ªjs¸,¾ge.ì\x~÷ùo>ûØ x°"*¶ñ±|äÄÚ™ñʱÉv§Á4x‰¶·Óõ†s‹½€½Ž£qfècÅcŒ¡oh ˆ²ÝˤϷws›ë›'è$þûòþ:931þkû¸-z;1Ÿv%ôÐ’c ߸&lûaëgq:Ó>Í•àÃñ`¼:;eŠÉhbl­¸ºv<š¤É€†§†Ç¿õ¥¯ŸýÉì');¾ó·7ëÜ' 9ö¥ˆh\c–Çäß¼ùæ%Ýž #µs­¦áéptu–}±lst°f:£#úãÏ}ù«g?hÊ q<÷¥=5>–»b¢m¹uv †½8»<»úûŸ{ooa€xmïÓ|üÈÚÀ›Ï}/

how can solve

what you're seeing actual content of image that's generated. need specify content/type, otherwise assumed text/plain or text/html. image seem png, so

header("content-type: image/png") 

should sufficient. can see line commented out - needs included. 1 note though: needs go before actual image data output, need move top of script (or @ least above imagephp call).

edit: if want save resulting image file rather output browser, need pass second parameter imagepng function:

imagepng($iout, $myfilename) 

see imagephp documentation more details

edit 2: if need content of created image use elsewhere, can use trick:

ob_start(); imagephp($iout); $image_data = ob_get_clean(); 

now got resulting image data in variable , can continue script.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -