gundambison

perbaikan 47

May 3rd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2. $demo_image= "";
  3. $font_path = "gilsanub.ttf"; // Font file
  4. $font_size = 30; // in pixcels
  5. $water_mark_text_2 = "Tes"; // Watermark Text
  6.  
  7. if(isset($_POST['createmark']) and $_POST['createmark'] == "Submit")
  8. {
  9.     $path = "uploads/";
  10.     $valid_formats = array("jpg", "bmp","jpeg");
  11.     $name = $_FILES['imgfile']['name'];
  12.     if(strlen($name))
  13.     {
  14.         list($txt, $ext) = explode(".", $name);
  15.         if(in_array($ext,$valid_formats) && $_FILES['imgfile']['size'] <= 256*1024)
  16.         {
  17.             $upload_status = move_uploaded_file($_FILES['imgfile']['tmp_name'], $path.$_FILES['imgfile']['name']);
  18.             if($upload_status){
  19.                 $new_name = $path.time().".jpg";
  20.                 // Here you have to user functins watermark_text or watermark_image
  21.                 if(watermark_text($path.$_FILES['imgfile']['name'], $new_name))
  22.                     $demo_image = $new_name;
  23.             }
  24.         }
  25.         else{
  26.             $msg="File size Max 256 KB or Invalid file format.";
  27.         }
  28.    
  29.     }else{
  30.         $msg='no name';
  31.     }
  32. }else{
  33.     //var_dump($_POST);
  34. }
  35.  
  36.  
  37. ?>
  38.  
  39.  
  40. <center>TEXT WATERMARK</center>
  41. <h2></h2>
  42. <form name="imageUpload" method="post" enctype="multipart/form-data" >
  43. <center>Upload Image
  44. Image :<input type="file" name="imgfile" /><br />
  45. <input type="submit" name="createmark" value="Submit" /></center>
  46.  
  47.  
  48.  
  49. <?php
  50. if(isset($msg)){
  51.     echo "<div>$msg</div>";
  52. }
  53.  
  54. if(!empty($demo_image))
  55. echo '<img src="'.$demo_image.'" />';
  56. ?>
  57. </form>
  58. <?php
  59.  
  60.  
  61. function watermark_text($oldimage_name, $new_image_name)
  62. {
  63.     global $font_path, $font_size, $water_mark_text_2;
  64.     if(!is_file($font_path)){
  65.         die('=='.$font_path);
  66.     }
  67.    
  68.     list($owidth,$oheight) = getimagesize($oldimage_name);
  69.     $width = $height = 300;
  70.     $image = imagecreatetruecolor($width, $height);
  71.     $image_src = imagecreatefromjpeg($oldimage_name);
  72.     imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
  73.     $blue = imagecolorallocate($image, 79, 166, 185);
  74.     imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);
  75.     imagejpeg($image, $new_image_name, 100);
  76.     imagedestroy($image);
  77.     unlink($oldimage_name);
  78.  
  79.     return true;
  80. }
  81. ?>
  82.     </form>
  83.  
  84.     <script>
  85.        *//alert
  86.         window.setTimeout(function(){
  87.         $(".alert").fadeTo(500,0).slideUp(500,function(){
  88.             $(this).remove();
  89.             });
  90.         },5000);
  91.         </script>
  92.  
  93. <script src="asset/js/jquery.min.js"></script>
  94. <script src="asset/js/popper.min.js"></script>
  95. <script src="asset/js/bootstrap.min.js"></script>
Advertisement
Add Comment
Please, Sign In to add comment