Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

the_manish_sharma's avatar

image intervention insert images as background

I want to insert a transparent png file in the background in a png file like this

see url - https://e7.pngegg.com/pngimages/375/1014/png-clipart-rage-comic-internet-meme-comics-know-your-meme-meme-white-hand.png

0 likes
5 replies
siangboon's avatar

@the_manish_sharma

the basic example at the introduction page not working??

https://image.intervention.io/v2

// open an image file
$img = Image::make('public/foo.jpg');

// now you are able to resize the instance
$img->resize(320, 240);

// and insert a watermark for example
$img->insert('public/watermark.png');

// finally we save the image as a new file
$img->save('public/bar.jpg');

or set a blank white image opacity to 0 first??

https://image.intervention.io/v2/api/opacity

1 like
Snapey's avatar

https://image.intervention.io/v2/api/insert

bear in mind that you cannot put an image in the background if the foreground image does not have transparency

If you want your image behind then start with your image and insert the image you want to watermark over the top

1 like
the_manish_sharma's avatar

Hey I AM Adding Background Images o on PNG File But PN File Does Not Fit

this is output - https://cdn.pngpexel.com/nuploads/preview/berdiri-serigala-transparan-gambar-png-gratis-dpo92.webp

I Want Like This like this - https://ibb.co/CzVBcts

$watermarkSource = url('public/img/pexel.png'); $watermark = Image::make($watermarkSource);

$imgPreview = Image::make($photo)->resize($widthPreview, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode($extension);

Copy Insert Watermark

    $watermark->insert($imgPreview, 'center');

$watermark->save($preview)->destroy();

if (\File::exists($preview)) { \File::delete($preview); } I want the size of the png file to increase

Please or to participate in this conversation.