Tuesday, 9 June 2020

convert text to image

php lesson 51
gd library
convert text to image
static method
createimageforemail.php
<?Php
header ('content-type: image/jpeg');
which format we have to display in browser
//$email= 'sfd@gmail.com';
load the email
//$email =$_GET ['email'];
get the email
//in url after domain name ?email= narayana@gmail.com,it will take that and print as image ,it is called dynamic way
if (isset ($_GET['email'])){
if that page is submittted
$email = $_GET['email'];
it will take from url
if(!empty($email)){
if email is not empty
$email_length = strlen ($email);
find out the string length
$fsize = 4;
loads the size is four menas font size
$img_height = ImageFontHeight($fsize) * $email_length/10;
load the font size
$img_width = ImageFontWidth($fsize)* $email_length;
load the font widht
$image = imagecreate($img_width, $img_height);
create the image with that dimensions
$bg = imagecolorallocate($image, 255,255,255);
write the color for that image
$fcolor = imagecolorallocate($image, 0,0,0);
write the font scolor
imagestring($image, $fsize, 7 , 0, $email, $fcolor);
create the image with that string
imagejpeg($image);
created image convert to jpeg
imagedestroy($image);
after shown clear in memory
}
}
?>
require.php
<?php
if u see the source from this ,it will display the txt of that mail
?>
<img src="createimageforemail.php?email=ragiquemohamad@gmail.com">
with this it will convert that to image
<!--<img src="createimageforemail.php?email=ragiquemohamad@gmail.com"> -->
to not display in source also, we have to load from database
$email = '' means nothing
nothing between two '  and ;
no email found

we converted that email to image because of hacking, if u see source ,it will be visible, how can we avoid
if we laods from data base, nobody cant see,its safe version


