How can I align text to an image automatically in PHP? -


I have some lines of code to create a plain image with some given PHP text. But when I give the width of the image text then goes out of the image. How can I align the text inside the image with a fixed width but dynamic height? My code is given below.

  header ("content-type: image / PNG"); $ String = 'Lorem Ipsum is simply the dummy text of the printing and typesetting industry; Lorem Ipsum 1500s' has been the industry standard dummy text since; $ Font = 4; $ Width = ImageFontWidth ($ font) * strlen ($ string); $ Height = ImageFontHeight ($ font); $ Im = @imagecreate (200,500); $ Background_color = imagecolorallocate ($ im, 255, 255, 255); // white background $ text_color = imagecolorallocate ($ im, 0, 0,0); // black text imagestring ($ im, $ font, 0, 0, $ string, $ text_color); Imagepng ($ im);   

I want this image to automatically adjust the text based on the given paragraph. How to do this

You can try this: (based on the contributions of Gannon)

  header ("content-type: image / png"); $ String = "Dummy \ n text is mainly the text of the printing and typing industry. Lorem Ipsum has been the standard dummy text of the industry since the 1500s;" $ Im = make_wrapped_txt ($ string, 0, 4, 4, 200); Imagepng ($ im); Function make-work_tit ($ test, $ color = 000000, $ location = 4, $ font = 4, $ w = 300) {if (strollon ($ color)! = 6) $ color = 000000; $ Int = hexdec ($ color); $ H = imagefontheight ($ font); $ Fw = imagefontwidth ($ font); $ Txt = Explosion ("\ n", wordDrop ($ textile, ($ w / $ fw), "\ n")); $ Rows = count ($ txt); $ Im = imagecreate ($ w, ($ h * $ rows) + ($ lines * $ location)); $ Bg = picture algorithm ($ im, 255, 255, 255); $ Color = imagecolorallocate ($ im, 0xFF & amp; ($ int> & gt; 0x10), 0xFF & amp; ($ int> & gt; 0x8), 0xFF and $ int); $ Y = 0; Foreign currency ($ test as $ text) {$ x = (($ w - ($ fw * strlen ($ text)) / 2); Imagestring ($ im, $ font, $ x, $ y, $ text, $ color); $ Y + = ($ h + $ location); } Return $ IM; }   

Given this type of result:

 Enter image details here

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -