I need to render an image (PNG) from a string (a user's telephone number) when the page is presented goes. Is it possible to present the image within the PHP page? Or should I have to create a page specifically to render the image and I will include it?
If I use this code inside my php page, it does not work properly
& lt ;? Php // Create a 100 * 30 image $ im = imagecreate (100, 30); // White's background and blue text $ BG = Size of image ($ im, 255, 255, 255); $ Text color = picture calculator ($ im, 0, 0, 255); // Write the string on the upper left commenting ($ im, 5, 0, 0, 'hello world!', $ Text color); // Output image header ('content-type: image / PNG'); Imagepng ($ im); Imagedestroy ($ im); ? & Gt;
I have to declare "header-type: image / PGN" or another way of rendering PNG because if I I declare this, then the other parts of the page are not presented.
I am using Zend Framework 2
As he suggested me, I used Base 64 mode Tried to use and works fine
& lt ;? php ob_start (); $ im = @imagecreate (110, 20) or die ("new gd image The stream can not be initialized "); $ Background_color = imagecolorallocate ($ im, 0, 0, 0); $ Text_color = imagecolorallocate ($ im, 233, 14, 91); Imagestring ($ im, 1, 5, 5 , "A simple text string", $ text_color); imagepng ($ im); $ Image_data = ob_get_contents (); Ob_end_clean (); $ Image_data_base64 = base64_encode ($ image_data);? & Gt; & lt; img src = "data : Image / png; Base64, & lt ;? Php echo $ image_data_base64 ;? This is an exam, do not compete with and use this code on your site; It is unsafe.
With all web pages - Images are not part of HTML - they are separate So if you have files, you have to create a separate file and set the appropriate headings for your image, and then just add the URL of the file to the source of your image
Keep in mind that if your Url "file.php? Number = 123456 ", robots are easy to find phone numbers and it will only beat the purpose of the image (if I believe this purpose correctly).
Alternatively, You can create an image, change it to base 64 and embed it in the actual HTML source as a data-uri. I do not recommend it, but if you are interested, just "html data -uri "google - You will find many examples.
No comments:
Post a Comment