I want to be able to show an image made on the fly with php in jQuery Dialog window.
When I try this all I get is the binary data for the image. But creating the image on a normal php page is not a problem.
I have a simple php script to create the image
public function image()
{
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 400);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 399, $white);
// The text to draw
$text = 'Just some simple text...';
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 10, 40, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
}
Creation of the dialog is not a problem and outputting html.
Any suggestion on how I can get this to show my created image ?
Really hope someone can help?
Thank you
Load the image using $.ajax() and inject into DOM:
$.load('#yourDialogContentDiv').html('<img src="http://YOUR_PHP_IMAGE_GENERATOR_SCRIPT" />'));
Then show your jQuery dialog.
Presto!
Related
I want to ask on how to create an image based on updated data on my site?
For example like this image:
[![x][1]][1]
The details of the image is get from this url: [Pine][2].
That's the full code:
It's show an image with updated data based on that link.
Can someone show me what I have to find in google for the details like this? what type is this code?
You should use GD library or Imagick(ImageMagick)
Example of image creation with GD
To install or enable already installed GD extension (https://stackoverflow.com/a/44720393/8579824)
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
I want to display hindi words on an image. Here is the code for it, it is working properly but it does not display "chote E ki matra" correctly. Example "अब हिन्दी" is displayed as : http://prntscr.com/8rj8mq
Also hindi.txt file contains these :
अब हिन्दी
मे टाइप
करना बहुत आसान है
Below php script read one line randomly and put it on image and display it. Can someone help me to correct this....
<?php
$word= file("hindi.txt");
$random = rand(0,2);
$text = $word[$random];
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
// Replace path by your own font path
$font = 'Mangal.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
i have a image and i wrote some text on this image by using php "imagettftext" function. now i don't know that how it will save automatic.
header('Content-Type: image/png');
// Create the image
$im = imagecreatefromjpeg('image-1.jpg');
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
//imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'www.blockprintsonline.com';
// Replace path by your own font path
$font = 'arial.ttf';
list($width, $height, $type, $attr) = getimagesize($get_image);
$width1=$width*20/100;
$height1=$height*50/100;
$font_size=$width*4/100;
// Add some shadow to the text
//imagettftext($im, 30, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, $font_size, 0, $width1, $height1, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
If you want to save the image to a file, check out the docs for the imagepng() function here.
By passing a filename as the second argument it will save the image to a file, e.g:
imagepng($im, "path/to/save/image/in.png");
<?php
// Save the image as 'simpletext.png'
imagepng($im, 'simpletext.png');
// Free up memory
imagedestroy($im);
?>
this is an example on how to save an image.
If you check the documentation for imagepng you would see that you can provide a filename. That would save the image to disk
I want to create images for my dynamic text.
My problem is that I am reading folder name from some specific directory.
So folder name will be what ever but client wants that folder name should come as the images only.
So I thought that I will place one image with the same name as folder on any unique name.
But client don't want to create new images if they create a new folder.
So how can I do this with PHP?
I need to use some specific background color for image and also want to use some specific font for the text in image.
See imagefttext() in the examples section
From php.net:
http://pl2.php.net/manual/en/function.imagettftext.php
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
What is the best way to display underlined text and output the result as image with GD or any other library?
You can try using the Unicode underline combining character U+0332.
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = "̲U̲d̲e̲r̲l̲i̲n̲e";
// Replace path by your own font path
$font = 'arial.ttf';
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
There are lots of FREE PHP CAPTCHA out there that come with a lot of customization, download one and see what exactly happens behind the scene. Also have a look at this link
HTH
I am using this...
$font = imageloadfont($font_file);
$font_width = ImageFontWidth($font);
$font_height = ImageFontHeight($font);
$str_width = strlen($text)*$font_width;
ImageLine($image, $left, $top+$font_height, $left+$str_width, $top+$font_height, $color);