Hi I coded an image generator from textbox to image, after it creates, when I want to save it as image it shows me
-*.php file, and not .png (image)-
code:
$name = $_POST['tekst'];
$file ="imgs/tbybc1.png";
header('Content-Type: image/png');
$im = imagecreatefrompng($file);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$text = $name;
$font = 'fonts/Roboto-Thin.ttf';
imagettftext($im, 40, 0, 70, 215, $white, $font, $text);
//imagettftext($im, 20, 0, 260, 255, $white, $font, $data);
imagepng($im);
imagedestroy($im);
what can I do for it, i googled but I didn't find anything. is there any solution to do this? or if there is any method of image generator tell me :) Thank You :)
You can use a htaccess rewrite for this.
eg.
RewriteRule ^/captcha.png$ /gen.php [NC,L]
then just include captcha.png in your page source:
<img src="/captcha.png" alt="" />
Related
I'm trying to output a text to image using a font that has 7 stylistic sets. I'm using the code below but can't find how I can use a style in the output. Any advice would be greatly appreciated.
<?php
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 = 'This is a test!';
// Replace path by your own font path
$font = 'joined.otf';
// 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'm making my own 'captcha' form and I now have a page that generates the image:
<?php
header('Content-Type: image/png');
$im = imagecreatetruecolor(200, 50);
$white = imagecolorallocate($im, 255, 255, 255);
$gray = imagecolorallocate($im, 160, 160, 160);
imagefilledrectangle($im, 0, 0, 200, 50, $white);
$captcha = "SOMErandomTEXT";
$font = 'Chewy.ttf';
imagettftext($im, 20, 0, 0, 20, $gray, $font, $captcha);
imagepng($im);
imagedestroy($im);
?>
Now I also have another page that shows this image, inside the form. Now I want to get the value $captcha from the page shown above on the other page. How can I do it?
Using sessions did the job for me.
PHP Sessions
I am trying to make a gamecard for a RSPS. This is my first time using PHP to generate text on images and when trying to apply this weird glitch happens:
But, when the original photo looks like this:
As you can see the corners are not curved like they should be. But, in the original it comes out fine. I am not talking about the location of the numbers.
Here is the code I am using:
<?php
header('Content-Type: image/png');
// Image Creation
$image_file = "SoulSplitCard.png";
$im = imagecreatefrompng($image_file);
//Colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$rscol = imagecolorallocate($im, 23, 113, 183);
// Levels (for now)
$text = '99';
$text2 = '87';
// Font
$font = 'arial.ttf';
//Text Applications
imagettftext($im, 15, 0, 150, 35, $rscol, $font, $text);
imagettftext($im, 15, 0, 150, 81, $rscol, $font, $text2);
// Using imagepng() instead of imagejpeg()
imagepng($im);
imagedestroy($im);
?>
What is causing this to happen?
I want to move a file that has been created using imagettftext and saved as a png. as you can see, in the code below, i used the move_uploaded_file but to no avail. please help.
tq
// Set the content-type
header('Content-Type: image/png');
// Create the image from created image
//$im = imagecreatetruecolor(180, 180);
$im = #imagecreatefromjpeg('poloroid.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 = 'John...';
$fbid = $_POST["id"];
$text = $_POST["want"];
$fb_email =$_POST["email"];
$fb_name=$_POST["name"];
$uploads_dir = '/uploaded_files';
// Replace path by your own font path
$font = 'verdana.ttf';
//image file name
$name ="$fbid.png";
// Add some shadow to the text
imagettftext($im, 20, 0, 25, 126, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 25, 125, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
//imagepng($im);
imagepng($im,$name,9);
move_uploaded_file($name,"$uploads_dir/$name");
imagedestroy($im);
You are not uploading a file, you are generating one!
imagepng has filename parameter so you can save it to your drive:
$uploads_dir = '/uploaded_files/';
$name = $uploads_dir.$fbid.'.png';
imagepng($im,$name,9);
imagedestroy($im);
try to use rename instead of move_uploaded_file
I'm currently using the following script--
<?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, 115, 150, 195);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'My Name';
// Replace path by your own font path
$font = 'AGENCYB.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);
?>
But I want to add a background image too. Please help, I'm new to this function especially.
Would something like the following work for you? You want to open the image you want to use as the background, and then write your text over the top.
<?php
// Set the content-type
header('Content-type: image/png');
/* Attempt to open */
$im = #imagecreatefrompng('backgroundimage.png');
/* See if it failed */
if(!$im)
{
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 115, 150, 195);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'My Name';
// Replace path by your own font path
$font = 'AGENCYB.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);
}else
{
//you want to do something here if your image didn't open like maybe fpassthru an alternative image
}
?>