Merge PNG/JPEG with GIF using PHP

Asked

Viewed 113 times

0

I need to make a merge of an image in PNG/JEPG with some gifs and save the end result as GIF. I can do that merge with the code below, the image is saved as gif but it turns out that gif loses animation.

// No request eu tenho uma imagem JPEG e 2 gifs
$files = $request->file('gif');

$image1 = imagecreatefromjpeg( $files[0]->getRealPath() );
$image2 = imagecreatefromgif( $files[1]->getRealPath() );
$image3 = imagecreatefromgif( $files[2]->getRealPath() );

// Cria uma nova imagem true color
$merged_image = imagecreatetruecolor( 800, 800 );

imagecopymerge( $merged_image, $image1, 0, 0, 0, 0, 800, 800, 100 );
imagecopymerge( $merged_image, $image2, 20, 50, 0, 0, imagesx( $image2 ), imagesy( $image2 ), 100 );
imagecopymerge( $merged_image, $image3, 550, 50, 0, 0, imagesx( $image3 ), imagesy( $image3 ), 100 );

header( 'Content-Type: image/gif' );

imagegif( $merged_image );

imagedestroy( $image1 );
imagedestroy( $image2 );
imagedestroy( $image3 );
imagedestroy( $merged_image );

GIF 01GIF 02JPEGImagem depois do merge

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.