Advertisement
taktikhek

Untitled

Jun 29th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. public function crop(){
  2. $sourceImg = @imagecreatefromstring(@file_get_contents($_FILES["image"]["tmp_name"]));
  3. if ($sourceImg === false){
  4. echo base_url("assets/upload/image/images/1.png");
  5. exit;
  6. }
  7.  
  8. // makeDP
  9. $sourcePath = $_FILES["image"]["tmp_name"];
  10. $design = (
  11. isset($_POST["design"]) ? $_POST["design"] : 0
  12. );
  13. if(in_array($design, array(0, 1, 2)))
  14. $design = "frame-$design.png";
  15. else
  16. exit;
  17.  
  18. $src = imagecreatefromstring(file_get_contents($sourcePath));
  19. $fg = imagecreatefrompng(base_url("localhost/weboo/assets/upload/image/produk/$design"));
  20.  
  21. list($width, $height) = getimagesize($sourcePath);
  22.  
  23. $croppedFG = imagecreatetruecolor($width, $height);
  24.  
  25. $background = imagecolorallocate($croppedFG, 0, 0, 0);
  26. // removing the black from the placeholder
  27. imagecolortransparent($croppedFG, $background);
  28.  
  29. imagealphablending($croppedFG, false);
  30. imagesavealpha($croppedFG, true);
  31.  
  32. imagecopyresized($croppedFG, $fg, 0, 0, 0, 0, $width, $height, 400, 400);
  33.  
  34. // Start merging
  35. $out = imagecreatetruecolor($width, $height);
  36. imagecopyresampled($out, $src, 0, 0, 0, 0, $width, $height, $width, $height);
  37. imagecopyresampled($out, $croppedFG, 0, 0, 0, 0, $width, $height, $width, $height);
  38.  
  39. ob_start();
  40. imagepng($out);
  41. $image = ob_get_clean();
  42. // makeDPend
  43.  
  44. $str="";
  45. $chars = "addzifiabcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  46. $size = strlen($chars);
  47. for($i = 0;$i < 10;$i++) {
  48. $str .= $chars[rand(0,$size-1)];
  49. }
  50.  
  51. $url = $str;
  52. $loc = base_url("assets/upload/image/order/") . $url . ".png";
  53. file_put_contents($loc, $image);
  54. echo $loc;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement