Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add signature functionality #44

Merged
merged 2 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 18 additions & 33 deletions apis/index.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,40 @@

<?php
session_start();
echo isset($_FILES['file']['name']);
if (isset($_POST['name']) && isset($_POST['event']) && isset($_POST['date']) &&isset($_POST['template'])) {
// echo 'yes';
$font = realpath('../Gabriola.ttf');
$template = $_POST['template'];
$image = imagecreatefromjpeg("../template/".$template);
$color = imagecolorallocate($image, 19, 21, 22);
$srcImage = $_POST['sign'];
//signature resizing
$signature=imagecreatefromjpeg("../uploads/".$srcImage);
$width = imagesx($signature);
$height = imagesy($signature);
$targetHeight = 140;
$targetWidth = 300;
$targetImage = imagecreatetruecolor($targetWidth, $targetHeight);
imagecopyresampled($targetImage, $signature, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
$size = getimagesize("../template/".$template);
//position in template to place sign
$dest_x =round($size[0]) - 400;
$dest_y =round($size[1]) - 300;
imagettftext($image, 50, 0, 800, 600, $color, $font, $_POST['name']);
imagettftext($image, 50, 0, 800, 900, $color, $font, $_POST['event']);
imagettftext($image, 50, 0, 1200, 900, $color, $font, $_POST['date']);
//merge signature
imagecopy($image, $targetImage, $dest_x , $dest_y, 0, 0, $targetWidth, $targetHeight);
$file = $_POST['name']."_".$_POST['event']."_".$_POST['date'];
imagejpeg($image, "../certificates/" . $file . ".jpg");
imagedestroy($image);
session_start();
$_SESSION['certificate'] = "../certificates/" . $file . ".jpg";
if(isset($_SESSION['certificate'])){
echo(json_encode(array('status'=>'success','message' => $file)));
}
}

// Upload Signature
if(isset($_FILES['Signature'])){
echo "alert('Working!')";
$errors= array();
$file_name = $_FILES['Signature']['name'];
$file_size =$_FILES['Signature']['size'];
$file_tmp =$_FILES['Signature']['tmp_name'];
$file_type=$_FILES['Signature']['type'];
$tmp = explode('.',$_FILES['Signature']['name']);
$file_ext=strtolower(end($tmp));

$extensions= array("jpeg","jpg","png");

if(in_array($file_ext,$extensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}

if($file_size > 2097152){
$errors[]='File size must be exactely 2 MB';
}

if(empty($errors)==true){
move_uploaded_file($file_tmp,"../uploads/".$file_name);
echo "Success";
}else{
print_r($errors);
}

$redirectUrl = '../index.html';
echo '<script type="application/javascript">alert("Upload SUccessful!."); window.location.href = "'.$redirectUrl.'";</script>';
}



?>
35 changes: 35 additions & 0 deletions apis/signature_upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
session_start();
if (isset($_FILES["file"]["name"])) {
$extension = array('jpg', 'jpeg');
$errors = array();
$path = "../uploads/";
$uploadThisFile = true;
$file_name=$_FILES["file"]["name"];
$file_tmp=$_FILES["file"]["tmp_name"];
$file_size = $_FILES["file"]["size"];
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(!in_array(strtolower($ext),$extension))
{
array_push($errors, "File type is invalid. Name:- ".$file_name);
$uploadThisFile = false;
}
if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
$uploadThisFile = false;
}
if($uploadThisFile){
move_uploaded_file($_FILES["file"]["tmp_name"],$path.$file_name);
if(file_exists($path.$file_name)){
echo(json_encode(array('status' => 'success', 'result' => $file_name)));
}
}else{
echo(json_encode(array('status' => 'error', 'result' => "The files should be jpeg/jpg. Problem while uploading")));
}

}
else
{
echo(json_encode(array('status'=>'error','result' => 'No file selected')));
}
?>
Binary file added certificates/music_Cricklon_3 December, 2020.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading