Guest User

Untitled

a guest
Feb 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. // resize image
  2. $image = Intervention\Image\Facades\Image::make(public_path() . '/template.png')
  3. ->resize(640, null, function ($constraint) {
  4. $constraint->aspectRatio();
  5. })
  6. ->save(public_path() . '/output.png')
  7. ->destroy();
  8. // Fill transparent with white color
  9. $image = Intervention\Image\Facades\Image::canvas(640, 527)
  10. // fill white to transparent on empty image
  11. ->fill('#fff')
  12. // fill image into empty image
  13. ->fill(public_path() . '/output.png')
  14. ->save(public_path() . '/output1.png')->destroy();
  15.  
  16. // Get the original image.
  17. $src = imagecreatefrompng(public_path() . '/output1.png');
  18.  
  19. // Get the width and height.
  20. $width = imagesx($src);
  21. $height = imagesy($src);
  22.  
  23. // Create a white background, the same size as the original.
  24. $bg = imagecreatetruecolor($width, $height);
  25. $red = imagecolorallocate($bg, 255, 0, 0);
  26. $white = imagecolorallocate($bg, 0, 0, 0);
  27. imagefill($bg, 0, 0, $white);
  28. $tr = imagecolortransparent($bg, $white);
  29.  
  30. // Merge the two images.
  31. imagecopyresampled(
  32. $bg, $src,
  33. 0, 0, 0, 0,
  34. $width, $height,
  35. $width, $height);
  36. // (left, top, left + width, top + height)
  37. imagefilledrectangle($bg, 37, 170, 603, 493, $tr);
  38.  
  39. // Save the finished image.
  40. imagepng($bg, public_path() . '/merged.png', 0);
Add Comment
Please, Sign In to add comment