<?Php
header ('content-type: image/jpeg');
sample text, same like before
//$email= 'sfd@gmail.com';
//$email =$_GET ['email'];
//in url after domain name ?email= narayana@gmail.com,it will take that and print as image ,it is called dynamic way
if (isset ($_GET['email'])){
$email = $_GET['email'];
if(!empty($email)){
$email = 'no email found';
}
else {
$email = 'no email founddd';
}
$email_length = strlen ($email);
$fsize = 4;
$img_height = ImageFontHeight($fsize) * $email_length/10;
$img_width = ImageFontWidth($fsize)* $email_length;
$image = imagecreate($img_width, $img_height);
$bg = imagecolorallocate($image, 255,255,255);
$fcolor = imagecolorallocate($image, 0,0,0);
imagestring($image, $fsize, 7 , 0, $email, $fcolor);
imagejpeg($image);
imagedestroy($image);
}
?>
<?php
?>
<img src="createimageforemail.php?email=">
working text
how to convert to image from text, which is loaded from database
<?Php
header ('content-type: image/jpeg');
//$email= 'sfd@gmail.com';
//$email =$_GET ['email'];
//in url after domain name ?email= narayana@gmail.com,it will take that and print as image ,it is called dynamic way
if (isset ($_GET['id'])){
$email = $_GET['id'];
if(empty($email)){
$email = 'no email found';
}
else {
$email = 'no email founddd';
}
}
$email_length = strlen ($email);
$fsize = 4;
$img_height = ImageFontHeight($fsize) * $email_length/10;
$img_width = ImageFontWidth($fsize)* $email_length;
$image = imagecreate($img_width, $img_height);
$bg = imagecolorallocate($image, 255,255,255);
$fcolor = imagecolorallocate($image, 0,0,0);
imagestring($image, $fsize, 7 , 0, $email, $fcolor);
imagejpeg($image);
imagedestroy($image);
?>
connect to data base , and get the text, and convert to image, no body can hack that mail
create image from email
<?Php
$host = 'localhost';
$user = 'root';
connect to database
$pass = '';
$dbname = 'lesson44';
if($mycon = @mysqli_connect($host, $user, $pass)){
mysqli_select_db($mycon, $dbname);
}
header ('content-type: image/jpeg');
shown image as text
//$email= 'sfd@gmail.com';
//$email =$_GET ['email'];
//in url after domain name ?email= narayana@gmail.com,it will take that and print as image ,it is called dynamic way
if (isset ($_GET['id'])){
if we got from user page
$id = $_GET['id'];
chcek it s empty or not
if(!empty($id)){
$query = "SELECT `email` FROM `users` WHERE `id` =$id";
select email row head fro user table with condition where
if($q_run = mysqli_query($mycon, $query)){
run this query
$num_rows = mysqli_num_rows($q_run);
get the number of rows we got and converts to array
if($num_rows == 1){
if it is found,
$row = mysqli_fetch_row($q_run);
convert to array
$email =$row[0];
access that array data
}else
{$email ='';}
if not get that email not found
}
}
else {
$email = 'no email founddd';
}
}
else {
$email = 'no email founddd';
}
$email_length = strlen ($email);
find out the string length
$fsize = 4;
loads the size is four menas font size
$img_height = ImageFontHeight($fsize) * $email_length/10;
load the font size
$img_width = ImageFontWidth($fsize)* $email_length;
load the font widht
$image = imagecreate($img_width, $img_height);
create the image with that dimensions
$bg = imagecolorallocate($image, 255,255,255);
write the color for that image
$fcolor = imagecolorallocate($image, 0,0,0);
write the font scolor
imagestring($image, $fsize, 7 , 0, $email, $fcolor);
create the image with that string
imagejpeg($image);
created image convert to jpeg
imagedestroy($image);
after shown clear in memory
?>
<?php
?>
<img src="createimageforemail.php?id=1">
get that using url and id
how to place an image on image in an dynamic way
wter mark image
<?php
if (isset($_GET['im'])){
if url is submitted or not
$im_name = $_GET['im'];
if submitted, submitted text gets from url
$wm_name = 'logo.jpg';
load the image
$im = imagecreatefrompng ($im_name);// how to create image, this already image, but we have to create image
create the image from image
$wm = imagecreatefromjpeg($wm_name);
create the image from image

$wm_x = imagesx ($wm);// how  to get the height and width of image
get the image height and width
$wm_y = imagesy ($wm);
$mrg_right =10; //how to place the margin
place the margin
$mrg_bottom =10;
$im_x = imagesx ($im);
find the image height
$im_y = imagesy ($im);
find the image height
$dst_x = $im_x - $wm_x -$mrg_right; // using substraction get the value
get the imag placement
$dst_y = $im_y -$wm_y - $mrg_bottom;
get the image place

imagecopy($im, $wm, $dst_x, $dst_y, 0, 0, $wm_x, $wm_y);
make the image with given dimensions
/*(destination image source link, source image link resource,
 x-coordinate of destinationpoint, y-coordinate of destination point,
 x-coordinate of souirce point, y-coordinate of source point,
 source width, source height)
 */
header('content-type: image/jpeg');
load the image as jpeg
// till now we created the image and how to display, we have to display in one format, that one using this jpeg or png

imagejpeg ($im); // displayd image in browser, we created image and we selected format, using this we display which image as final iamge
convert that image to jpeg

imagedestroy($im); // to clean the memory or free
clear that memory
}
?>




<?php

?>

<img src="watermark.php?im=img.png">
load that image in dyanic way without writing code in this page, execute that

graphic design library
how to display text as image 
databasse
 @mysqli_connect
mysqli_select_db
header ('content-type: image/jpeg');
how to check that is submitted isset
$_GET
how to select the required row from table SELECT FROM WHERE
run the query mysqli_query
how to find how many rows mysqli_num
how to get the required row mysqli_fetch_row
how to access aray
if if else else else else
how to find length of string strlen
how to get the heigh or set the heivhgt imagefontheight
how to write the font width imagefontwidth
how to create image imagecreate
how to write color to font imagecolorallocate
how to write color to font imagecolorallocate
imagestring
imagejpeg
imagedestroy
?id=1
how to check it submits or not isset
how to get that data from url $_GET
how to create image imagecreatefromjpeg
how to create image imagecreatefrompng
how to get the dimensions imagesx
how to get the dimensions imagesy
imagesy
imagesx
how to convert to image by given som e parameteres imagecopy
how to represent in one image header
how to shown to image in whchh format imagejpeg
after this conversion by script in memory , delete that memory imagedestroy
how to convert image to water mark in a dyanmic way url get



No comments:

Post a Comment