{"id":3204,"date":"2018-04-26T06:19:09","date_gmt":"2018-04-26T06:19:09","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=3204"},"modified":"2018-04-26T06:19:09","modified_gmt":"2018-04-26T06:19:09","slug":"create-dynamic-image-text-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/","title":{"rendered":"Dynamic Image Creation with PHP"},"content":{"rendered":"<p>The image functions of GD library is the easiest way to create dynamic image with text in PHP. In some situation, you need to create an image on the fly and write dynamic text to image. To generate a dynamic random image with PHP, GD library needs to be installed. In this tutorial, we will show you how to <b>create dynamic image with PHP<\/b>.<\/p>\n<p>The example code creates a dynamic image with PHP based on the specified configuration. You can customize the image width, height, background color, text color, and text.<\/p>\n<h2>Create Dynamic Image with PHP<\/h2>\n<p>The following code generates a random dynamic image using PHP. The GD image functions are used to create dynamic image with PHP.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>imagecreate() &#8211; Creates blank image resource of specified size (width and hwight).<\/li>\n<li>imagecolorallocate() &#8211; Allocate a color for an image resource.<\/li>\n<li>imagettfbbox() &#8211; Calculate the bounding box in pixels for TrueType text.<\/li>\n<li>imagettftext() &#8211; Write text to the image using TrueType fonts.<\/li>\n<li>imagepng() &#8211; Creates a PNG image.<\/li>\n<li>imagedestroy() &#8211; Destroy an image resource.<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Specify&nbsp;font&nbsp;path<br \/><\/span><span style=\"color: #0000BB\">$font&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'fonts\/verdana.ttf'<\/span><span style=\"color: #007700\">;<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Text&nbsp;font&nbsp;size<br \/><\/span><span style=\"color: #0000BB\">$font_size&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">10<\/span><span style=\"color: #007700\">;<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;settings&nbsp;from&nbsp;URL<br \/><\/span><span style=\"color: #0000BB\">$setting&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;isset(<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'s'<\/span><span style=\"color: #007700\">])&nbsp;?&nbsp;<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'s'<\/span><span style=\"color: #007700\">]&nbsp;:&nbsp;<\/span><span style=\"color: #DD0000\">\"000_FFF_350_350\"<\/span><span style=\"color: #007700\">;<br \/><\/span><span style=\"color: #0000BB\">$setting&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">explode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"_\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$setting<\/span><span style=\"color: #007700\">);<br \/><br \/><\/span><span style=\"color: #0000BB\">$img&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array();<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Define&nbsp;image&nbsp;width,&nbsp;height,&nbsp;and&nbsp;color<br \/><\/span><span style=\"color: #007700\">switch(<\/span><span style=\"color: #0000BB\">$n&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">count<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$setting<\/span><span style=\"color: #007700\">)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #0000BB\">$n&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">4&nbsp;<\/span><span style=\"color: #007700\">:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #0000BB\">3<\/span><span style=\"color: #007700\">:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$setting<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">3<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$setting<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">];<br \/>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #0000BB\">4<\/span><span style=\"color: #007700\">:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'width'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;(int)&nbsp;<\/span><span style=\"color: #0000BB\">$setting<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">];<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'height'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;(int)&nbsp;<\/span><span style=\"color: #0000BB\">$setting<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">3<\/span><span style=\"color: #007700\">];<br \/>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'background'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$setting<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">];<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'color'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$setting<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">];<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;default:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list(<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'background'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'color'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'width'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'height'<\/span><span style=\"color: #007700\">])&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'F'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'0'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br \/>}<br \/><\/span><span style=\"color: #0000BB\">$background&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">explode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\",\"<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">hex2rgb<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'background'<\/span><span style=\"color: #007700\">]));<br \/><\/span><span style=\"color: #0000BB\">$textColorRgb&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">explode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\",\"<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">hex2rgb<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'color'<\/span><span style=\"color: #007700\">]));<br \/><\/span><span style=\"color: #0000BB\">$width&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;empty(<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'width'<\/span><span style=\"color: #007700\">])&nbsp;?&nbsp;<\/span><span style=\"color: #0000BB\">100&nbsp;<\/span><span style=\"color: #007700\">:&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'width'<\/span><span style=\"color: #007700\">];<br \/><\/span><span style=\"color: #0000BB\">$height&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;empty(<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'height'<\/span><span style=\"color: #007700\">])&nbsp;?&nbsp;<\/span><span style=\"color: #0000BB\">100&nbsp;<\/span><span style=\"color: #007700\">:&nbsp;<\/span><span style=\"color: #0000BB\">$img<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'height'<\/span><span style=\"color: #007700\">];<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;text&nbsp;from&nbsp;URL<br \/><\/span><span style=\"color: #0000BB\">$text&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(string)&nbsp;isset(<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'t'<\/span><span style=\"color: #007700\">])&nbsp;?&nbsp;<\/span><span style=\"color: #0000BB\">urldecode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'t'<\/span><span style=\"color: #007700\">])&nbsp;:&nbsp;<\/span><span style=\"color: #0000BB\">$width&nbsp;<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;x&nbsp;\"<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$height<\/span><span style=\"color: #007700\">;<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Create&nbsp;the&nbsp;image&nbsp;resource&nbsp;<br \/><\/span><span style=\"color: #0000BB\">$image&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;@<\/span><span style=\"color: #0000BB\">imagecreate<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$width<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$height<\/span><span style=\"color: #007700\">)&nbsp;or&nbsp;die(<\/span><span style=\"color: #DD0000\">\"Cannot&nbsp;Initialize&nbsp;new&nbsp;GD&nbsp;image&nbsp;stream\"<\/span><span style=\"color: #007700\">);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Create&nbsp;image&nbsp;background<br \/><\/span><span style=\"color: #0000BB\">$background_color&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagecolorallocate<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$image<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$background<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$background<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$background<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">]);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Grab&nbsp;the&nbsp;width&nbsp;&amp;&nbsp;height&nbsp;of&nbsp;the&nbsp;text&nbsp;box<br \/><\/span><span style=\"color: #0000BB\">$bounding_box_size&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagettfbbox<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$font_size<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$font<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$text<\/span><span style=\"color: #007700\">);<br \/><\/span><span style=\"color: #0000BB\">$text_width&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$bounding_box_size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">]&nbsp;-&nbsp;<\/span><span style=\"color: #0000BB\">$bounding_box_size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">];<br \/><\/span><span style=\"color: #0000BB\">$text_height&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$bounding_box_size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">7<\/span><span style=\"color: #007700\">]-<\/span><span style=\"color: #0000BB\">$bounding_box_size<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">];<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Text&nbsp;x&amp;y&nbsp;coordinates<br \/><\/span><span style=\"color: #0000BB\">$x&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">ceil<\/span><span style=\"color: #007700\">((<\/span><span style=\"color: #0000BB\">$width&nbsp;<\/span><span style=\"color: #007700\">-&nbsp;<\/span><span style=\"color: #0000BB\">$text_width<\/span><span style=\"color: #007700\">)&nbsp;\/&nbsp;<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">);<br \/><\/span><span style=\"color: #0000BB\">$y&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">ceil<\/span><span style=\"color: #007700\">((<\/span><span style=\"color: #0000BB\">$height&nbsp;<\/span><span style=\"color: #007700\">-&nbsp;<\/span><span style=\"color: #0000BB\">$text_height<\/span><span style=\"color: #007700\">)&nbsp;\/&nbsp;<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Define&nbsp;text&nbsp;color<br \/><\/span><span style=\"color: #0000BB\">$text_color&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">imagecolorallocate<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$image<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$textColorRgb<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$textColorRgb<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$textColorRgb<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">]);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Write&nbsp;text&nbsp;to&nbsp;image<br \/><\/span><span style=\"color: #0000BB\">imagettftext<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$image<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$font_size<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$x<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$y<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$text_color<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$font<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$text<\/span><span style=\"color: #007700\">);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;the&nbsp;content&nbsp;type&nbsp;header&nbsp;-&nbsp;in&nbsp;this&nbsp;case&nbsp;image\/png<br \/><\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'Content-Type:&nbsp;image\/png'<\/span><span style=\"color: #007700\">);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;the&nbsp;image<br \/><\/span><span style=\"color: #0000BB\">imagepng<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$image<\/span><span style=\"color: #007700\">);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Free&nbsp;up&nbsp;memory<br \/><\/span><span style=\"color: #0000BB\">imagedestroy<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$image<\/span><span style=\"color: #007700\">);<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Convert&nbsp;color&nbsp;code&nbsp;to&nbsp;rgb<br \/><\/span><span style=\"color: #007700\">function&nbsp;<\/span><span style=\"color: #0000BB\">hex2rgb<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">)&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$hex&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">str_replace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"#\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">);<br \/><br \/>&nbsp;&nbsp;&nbsp;&nbsp;switch(<\/span><span style=\"color: #0000BB\">strlen<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$hex&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$r&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$g&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$b&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #0000BB\">3<\/span><span style=\"color: #007700\">:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$r&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">).<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$g&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">).<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$b&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">).<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$r&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$g&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$b&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">hexdec<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$hex<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">4<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/><br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$rgb&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array(<\/span><span style=\"color: #0000BB\">$r<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$g<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$b<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">implode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\",\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$rgb<\/span><span style=\"color: #007700\">);&nbsp;<br \/>}<\/span><\/pre>\n<p><b>Configure Options:<\/b><\/p>\n<ul class=\"bullet_disk_list\">\n<li>s &#8211; Specify the image background color, foreground color, width, and height in the query string. The settings should be separated by an underscore (_). (For example, 000_FFF_350_350)<\/li>\n<li>t &#8211; Specify text that you want to write on the image. By default, the image width and height will be written over the image.<\/li>\n<\/ul>\n<p><b>Usage:<\/b><br \/>\nSpecify the URL of the dynamic image generation script with the configuration option in the src tag.<\/p>\n<pre>&lt;<span style=\"color:#bf4f24\">img<\/span> <span style=\"color:#bf4f24\">src<\/span>=<span style=\"color:#0b6125\">\"create_image.php?s=000_FFF_350_350<span style=\"background:#b52a1d;color:#f8f8f8;\">&amp;<\/span>t=Dynamic Image\"<\/span> >\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>The dynamic image creation functionality is very useful when you want to create a random image on the fly for Captcha code. If you want to make the image transparent, don&#8217;t use the background color. You can easily extend our dynamic image generation code functionality as per your needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The image functions of GD library is the easiest way to create dynamic image with text in PHP. In some situation, you need to create an image on the fly and write dynamic text to <\/p>\n","protected":false},"author":1,"featured_media":3206,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[14],"class_list":["post-3204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Dynamic Image Creation with PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Create dynamic image with PHP - Use image functions of GD library to create dynamic image on the fly using PHP. The example code to generate a random image with dynamic text in PHP. Create dynamic image and customize the image width, height, background color, text color, and text.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dynamic Image Creation with PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Create dynamic image with PHP - Use image functions of GD library to create dynamic image on the fly using PHP. The example code to generate a random image with dynamic text in PHP. Create dynamic image and customize the image width, height, background color, text color, and text.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-26T06:19:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/04\/create-dynamic-image-with-text-php-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Dynamic Image Creation with PHP\",\"datePublished\":\"2018-04-26T06:19:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/\"},\"wordCount\":300,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/create-dynamic-image-with-text-php-codexworld.png\",\"keywords\":[\"PHP\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/\",\"name\":\"Dynamic Image Creation with PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/create-dynamic-image-with-text-php-codexworld.png\",\"datePublished\":\"2018-04-26T06:19:09+00:00\",\"description\":\"Create dynamic image with PHP - Use image functions of GD library to create dynamic image on the fly using PHP. The example code to generate a random image with dynamic text in PHP. Create dynamic image and customize the image width, height, background color, text color, and text.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/create-dynamic-image-with-text-php-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/create-dynamic-image-with-text-php-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"create-dynamic-image-with-text-php-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/create-dynamic-image-text-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dynamic Image Creation with PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dynamic Image Creation with PHP - CodexWorld","description":"Create dynamic image with PHP - Use image functions of GD library to create dynamic image on the fly using PHP. The example code to generate a random image with dynamic text in PHP. Create dynamic image and customize the image width, height, background color, text color, and text.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/","og_locale":"en_US","og_type":"article","og_title":"Dynamic Image Creation with PHP - CodexWorld","og_description":"Create dynamic image with PHP - Use image functions of GD library to create dynamic image on the fly using PHP. The example code to generate a random image with dynamic text in PHP. Create dynamic image and customize the image width, height, background color, text color, and text.","og_url":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2018-04-26T06:19:09+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/04\/create-dynamic-image-with-text-php-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Dynamic Image Creation with PHP","datePublished":"2018-04-26T06:19:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/"},"wordCount":300,"commentCount":4,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/04\/create-dynamic-image-with-text-php-codexworld.png","keywords":["PHP"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/","url":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/","name":"Dynamic Image Creation with PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/04\/create-dynamic-image-with-text-php-codexworld.png","datePublished":"2018-04-26T06:19:09+00:00","description":"Create dynamic image with PHP - Use image functions of GD library to create dynamic image on the fly using PHP. The example code to generate a random image with dynamic text in PHP. Create dynamic image and customize the image width, height, background color, text color, and text.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/04\/create-dynamic-image-with-text-php-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/04\/create-dynamic-image-with-text-php-codexworld.png","width":1366,"height":768,"caption":"create-dynamic-image-with-text-php-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/create-dynamic-image-text-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Dynamic Image Creation with PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/04\/create-dynamic-image-with-text-php-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-PG","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=3204"}],"version-history":[{"count":1,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3204\/revisions"}],"predecessor-version":[{"id":3205,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3204\/revisions\/3205"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/3206"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=3204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=3204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=3204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}