Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- $demo_image= "";
- $font_path = "./gilsanub.ttf"; // Font file
- $font_size = 30; // in pixcels
- $water_mark_text_2 = "Tes"; // Watermark Text
- if(isset($_POST['createmark']) and $_POST['createmark'] == "Submit")
- {
- $path = "uploads/";
- $valid_formats = array("jpg", "bmp","jpeg");
- $name = $_FILES['imgfile']['name'];
- if(strlen($name))
- {
- list($txt, $ext) = explode(".", $name);
- if(in_array($ext,$valid_formats) && $_FILES['imgfile']['size'] <= 256*1024)
- {
- $upload_status = copy($_FILES['imgfile']['tmp_name'], $path.$_FILES['imgfile']['name']);
- if($upload_status){
- $new_name = $path.time().".jpg";
- // Here you have to user functins watermark_text or watermark_image
- if(watermark_text($path.$_FILES['imgfile']['name'], $new_name)){
- $demo_image = $new_name;
- }else{
- $msg="File Error.";
- }
- }
- }
- else{
- $msg="File size Max 256 KB or Invalid file format.";
- }
- }else{
- $msg='no name';
- }
- }else{
- //var_dump($_POST);
- }
- ?>
- <center>TEXT WATERMARK</center>
- <h2></h2>
- <form name="imageUpload" method="post" enctype="multipart/form-data" >
- <center>Upload Image
- Image :<input type="file" name="imgfile" /><br />
- <input type="submit" name="createmark" value="Submit" /></center>
- <?php
- if(isset($msg)){
- echo "<div>$msg</div>";
- }
- if(!empty($demo_image))
- echo '<img src="'.$demo_image.'" />';
- ?>
- </form>
- <?php
- function watermark_text($oldimage_name, $new_image_name)
- {
- global $font_path, $font_size, $water_mark_text_2;
- if(!is_file($font_path)){
- echo ('==no font=='.$font_path);
- return FALSE;
- }
- list($owidth,$oheight) = getimagesize($oldimage_name);
- $width = $height = 300;
- $image = imagecreatetruecolor($width, $height);
- $image_src = imagecreatefromjpeg($oldimage_name);
- imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
- $blue = imagecolorallocate($image, 79, 166, 185);
- imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);
- imagejpeg($image, $new_image_name, 100);
- imagedestroy($image);
- unlink($oldimage_name);
- return true;
- }
- ?>
- </form>
- <script>
- *//alert
- window.setTimeout(function(){
- $(".alert").fadeTo(500,0).slideUp(500,function(){
- $(this).remove();
- });
- },5000);
- </script>
- <script src="asset/js/jquery.min.js"></script>
- <script src="asset/js/popper.min.js"></script>
- <script src="asset/js/bootstrap.min.js"></script>
Advertisement
Add Comment
Please, Sign In to add comment