Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // resize image
- $image = Intervention\Image\Facades\Image::make(public_path() . '/template.png')
- ->resize(640, null, function ($constraint) {
- $constraint->aspectRatio();
- })
- ->save(public_path() . '/output.png')
- ->destroy();
- // Fill transparent with white color
- $image = Intervention\Image\Facades\Image::canvas(640, 527)
- // fill white to transparent on empty image
- ->fill('#fff')
- // fill image into empty image
- ->fill(public_path() . '/output.png')
- ->save(public_path() . '/output1.png')->destroy();
- // Get the original image.
- $src = imagecreatefrompng(public_path() . '/output1.png');
- // Get the width and height.
- $width = imagesx($src);
- $height = imagesy($src);
- // Create a white background, the same size as the original.
- $bg = imagecreatetruecolor($width, $height);
- $red = imagecolorallocate($bg, 255, 0, 0);
- $white = imagecolorallocate($bg, 0, 0, 0);
- imagefill($bg, 0, 0, $white);
- $tr = imagecolortransparent($bg, $white);
- // Merge the two images.
- imagecopyresampled(
- $bg, $src,
- 0, 0, 0, 0,
- $width, $height,
- $width, $height);
- // (left, top, left + width, top + height)
- imagefilledrectangle($bg, 37, 170, 603, 493, $tr);
- // Save the finished image.
- imagepng($bg, public_path() . '/merged.png', 0);
Add Comment
Please, Sign In to add comment