how to save image after editing in php - php

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

Related

Create an image from data details in site

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);
?>

PHP text to image using stylistc set in OTF font

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);
?>

Move uploaded file php not working

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

How to create images for dynamic text using PHP?

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);
?>

Outputting image with underlined text using php GD library

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);

Categories