Jump to content

[SOLVED] playing with php and images


adam291086

Recommended Posts

I am looking at this tutorial http://discomoose.org/2005/10/19/write-text-on-to-an-existing-png-image-using-php/ but when i print out the image all i get is

‰PNG IHDR––³cæµëIDATxœíÁ‘Û0EåÌ‘ËV•*rHi"‡ "UåíB9pÆ£P²Lñ?ýßi×Ë ž@RmÞþÞ~.‚™·ìøúû—ååŸß~xE’—ì¬ý¹!z…B é‘Bz¤n…^3ê ·B±HáH!=Ä ©0GˆúÂ{BÜ?æM7ÝG¦d ‡Õ ‘È@…%Ý.¹Èêå¼D:¦bO”ÂmÒ-¡ƒQ^Mˆ°¢ð0ïW£‘·Å¥ îýž¤¾%z@s{Œ ñµè¬°EÀ£PÈÛbiˆ£EO…í¶  3·§¯9^ÝN`b<.Jž»EëlògÄž@“BùsÁ˜ÆþŽTþÜéëT;«Pþ"èËjBù‹£#·—Ê_4W3|M¡üáRžuמžk ‰n„Rs)Ï—«P£¹šau¤ôô(T!ÆÑ‘ÛÎ*”Åú²:õO¸}ÿSþX?Þs#yJwUô+üüöê2ñn«ýY|¯-XïæZ<×v‰\–‰µ#u”·=`ŠHãĪppwênîðø\,Ó]ûhÛ7ö^‹9‡éÈ„VoŠ_‘¦éÌ€L‘·g€Èîú6R${úF— ZÖÐâ¹Z…˜ù ª»$bú+Æ·‚ 0GqŽ[Á¾¿Tœ@‹¡òò” hG,B‚Ë_$f… ¹è!r-†#v)p'²…ôø“Ws§·ß÷Vh5÷kqA¡Jð„ÄBTÒ“¦p¦,dµ¨U¡®%ÆÓ˜óç/"äÍW‚A´ü„âÁ‹×YNÁø%o‹:I6*_ Ó™‰K0]T83þ•Bz¤)¤g´ÂW˜Ën£ª)¤G é‘Bz¤)¤G é‘Bz¤žÑ ñ}ÀÎà6ª é‘Bz¤)¤'AáÜ3šñ {[¦ÛòØ*«—Wke„“ÕÀ ¿Á¦¯5µàÞ‹¶ü0[ëX¨ßSOcÎÓf¤óMj²Z¤‹ z.(tïKg*Ä”Q° *¤'yç´9 1±U¡ô³0_az Ðßü.â‘×"BäùUX@ÈÅU@bÚ¿$#E;nÿÂêlÃÚ‚*5ˆ²/«pU¸~¼#‹Œ Na0SjTý £o?¡å+:ž9÷l±ˆÉŽ`oñ‘géÒ «ðNV ßk.“n$:R^ò^¾ƒ)™ IQy[8ÆÂGhSô#ØFº]âÔ\·E²Žô{‡Rq„9Ò_…8%8 C?#•¿fØ‚Rt´¥XÆlA)Ñðm~'Œ$o~' ÜüN_QCìjnYŒ&|)pÇ{ˆvÆ-B”ÅF¯`“E_rÖÎÈ¢™/dÑŽ1‡—ö²hÁž=‡µ3…KW£“ýÞTws\Î~7…Ksô‡q“Š´´Å«÷òT¸<‹¾%h —ö†hôB!„`a]ë?ú^Dôñ[ÐÂz&YÍýˆÛ-êÈU÷÷FOIS¸®ÿ5{ûï=;û¼ìŸ*/<|É¥ä>=Nõxù£jÅkQ"‡cÞºþ÷xõÔùã‡ÿžÇóèø-a'=V'ø£ó}û¸¥&Hë) #-½Ew„Pj'L>qùôZr;ÒRˆ'%wúW#ŸË³€«ÂjZدIÃ~xN¿¨B!„ çE-å+´KÃIEND®B`‚

 

Why?

 

 

Link to comment
Share on other sites

  
<?php
// load the image from the file specified:
$im = imagecreatefrompng("image.png");
// if there's an error, stop processing the page:
if(!$im)
{
die("");
}

// define some colours to use with the image
$yellow = imagecolorallocate($im, 255, 255, 0);
$black = imagecolorallocate($im, 0, 0, 0);

// get the width and the height of the image
$width = imagesx($im);
$height = imagesy($im);

// draw a black rectangle across the bottom, say, 20 pixels of the image:
imagefilledrectangle($im, 0, ($height-20) , $width, $height, $black);

// now we want to write in the centre of the rectangle:
$font = 4; // store the int ID of the system font we're using in $font
$text = "vdhri.net"; // store the text we're going to write in $text
// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*strlen($text) )/2;
// finally, write the string:
imagestring($im, $font, $leftTextPos, $height-18, $text, $yellow);

// output the image
// tell the browser what we're sending it
header("Content-Type: image/png");
// output the image as a png
imagepng($im);

// tidy up
imagedestroy($im);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.