Skip to content

Instantly share code, notes, and snippets.

@surajitbasak109
Created January 16, 2019 07:54
Show Gist options
  • Save surajitbasak109/395f6bac982da7d1f90a765816af2c4e to your computer and use it in GitHub Desktop.
Save surajitbasak109/395f6bac982da7d1f90a765816af2c4e to your computer and use it in GitHub Desktop.
<?php
ob_start();
// Load the stamp and the photo to apply the watermark to
$logoImage = imagecreatefrompng('stamp.png');
$image = imagecreatefromjpeg('photo.jpg');
$new_name = 'abcdefg.jpg';
// $image = imagecreatefromjpeg( $new_name );
// $logoImage = imagecreatefrompng( $watermarksrc );
imagealphablending( $logoImage, true );
$imageWidth=imagesx($image);
$imageHeight=imagesy($image);
$logoWidth=imagesx($logoImage);
$logoHeight=imagesy($logoImage);
imagecopy(
$image,
$logoImage,
$imageWidth-$logoWidth, $imageHeight-$logoHeight,
0, 0,
$logoWidth, $logoHeight );
// Set type of image and send the output
// header("Content-type: image/jpeg");
imagepng( $image );
$img_data = ob_get_contents ();
ob_end_clean ();
$b_img = base64_encode( $img_data );/*display image with watermark */
// @imagepng( $image, $new_name );/* save image with watermark */
// Release memory
imagedestroy( $image );
imagedestroy( $imageLogo );
?>
<img src="data:image/jpeg;base64,<?php echo $b_img; ?>" alt="Image">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment