Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /**
  2. * Get the head from the player uploaded skin
  3. * Cut the hat and place it on the top of the cut head.
  4. * Rectangle for head is (8, 8, 8, 8)
  5. * Rectangle for hat is (40, 8, 8, 8)
  6. * Based on x, y, width, height
  7. * @param int $size - The size of the head
  8. * @return mixed - The image/png response of the head with the hat.
  9. */
  10. public function getHead($username, $size = 64) {
  11. $user = User::with('profile')->where('username', $username)->first();
  12. $source = null;
  13.  
  14. if($user != null) {
  15. if($user->profile != null) {
  16. if($user->profile->skin != null) {
  17. $source = Image::make(public_path().$user->profile->skin);
  18. }
  19. }
  20. }
  21.  
  22. if($source == null) {
  23. $source = Image::make(public_path().'/images/skins/astronaute.png');
  24. }
  25.  
  26. $source2 = clone $source;
  27. $head = $source->crop(8,8,8,8);
  28. $hat = $source2->crop(8, 8, 40, 8);
  29. $image = $head->insert($hat);
  30.  
  31. return $image->resize($size, $size)->response();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement