Cree
asked on
Returning junk when using imagecreatefrompng()
I have a IIS server running php 5.4.9
I have added the extension path of where I put the php_gd2.php and added "extension = php_gd2.php" on my php.ini
When I fun the following script:
I get a bunch of junk on my browser. that looks like png code.
‰PNG IHDRÉ ŸÅ IDATxœí{y´eWYçoOgºço¨¹*y• Te ¤ª ‘0…µƒ4 „]vŒ-.•W°qÓy¸Q”´¢µÁ 4þ!Ø!C‘W$ Á„ªT*©$j® TUjxÓÎ=çì ±ÿØ÷ÞºU‡v i/×ÊþãóöÙ gßþöoû›. ðr{¹½Ü^nÿ¾ ùç½tÿjŒ¼Ü þåíÜLà_¼}ÌÿÍvÞp2çBHÿ!££IÀySœû°ÖzÒÃOàœëÏé?x)/|”É‘·çžÈyËtä•ñpiçXò“;?Õ`2r>§#¼GÞ éŸ<²ð18€Rznž8s#Ôû2YËùÂñ#=ÿ„7˜oT¶Úä% 3œÇ÷÷nÎý?€ Azø̇O,`× ýâ5Œ1ZkÁ8ç q „”ˆƒ°( ?¿Â `œ1–+€RšeY–e~@RJRÊ¢A¹š «ªH„ Z™¨’ Œ¶¥¶J{*Ahhgl¯(ä¶ô‹1ÆÖ³ 'n-Ë@H9 çœSÆZí8cp ÊHRJýîrÎË ²BȲŒRzåÕ ûì³*µñ ¦€\»B[c£iš¦i(ËÒo¨3ΖPÚ (:2‰Rc¬ˆ? ©ÀÀ)µ eaaðŒê¶[8¾ rI’LÆéò oæù\Ï”ÆØùtEN•JÇ!t»Æ q”Z‡€±D0!úV£ñÝnW;ÀSkÔ|§³–Vôzâ8Niätb¬Ó@ÌbêMΘRÖãÚ‚tcÌcó{d`à·Îè Ê2Ïe I¢˜Ç$li†`µîÏa‡lú½×x2²§f ÿ|g}eê_ùẠ4E§¼ê-Æ/® p›ÃpΡ þÙ£•`áò… bïß<ŸLĪÔé dzñ¯ eÙwXa½³òØ£GŠf1qÉä%7lôØ¢Þè;U ÄRx/Ásì á“£í°i£ ±pÍõ+&ÃÐᜯ[·Î͹¹¹ž—{—UêÕÂi<Ë»(qÐÌ RzÒ„J©ö è뉡¯W,‡ :-dË/_~ñôT_¶ƒÝÿû±Ê²*t©EÌ7¾ùò'¿°+]ž° Öé\½òÝWsAÕž¨7ÎB€hZø5rÎ9gƒ ëkGk-J@k†¡’Òà”åyîù¬•¾ `#`ý«-`Þ’c”˜¾é=e?3!ÄZëûU+'„x0}X÷¯£¾êú³ y‡r†Gþø £ú'pÔ–'ñàèL:ëO´q~Û¶mÛû~í—¯zÇ¥AEPÎ þŠ²ŒÓŠgBY MüÞpžuÚñdÜ |¡µcÇŽ·ýÄÛ ýâ5´2Ä’ c©,K¾t÷âg~Òå91Æ;ƒ}E-D Vcj€ÓÏý¯¿ºç¦›nj6›“Ë' WVE…',Qªî99xp?€(Š8çÞý!Ë—“JЖ @’Š$#ÍJºí¶]´&''½Nʲ¬( ïçöíú´/kG©7zlº²¬úù?ýüOþç ÷\F_Б™5 ¶}ª ÙlN,›hi‰8hlõ…ð H”îÉRBî›”’RÇ€†cŽpJk;*£Tx{7Š„š‹þ‡ <Ø0½þñ' ¤¿ëDyT€1V 9^xH]°Ñ•É1g¬¬å<`µ1R¯¼‘ RpF†`m#ö !$´UJ§½J Û³gϽíM„ Ì~ý[·Ür˯üÆmì.m·Nv¬¶ $]/¿v2^-Mi:‡ºs{çËvI9«_\¯¬ªC "VÚg¿úL¾” F–_=¹ü•“”‘ …}ùb¯·íرCõäÞ{ö¬½ví™çΔíÒ9„ µpÅUkV^¾I àø±ãÞhîˆPÜtÓ
Any suggestions?
I have added the extension path of where I put the php_gd2.php and added "extension = php_gd2.php" on my php.ini
When I fun the following script:
<?php
$string = 'TEST TEXT';
$im = imagecreatefrompng("images/backtoa_manager.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
I get a bunch of junk on my browser. that looks like png code.
‰PNG IHDRÉ ŸÅ IDATxœí{y´eWYçoOgºço¨¹*y•
Any suggestions?
ASKER
I tried that before but this is all i see.
this is my code now
this is my code now
<?php
header('Content-Type: image/png');
$string = 'testing';
$im = imagecreatefrompng("http://192.168.0.117/images/backtoc_manager.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
In case you wonder if that image doesn't exist... ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you . That did it. The image is showing up with text perfectly now.
The problem is that the browser doesn't realize that the data is a PNG image (as opposed to just html/text, which is what a PHP file normally returns)
You must send the correct MIME headers so that the browser renders the data as a PNG instead of just displaying it as raw text.
See the example here:
http://php.net/manual/en/function.imagepng.php
The appropriate call for the content-type header for a PNG graphic is:
header('Content-Type: image/png');